Exemplo n.º 1
0
    def test_does_not_crash_with_mixed_unicode_and_nonascii_str(self):
        class Dummy:
            pass

        d = Dummy()
        c = Capture()
        c.start()
        printed_nonascii_str = force_unicode("test 日本").encode('utf-8')
        printed_unicode = force_unicode("Hello")
        print printed_nonascii_str
        print printed_unicode
        try:
            raise Exception("boom")
        except:
            err = sys.exc_info()
        formatted = c.formatError(d, err)
        _, fev, _ = formatted

        if py2:
            for string in [
                    force_unicode(printed_nonascii_str, encoding='utf-8'),
                    printed_unicode
            ]:
                assert string not in fev, "Output unexpectedly found in error message"
            assert d.capturedOutput == '', "capturedOutput unexpectedly non-empty"
            assert "OUTPUT ERROR" in fev
            assert "captured stdout exception traceback" in fev
            assert "UnicodeDecodeError" in fev
        else:
            for string in [repr(printed_nonascii_str), printed_unicode]:
                assert string in fev, "Output not found in error message"
                assert string in d.capturedOutput, "Output not attached to test"
Exemplo n.º 2
0
    def test_ping_prints_status(self):
        c = Capture()
        c.start()
        self._client.ping()
        c.end()

        self.assertEquals('ping -> [ok]\n', c.buffer)
Exemplo n.º 3
0
 def test_captures_nonascii_stdout(self):
     c = Capture()
     c.start()
     print
     "test 日本"
     c.end()
     self.assertEqual(c.buffer, "test 日本\n")
Exemplo n.º 4
0
 def test_captures_stdout(self):
     c = Capture()
     c.start()
     print
     "Hello"
     c.end()
     self.assertEqual(c.buffer, "Hello\n")
 def test_format_nonascii_error(self):
     class Dummy:
         pass
     d = Dummy()
     c = Capture()
     c.start()
     try:
         print "debug 日本"
         raise AssertionError(u'response does not contain 名')
     except:
         err = sys.exc_info()
     formatted = c.formatError(d, err)
 def test_format_error(self):
     class Dummy:
         pass
     d = Dummy()
     c = Capture()
     c.start()
     try:
         print "Oh my!"
         raise Exception("boom")
     except:
         err = sys.exc_info()
     formatted = c.formatError(d, err)
     ec, ev, tb = err
     (fec, fev, ftb) = formatted
     # print fec, fev, ftb
     
     self.assertEqual(ec, fec)
     self.assertEqual(tb, ftb)
     assert 'Oh my!' in fev, "Output not found in error message"
     assert 'Oh my!' in d.capturedOutput, "Output not attached to test"
 def test_format_error(self):
     class Dummy:
         pass
     d = Dummy()
     c = Capture()
     c.start()
     try:
         print "Oh my!"
         raise Exception("boom")
     except:
         err = sys.exc_info()
     formatted = c.formatError(d, err)
     ec, ev, tb = err
     (fec, fev, ftb) = formatted
     # print fec, fev, ftb
     
     self.assertEqual(ec, fec)
     self.assertEqual(tb, ftb)
     assert 'Oh my!' in fev, "Output not found in error message"
     assert 'Oh my!' in d.capturedOutput, "Output not attached to test"
 def test_captures_nonascii_stdout(self):
     c = Capture()
     c.start()
     print "test 日本"
     c.end()
     self.assertEqual(c.buffer, "test 日本\n")
 def test_captures_stdout(self):
     c = Capture()
     c.start()
     print "Hello"
     c.end()
     self.assertEqual(c.buffer, "Hello\n")
Exemplo n.º 10
0
 def test_captured_stdout_has_encoding_attribute(self):
     c = Capture()
     c.start()
     self.assertNotEqual(sys.stdout, sys.__stdout__)
     self.assertTrue(hasattr(sys.stdout, 'encoding'))
     c.end()
Exemplo n.º 11
0
 def test_captured_stdout_has_encoding_attribute(self):
     c = Capture()
     c.start()
     self.assertNotEqual(sys.stdout, sys.__stdout__)
     self.assertTrue(hasattr(sys.stdout, 'encoding'))
     c.end()