This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Neels Hofmeyr gerrit-no-reply at lists.osmocom.orgReview at https://gerrit.osmocom.org/5105 osmo_interact_common: add '... !regex' wildcard Sometimes it is desirable to match any lines, just make sure that a given regex does *not* exist in the command reply. For example, during handover config tests, to verify that no handover config exists, one would have to match an entire 'show running-config' output, which is subject to change whenever the VTY changes. Add a wildcard '... !' which allows passing a regex that must not be encountered, e.g.: OsmoBSC(config-net)# show running-config ... network ... !handover bts 0 ... handover 1 ... This checks that there is no handover config on the network level while bts 0 does have handover config. Change-Id: I7c1ebb2e7f059047903a53de26a0ec1ce7fa9b98 --- M osmopy/osmo_interact_common.py 1 file changed, 27 insertions(+), 4 deletions(-) git pull ssh://gerrit.osmocom.org:29418/python/osmo-python-tests refs/changes/05/5105/1 diff --git a/osmopy/osmo_interact_common.py b/osmopy/osmo_interact_common.py index 57f00bf..5efc22d 100644 --- a/osmopy/osmo_interact_common.py +++ b/osmopy/osmo_interact_common.py @@ -32,6 +32,7 @@ import traceback import socket import shlex +import re class Interact: @@ -210,25 +211,47 @@ - In 'expect', if a line is exactly '...', it matches any number of arbitrary lines in 'got'; the implementation is trivial and skips lines to the first occurence in 'got' that continues after '...'. + - If an 'expect' line is '... !regex', it matches any number of + lines like '...', but the given regex must not match any of those + lines. 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 = '... !' + e = 0 g = 0 while e < len(expect): - if expect[e] == '...': + if expect[e] == ANY or expect[e].startswith(ANY_EXCEPT): + wildcard = expect[e] e += 1 + g_end = g if e >= len(expect): # anything left in 'got' is accepted. - return True + g_end = len(got) # look for the next occurence of the expected line in 'got' - while g < len(got) and not match_line(expect[e], got[g]): - g += 1 + while g_end < len(got) and not match_line(expect[e], got[g_end]): + g_end += 1 + + if wildcard == ANY: + # no restrictions on lines + g = g_end + + elif wildcard.startswith(ANY_EXCEPT): + except_re = re.compile(wildcard[len(ANY_EXCEPT):]) + while g < g_end: + if except_re.search(got[g]): + return ('Got forbidden line for wildcard %r:' + ' did not expect %r in line %d of response' + % (wildcard, got[g], g)) + g += 1 + continue if g >= len(got): -- To view, visit https://gerrit.osmocom.org/5105 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7c1ebb2e7f059047903a53de26a0ec1ce7fa9b98 Gerrit-PatchSet: 1 Gerrit-Project: python/osmo-python-tests Gerrit-Branch: master Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>