random w, improved parsing debug output

This commit is contained in:
sezanzeb 2020-11-28 18:52:19 +01:00
parent e74c91e1f6
commit 98811a3358
2 changed files with 8 additions and 4 deletions

View File

@ -103,8 +103,12 @@ class _Macro:
def wait(self, min, max=None): def wait(self, min, max=None):
"""Wait a random time in milliseconds""" """Wait a random time in milliseconds"""
# TODO random if max is None:
self.tasks.append(lambda: time.sleep(min / 1000)) sleeptime = min
else:
sleeptime = random.random() * (max - min) + min
self.tasks.append(lambda: time.sleep(sleeptime / 1000))
return self return self
@ -169,7 +173,6 @@ def _parse_recurse(macro, handler, macro_instance=None, depth=0):
assert isinstance(macro_instance, _Macro) assert isinstance(macro_instance, _Macro)
macro = macro.strip() macro = macro.strip()
logger.spam('%sinput %s', ' ' * depth, macro)
space = ' ' * depth space = ' ' * depth
# is it another macro? # is it another macro?
@ -254,6 +257,7 @@ def parse(macro, handler):
macro will write to this function once executed with `.run()`. macro will write to this function once executed with `.run()`.
""" """
try: try:
logger.spam('input %s', macro)
return _parse_recurse(macro, handler) return _parse_recurse(macro, handler)
except Exception as e: except Exception as e:
logger.error('Failed to parse macro "%s": %s', macro, e) logger.error('Failed to parse macro "%s": %s', macro, e)

View File

@ -51,7 +51,7 @@ class TestMacros(unittest.TestCase):
]) ])
def test_3(self): def test_3(self):
parse('r(3, k(m).w(200))', self.handler).run() parse('r(3, k(m).w(200, 400))', self.handler).run()
# TODO test passed time # TODO test passed time
self.assertListEqual(self.result, [ self.assertListEqual(self.result, [
('m', 1), ('m', 0), ('m', 1), ('m', 0),