コード例 #1
0
 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')
コード例 #2
0
    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__
コード例 #3
0
 def setUp(self):
     rollback()
     db_session.__enter__()
     sys.stdout = StringIO()
コード例 #4
0
 def __init__(self, stream):
     self.stream = stream
     self._stringio_ = StringIO()
コード例 #5
0
 def runTest(self):
     try:
         func(Test)
     finally:
         rnr.stream = unittest.runner._WritelnDecorator(StringIO())