def test_3(self): q = A.select().order_by(-1) stream = StringIO() q.show(stream=stream) s = stream.getvalue() self.assertEqual(s, 'id|x |y \n' '--+-----+---\n' '3 |False|1.0\n' '2 |True |4.0\n' '1 |False|3.0\n')
class StreamWrapper(object): def __init__(self, stream): self.stream = stream self._stringio_ = StringIO() def __getattr__(self, name): return getattr(self.stream, name) def write(self, s, *args, **kw): if not muted: self.stream.write(s) self._stringio_.write(s) @classmethod @contextmanager def stdout(cls): __stdout__ = sys.stdout sys.stdout = cls(sys.stdout) yield sys.stdout._stringio_ sys.stdout = __stdout__
def setUp(self): rollback() db_session.__enter__() sys.stdout = StringIO()
def __init__(self, stream): self.stream = stream self._stringio_ = StringIO()
def runTest(self): try: func(Test) finally: rnr.stream = unittest.runner._WritelnDecorator(StringIO())