From 124657cfd4d4945dfe471606145472e2c54b0dfd Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Wed, 22 Apr 2020 12:42:21 -0300 Subject: Clean up tests slightly --- testing/test_abdl.py | 48 +++++++++++++++--------------------------------- 1 file 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 "" @hypothesis.given(objtree, st.just(abdl.compile("->X"))) def test_basic_iterator(foo, pat): -- cgit 1.4.1