Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Attributes
unittest.test.test_runner.Test_TextTestRunner Class Reference

List of all members.

Public Member Functions

def test_init
def testBufferAndFailfast
def testRunnerRegistersResult
def test_works_with_result_without_startTestRun_stopTestRun
def test_startTestRun_stopTestRun_called
def test_pickle_unpickle
def test_resultclass
def test_warnings
def testStdErrLookedUpAtInstantiationTime
def testSpecifiedStreamUsed

Public Attributes

 wasRegistered

Private Attributes

 _events

Detailed Description

Tests for TextTestRunner.

Definition at line 139 of file test_runner.py.


Member Function Documentation

Definition at line 142 of file test_runner.py.

00142 
00143     def test_init(self):
00144         runner = unittest.TextTestRunner()
00145         self.assertFalse(runner.failfast)
00146         self.assertFalse(runner.buffer)
00147         self.assertEqual(runner.verbosity, 1)
00148         self.assertEqual(runner.warnings, None)
00149         self.assertTrue(runner.descriptions)
00150         self.assertEqual(runner.resultclass, unittest.TextTestResult)
00151 

Here is the call graph for this function:

Definition at line 225 of file test_runner.py.

00225 
00226     def test_pickle_unpickle(self):
00227         # Issue #7197: a TextTestRunner should be (un)pickleable. This is
00228         # required by test_multiprocessing under Windows (in verbose mode).
00229         stream = io.StringIO("foo")
00230         runner = unittest.TextTestRunner(stream)
00231         for protocol in range(2, pickle.HIGHEST_PROTOCOL + 1):
00232             s = pickle.dumps(runner, protocol)
00233             obj = pickle.loads(s)
00234             # StringIO objects never compare equal, a cheap test instead.
00235             self.assertEqual(obj.stream.getvalue(), stream.getvalue())

Here is the call graph for this function:

Definition at line 236 of file test_runner.py.

00236 
00237     def test_resultclass(self):
00238         def MockResultClass(*args):
00239             return args
00240         STREAM = object()
00241         DESCRIPTIONS = object()
00242         VERBOSITY = object()
00243         runner = unittest.TextTestRunner(STREAM, DESCRIPTIONS, VERBOSITY,
00244                                          resultclass=MockResultClass)
00245         self.assertEqual(runner.resultclass, MockResultClass)
00246 
00247         expectedresult = (runner.stream, DESCRIPTIONS, VERBOSITY)
00248         self.assertEqual(runner._makeResult(), expectedresult)

Here is the call graph for this function:

Definition at line 205 of file test_runner.py.

00205 
00206     def test_startTestRun_stopTestRun_called(self):
00207         class LoggingTextResult(LoggingResult):
00208             separator2 = ''
00209             def printErrors(self):
00210                 pass
00211 
00212         class LoggingRunner(unittest.TextTestRunner):
00213             def __init__(self, events):
00214                 super(LoggingRunner, self).__init__(io.StringIO())
00215                 self._events = events
00216 
00217             def _makeResult(self):
00218                 return LoggingTextResult(self._events)
00219 
00220         events = []
00221         runner = LoggingRunner(events)
00222         runner.run(unittest.TestSuite())
00223         expected = ['startTestRun', 'stopTestRun']
00224         self.assertEqual(events, expected)

Check that warnings argument of TextTestRunner correctly affects the
behavior of the warnings.

Definition at line 249 of file test_runner.py.

