Advertisement
gruntfutuk

tempdiamondteststuff

Oct 2nd, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. import sys
  2.  
  3. class Print_trap(list):
  4.     def __enter__(self):
  5.         self._stdout = sys.stdout
  6.         sys.stdout = self._stringio = StringIO()
  7.         return self
  8.     def __exit__(self, *args):
  9.         self.extend(self._stringio.getvalue().splitlines())
  10.         del self._stringio
  11.         sys.stdout = self._stdout
  12.  
  13.        
  14. test_funcs = [diamond]
  15. tests = 3, 5, 11
  16. for test in tests:
  17.     with Print_trap() as target:
  18.         diamond(int(test/2))
  19.     for func in test_funcs:
  20.         with Print_trap() as virt_print:
  21.             func(int(test/2))    
  22.         if virt_print == target:
  23.             print('passed', end='')
  24.         else:
  25.             print('failed', end='')
  26.         newline = f'\n'
  27.         print(f"\n{newline.join(virt_print)}\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement