diff options
Diffstat (limited to 'testing/test_abdl.py')
-rw-r--r-- | testing/test_abdl.py | 48 |
1 files changed, 15 insertions, 33 deletions
diff --git a/testing/test_abdl.py b/testing/test_abdl.py index cbdcd9d..0307623 100644 --- a/testing/test_abdl.py +++ b/testing/test_abdl.py @@ -6,9 +6,8 @@ import hypothesis import hypothesis.strategies as st import collections.abc - +import itertools import re - import traceback @@ -27,41 +26,24 @@ objtree = st.deferred(lambda: st.text() | st.dictionaries(hashables, values) | s class LogAndCompare: def __init__(self, left, right): - self._itl = left - self._itr = right - self.left = [] - self.right = [] - self.done = False + self.log = [] + self.iter = self.genny(left, right) + def genny(self, left, right): + def wrap_exc(it): + try: + for x in it: + yield x + except abdl.ValidationError as e: + yield e + for (l, r) in itertools.zip_longest(wrap_exc(left), wrap_exc(right), fillvalue=object()): + self.log.append((l, r)) + yield l == r or (type(l), type(r)) == (abdl.ValidationError,)*2 def __iter__(self): return self def __next__(self): - if self.done: - raise StopIteration - try: - left = next(self._itl) - except abdl.ValidationError as e: - e.tb = traceback.format_exc() - left = e - except StopIteration as e: - e.tb = traceback.format_exc() - left = e - try: - right = next(self._itr) - except abdl.ValidationError as e: - e.tb = traceback.format_exc() - right = e - except StopIteration as e: - e.tb = traceback.format_exc() - right = e - self.left.append(left) - self.right.append(right) - if StopIteration in (type(left), type(right)): - self.done = True - return (type(left), type(right)) == (StopIteration,)*2 - return left == right or (type(left), type(right)) == (abdl.ValidationError,)*2 + return next(self.iter) def __repr__(self): - return "LogAndCompare(left=" + repr(self.left) + ", right=" + repr(self.right) + ")" - + return "<LogAndCompare(log=" + repr(self.log) + ")>" @hypothesis.given(objtree, st.just(abdl.compile("->X"))) def test_basic_iterator(foo, pat): |