00249 
00250     def test_warnings(self):
00251         """
00252         Check that warnings argument of TextTestRunner correctly affects the
00253         behavior of the warnings.
00254         """
00255         # see #10535 and the _test_warnings file for more information
00256 
00257         def get_parse_out_err(p):
00258             return [b.splitlines() for b in p.communicate()]
00259         opts = dict(stdout=subprocess.PIPE, stderr=subprocess.PIPE,
00260                     cwd=os.path.dirname(__file__))
00261         ae_msg = b'Please use assertEqual instead.'
00262         at_msg = b'Please use assertTrue instead.'
00263 
00264         # no args -> all the warnings are printed, unittest warnings only once
00265         p = subprocess.Popen([sys.executable, '_test_warnings.py'], **opts)
00266         out, err = get_parse_out_err(p)
00267         self.assertIn(b'OK', err)
00268         # check that the total number of warnings in the output is correct
00269         self.assertEqual(len(out), 12)
00270         # check that the numbers of the different kind of warnings is correct
00271         for msg in [b'dw', b'iw', b'uw']:
00272             self.assertEqual(out.count(msg), 3)
00273         for msg in [ae_msg, at_msg, b'rw']:
00274             self.assertEqual(out.count(msg), 1)
00275 
00276         args_list = (
00277             # passing 'ignore' as warnings arg -> no warnings
00278             [sys.executable, '_test_warnings.py', 'ignore'],
00279             # -W doesn't affect the result if the arg is passed
00280             [sys.executable, '-Wa', '_test_warnings.py', 'ignore'],
00281             # -W affects the result if the arg is not passed
00282             [sys.executable, '-Wi', '_test_warnings.py']
00283         )
00284         # in all these cases no warnings are printed
00285         for args in args_list:
00286             p = subprocess.Popen(args, **opts)
00287             out, err = get_parse_out_err(p)
00288             self.assertIn(b'OK', err)
00289             self.assertEqual(len(out), 0)
00290 
00291 
00292         # passing 'always' as warnings arg -> all the warnings printed,
00293         #                                     unittest warnings only once
00294         p = subprocess.Popen([sys.executable, '_test_warnings.py', 'always'],
00295                              **opts)
00296         out, err = get_parse_out_err(p)
00297         self.assertIn(b'OK', err)
00298         self.assertEqual(len(out), 14)
00299         for msg in [b'dw', b'iw', b'uw', b'rw']:
00300             self.assertEqual(out.count(msg), 3)
00301         for msg in [ae_msg, at_msg]:
00302             self.assertEqual(out.count(msg), 1)

Here is the call graph for this function:

Definition at line 189 of file test_runner.py.

00189 
00190     def test_works_with_result_without_startTestRun_stopTestRun(self):
00191         class OldTextResult(ResultWithNoStartTestRunStopTestRun):
00192             separator2 = ''
00193             def printErrors(self):
00194                 pass
00195 
00196         class Runner(unittest.TextTestRunner):
00197             def __init__(self):
00198                 super(Runner, self).__init__(io.StringIO())
00199 
00200             def _makeResult(self):
00201                 return OldTextResult()
00202 
00203         runner = Runner()
00204         runner.run(unittest.TestSuite())

Definition at line 152 of file test_runner.py.

00152 
00153     def testBufferAndFailfast(self):
00154         class Test(unittest.TestCase):
00155             def testFoo(self):
00156                 pass
00157         result = unittest.TestResult()
00158         runner = unittest.TextTestRunner(stream=io.StringIO(), failfast=True,
00159                                            buffer=True)
00160         # Use our result object
00161         runner._makeResult = lambda: result
00162         runner.run(Test('testFoo'))
00163 
00164         self.assertTrue(result.failfast)
00165         self.assertTrue(result.buffer)

Definition at line 166 of file test_runner.py.

00166 
00167     def testRunnerRegistersResult(self):
00168         class Test(unittest.TestCase):
00169             def testFoo(self):
00170                 pass
00171         originalRegisterResult = unittest.runner.registerResult
00172         def cleanup():
00173             unittest.runner.registerResult = originalRegisterResult
00174         self.addCleanup(cleanup)
00175 
00176         result = unittest.TestResult()
00177         runner = unittest.TextTestRunner(stream=io.StringIO())
00178         # Use our result object
00179         runner._makeResult = lambda: result
00180 
00181         self.wasRegistered = 0
00182         def fakeRegisterResult(thisResult):
00183             self.wasRegistered += 1
00184             self.assertEqual(thisResult, result)
00185         unittest.runner.registerResult = fakeRegisterResult
00186 
00187         runner.run(unittest.TestSuite())
00188         self.assertEqual(self.wasRegistered, 1)

Definition at line 314 of file test_runner.py.

00314 
00315     def testSpecifiedStreamUsed(self):
00316         # see issue 10786
00317         f = io.StringIO()
00318         runner = unittest.TextTestRunner(f)
00319         self.assertTrue(runner.stream.stream is f)

Here is the call graph for this function:

Definition at line 303 of file test_runner.py.

00303 
00304     def testStdErrLookedUpAtInstantiationTime(self):
00305         # see issue 10786
00306         old_stderr = sys.stderr
00307         f = io.StringIO()
00308         sys.stderr = f
00309         try:
00310             runner = unittest.TextTestRunner()
00311             self.assertTrue(runner.stream.stream is f)
00312         finally:
00313             sys.stderr = old_stderr

Here is the call graph for this function:


Member Data Documentation

Definition at line 214 of file test_runner.py.

Definition at line 180 of file test_runner.py.


The documentation for this class was generated from the following file: