| OLD | NEW |
| (Empty) |
| 1 from twisted.trial import unittest | |
| 2 from twisted.trial.runner import TestSuite, suiteVisit | |
| 3 | |
| 4 pyunit = __import__('unittest') | |
| 5 | |
| 6 | |
| 7 | |
| 8 class MockVisitor(object): | |
| 9 def __init__(self): | |
| 10 self.calls = [] | |
| 11 | |
| 12 | |
| 13 def __call__(self, testCase): | |
| 14 self.calls.append(testCase) | |
| 15 | |
| 16 | |
| 17 | |
| 18 class TestTestVisitor(unittest.TestCase): | |
| 19 def setUp(self): | |
| 20 self.visitor = MockVisitor() | |
| 21 | |
| 22 | |
| 23 def test_visitCase(self): | |
| 24 """ | |
| 25 Test that C{visit} works for a single test case. | |
| 26 """ | |
| 27 testCase = TestTestVisitor('test_visitCase') | |
| 28 testCase.visit(self.visitor) | |
| 29 self.assertEqual(self.visitor.calls, [testCase]) | |
| 30 | |
| 31 | |
| 32 def test_visitSuite(self): | |
| 33 """ | |
| 34 Test that C{visit} hits all tests in a suite. | |
| 35 """ | |
| 36 tests = [TestTestVisitor('test_visitCase'), | |
| 37 TestTestVisitor('test_visitSuite')] | |
| 38 testSuite = TestSuite(tests) | |
| 39 testSuite.visit(self.visitor) | |
| 40 self.assertEqual(self.visitor.calls, tests) | |
| 41 | |
| 42 | |
| 43 def test_visitEmptySuite(self): | |
| 44 """ | |
| 45 Test that C{visit} on an empty suite hits nothing. | |
| 46 """ | |
| 47 TestSuite().visit(self.visitor) | |
| 48 self.assertEqual(self.visitor.calls, []) | |
| 49 | |
| 50 | |
| 51 def test_visitNestedSuite(self): | |
| 52 """ | |
| 53 Test that C{visit} recurses through suites. | |
| 54 """ | |
| 55 tests = [TestTestVisitor('test_visitCase'), | |
| 56 TestTestVisitor('test_visitSuite')] | |
| 57 testSuite = TestSuite([TestSuite([test]) for test in tests]) | |
| 58 testSuite.visit(self.visitor) | |
| 59 self.assertEqual(self.visitor.calls, tests) | |
| 60 | |
| 61 | |
| 62 def test_visitPyunitSuite(self): | |
| 63 """ | |
| 64 Test that C{suiteVisit} visits stdlib unittest suites | |
| 65 """ | |
| 66 test = TestTestVisitor('test_visitPyunitSuite') | |
| 67 suite = pyunit.TestSuite([test]) | |
| 68 suiteVisit(suite, self.visitor) | |
| 69 self.assertEqual(self.visitor.calls, [test]) | |
| 70 | |
| 71 | |
| 72 def test_visitPyunitCase(self): | |
| 73 """ | |
| 74 Test that a stdlib test case in a suite gets visited. | |
| 75 """ | |
| 76 class PyunitCase(pyunit.TestCase): | |
| 77 def test_foo(self): | |
| 78 pass | |
| 79 test = PyunitCase('test_foo') | |
| 80 TestSuite([test]).visit(self.visitor) | |
| 81 self.assertEqual( | |
| 82 [call.id() for call in self.visitor.calls], [test.id()]) | |
| OLD | NEW |