Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- class Print_trap(list):
- def __enter__(self):
- self._stdout = sys.stdout
- sys.stdout = self._stringio = StringIO()
- return self
- def __exit__(self, *args):
- self.extend(self._stringio.getvalue().splitlines())
- del self._stringio
- sys.stdout = self._stdout
- test_funcs = [diamond]
- tests = 3, 5, 11
- for test in tests:
- with Print_trap() as target:
- diamond(int(test/2))
- for func in test_funcs:
- with Print_trap() as virt_print:
- func(int(test/2))
- if virt_print == target:
- print('passed', end='')
- else:
- print('failed', end='')
- newline = f'\n'
- print(f"\n{newline.join(virt_print)}\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement