Commit 6477b02a authored by Marek Vavrusa's avatar Marek Vavrusa

scenario: STEP ASSERT <expr>

this allows to make assertions about test environment,
for example number of received queries,
average RTT, number of performed steps etc.

ranges are in variables: `RANGE = [...]`
step is in variable: `STEP`

example:
STEP QUERY
...

; Check whether the query was received
STEP ASSERT 0 < RANGE[0].received < 2
; This fails
STEP ASSERT RANGE[0].received > 100

it also evaluates subexpressions for useful
failure information
parent 75f7910c
......@@ -487,6 +487,8 @@ class Step:
return ctx.log.match(self.args)
elif self.type == 'REPLAY':
self.__replay(ctx)
elif self.type == 'ASSERT':
self.__assert(ctx)
else:
raise Exception('step %03d type %s unsupported' % (self.id, self.type))
......@@ -602,6 +604,19 @@ class Step:
time_file.flush()
time_file.close()
def __assert(self, ctx):
""" Assert that a passed expression evaluates to True. """
result = eval(' '.join(self.args), {'SCENARIO': ctx, 'RANGE': ctx.ranges})
# Evaluate subexpressions for clarity
subexpr = []
for expr in self.args:
try:
ee = eval(expr, {'SCENARIO': ctx, 'RANGE': ctx.ranges})
subexpr.append(str(ee))
except:
subexpr.append(expr)
assert result is True, '"%s" assertion fails (%s)' % (' '.join(self.args), ' '.join(subexpr))
class Scenario:
def __init__(self, info, filename = ''):
""" Initialize scenario with description. """
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment