lynxis lazus has submitted this change. ( https://gerrit.osmocom.org/c/python/osmo-python-tests/+/42762?usp=email )
Change subject: osmo_interact: improve vty transcript language by a regular rexex ......................................................................
osmo_interact: improve vty transcript language by a regular rexex
Currently the transcript language understand 3 different tokens: ... (ignore all lines until the following line matches) ... !REGEX (ignore all lines except REXEX)
But to support osmo-stp with different compile options, the vty help is indented with different amount of spaces depending on the compile options. To support those add a regular regex using the prefix !r!
E.g. ``` OsmoSTP(config-cs7-as)# ? - description Save human-readable description of the object vs + description Save human-readable description of the object ```
To use the new regex, the line would be: ``` !r! description[ ]+Save human-readable description of the object ```
Further all regex special characters needs to be escaped. ``` description Save human-readable description of the object (for humans)
!r! description[ ]+Save human-readable description of the object (for humans) ```
Change-Id: Iadcd7a8c3677548a6405e098fe53d0614ef2012c --- M osmopy/osmo_interact/common.py 1 file changed, 16 insertions(+), 2 deletions(-)
Approvals: Jenkins Builder: Verified lynxis lazus: Looks good to me, approved
diff --git a/osmopy/osmo_interact/common.py b/osmopy/osmo_interact/common.py index 87eca6a..c989fe9 100644 --- a/osmopy/osmo_interact/common.py +++ b/osmopy/osmo_interact/common.py @@ -218,14 +218,28 @@ - If an 'expect' line is '... !regex', it matches any number of lines like '...', but the given regex must not match any of those lines. + - If the line starts with '!r!' following the regex, but a exact + match has priority
Return 'True' on match, or a string describing the mismatch. ''' - def match_line(expect_line, got_line): - return expect_line == got_line
ANY = '...' ANY_EXCEPT = '... !' + REGEX = '!r!' + + def match_line(expect_line, got_line): + if expect_line == got_line: + return True + + # try to parse the expect_line as regex + if expect_line.startswith(REGEX): + try: + if re.compile(expect_line[len(REGEX):]).match(got_line): + return True + except: + pass + return False
e = 0 g = 0