diff options
Diffstat (limited to 'Lib/unittest/test/test_result.py')
-rw-r--r-- | Lib/unittest/test/test_result.py | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/Lib/unittest/test/test_result.py b/Lib/unittest/test/test_result.py index eb68c1d01c2..1c58e61bb2b 100644 --- a/Lib/unittest/test/test_result.py +++ b/Lib/unittest/test/test_result.py @@ -1,7 +1,8 @@ +import io import sys import textwrap -from StringIO import StringIO -from test import test_support + +from test import support import traceback import unittest @@ -28,7 +29,6 @@ class Test_TestResult(unittest.TestCase): self.assertIsNone(result._stdout_buffer) self.assertIsNone(result._stderr_buffer) - # "This method can be called to signal that the set of tests being # run should be aborted by setting the TestResult's shouldStop # attribute to True." @@ -289,10 +289,10 @@ class Test_TestResult(unittest.TestCase): self.assertTrue(result.shouldStop) def testFailFastSetByRunner(self): - runner = unittest.TextTestRunner(stream=StringIO(), failfast=True) + runner = unittest.TextTestRunner(stream=io.StringIO(), failfast=True) def test(result): self.assertTrue(result.failfast) - runner.run(test) + result = runner.run(test) classDict = dict(unittest.TestResult.__dict__) @@ -313,8 +313,8 @@ OldResult = type('OldResult', (object,), classDict) class Test_OldTestResult(unittest.TestCase): def assertOldResultWarning(self, test, failures): - with test_support.check_warnings(("TestResult has no add.+ method,", - RuntimeWarning)): + with support.check_warnings(("TestResult has no add.+ method,", + RuntimeWarning)): result = OldResult() test.run(result) self.assertEqual(len(result.failures), failures) @@ -356,7 +356,7 @@ class Test_OldTestResult(unittest.TestCase): def testFoo(self): pass runner = unittest.TextTestRunner(resultclass=OldResult, - stream=StringIO()) + stream=io.StringIO()) # This will raise an exception if TextTestRunner can't handle old # test result objects runner.run(Test('testFoo')) @@ -412,18 +412,18 @@ class TestOutputBuffering(unittest.TestCase): self.assertIsNot(real_out, sys.stdout) self.assertIsNot(real_err, sys.stderr) - self.assertIsInstance(sys.stdout, StringIO) - self.assertIsInstance(sys.stderr, StringIO) + self.assertIsInstance(sys.stdout, io.StringIO) + self.assertIsInstance(sys.stderr, io.StringIO) self.assertIsNot(sys.stdout, sys.stderr) out_stream = sys.stdout err_stream = sys.stderr - result._original_stdout = StringIO() - result._original_stderr = StringIO() + result._original_stdout = io.StringIO() + result._original_stderr = io.StringIO() - print 'foo' - print >> sys.stderr, 'bar' + print('foo') + print('bar', file=sys.stderr) self.assertEqual(out_stream.getvalue(), 'foo\n') self.assertEqual(err_stream.getvalue(), 'bar\n') @@ -463,12 +463,12 @@ class TestOutputBuffering(unittest.TestCase): result = self.getStartedResult() buffered_out = sys.stdout buffered_err = sys.stderr - result._original_stdout = StringIO() - result._original_stderr = StringIO() + result._original_stdout = io.StringIO() + result._original_stderr = io.StringIO() - print >> sys.stdout, 'foo' + print('foo', file=sys.stdout) if include_error: - print >> sys.stderr, 'bar' + print('bar', file=sys.stderr) addFunction = getattr(result, add_attr) @@ -489,6 +489,7 @@ class TestOutputBuffering(unittest.TestCase): Stderr: bar """) + expectedFullMessage = 'A traceback%s%s' % (expectedOutMessage, expectedErrMessage) self.assertIs(test, self) @@ -503,7 +504,7 @@ class TestOutputBuffering(unittest.TestCase): class Foo(unittest.TestCase): @classmethod def setUpClass(cls): - 1//0 + 1/0 def test_foo(self): pass suite = unittest.TestSuite([Foo('test_foo')]) @@ -517,7 +518,7 @@ class TestOutputBuffering(unittest.TestCase): class Foo(unittest.TestCase): @classmethod def tearDownClass(cls): - 1//0 + 1/0 def test_foo(self): pass suite = unittest.TestSuite([Foo('test_foo')]) @@ -534,7 +535,7 @@ class TestOutputBuffering(unittest.TestCase): class Module(object): @staticmethod def setUpModule(): - 1//0 + 1/0 Foo.__module__ = 'Module' sys.modules['Module'] = Module @@ -553,7 +554,7 @@ class TestOutputBuffering(unittest.TestCase): class Module(object): @staticmethod def tearDownModule(): - 1//0 + 1/0 Foo.__module__ = 'Module' sys.modules['Module'] = Module |