OLD | NEW |
| (Empty) |
1 # -*- test-case-name: twisted.trial.test.test_tests -*- | |
2 from twisted.trial import unittest, util | |
3 from twisted.internet import reactor, protocol, defer | |
4 | |
5 | |
6 class FoolishError(Exception): | |
7 pass | |
8 | |
9 | |
10 class TestFailureInSetUp(unittest.TestCase): | |
11 def setUp(self): | |
12 raise FoolishError, "I am a broken setUp method" | |
13 | |
14 def test_noop(self): | |
15 pass | |
16 | |
17 | |
18 class TestFailureInTearDown(unittest.TestCase): | |
19 def tearDown(self): | |
20 raise FoolishError, "I am a broken tearDown method" | |
21 | |
22 def test_noop(self): | |
23 pass | |
24 | |
25 | |
26 class TestFailureInSetUpClass(unittest.TestCase): | |
27 def setUpClass(self): | |
28 raise FoolishError, "I am a broken setUpClass method" | |
29 | |
30 def test_noop(self): | |
31 pass | |
32 | |
33 | |
34 class TestFailureInTearDownClass(unittest.TestCase): | |
35 def tearDownClass(self): | |
36 raise FoolishError, "I am a broken setUp method" | |
37 | |
38 def test_noop(self): | |
39 pass | |
40 | |
41 | |
42 class TestRegularFail(unittest.TestCase): | |
43 def test_fail(self): | |
44 self.fail("I fail") | |
45 | |
46 def test_subfail(self): | |
47 self.subroutine() | |
48 | |
49 def subroutine(self): | |
50 self.fail("I fail inside") | |
51 | |
52 class TestFailureInDeferredChain(unittest.TestCase): | |
53 def test_fail(self): | |
54 d = defer.Deferred() | |
55 d.addCallback(self._later) | |
56 reactor.callLater(0, d.callback, None) | |
57 return d | |
58 def _later(self, res): | |
59 self.fail("I fail later") | |
60 | |
61 | |
62 | |
63 class ErrorTest(unittest.TestCase): | |
64 """ | |
65 A test case which has a L{test_foo} which will raise an error. | |
66 | |
67 @ivar ran: boolean indicating whether L{test_foo} has been run. | |
68 """ | |
69 ran = False | |
70 | |
71 def test_foo(self): | |
72 """ | |
73 Set C{self.ran} to True and raise a C{ZeroDivisionError} | |
74 """ | |
75 self.ran = True | |
76 1/0 | |
77 | |
78 | |
79 | |
80 class TestSkipTestCase(unittest.TestCase): | |
81 pass | |
82 | |
83 TestSkipTestCase.skip = "skipping this test" | |
84 | |
85 | |
86 class TestSkipTestCase2(unittest.TestCase): | |
87 | |
88 def setUpClass(self): | |
89 raise unittest.SkipTest, "thi stest is fukct" | |
90 | |
91 def test_thisTestWillBeSkipped(self): | |
92 pass | |
93 | |
94 | |
95 class DelayedCall(unittest.TestCase): | |
96 hiddenExceptionMsg = "something blew up" | |
97 | |
98 def go(self): | |
99 raise RuntimeError(self.hiddenExceptionMsg) | |
100 | |
101 def testHiddenException(self): | |
102 """ | |
103 What happens if an error is raised in a DelayedCall and an error is | |
104 also raised in the test? | |
105 | |
106 L{test_reporter.TestErrorReporting.testHiddenException} checks that | |
107 both errors get reported. | |
108 | |
109 Note that this behaviour is deprecated. A B{real} test would return a | |
110 Deferred that got triggered by the callLater. This would guarantee the | |
111 delayed call error gets reported. | |
112 """ | |
113 reactor.callLater(0, self.go) | |
114 reactor.iterate(0.01) | |
115 self.fail("Deliberate failure to mask the hidden exception") | |
116 testHiddenException.suppress = [util.suppress( | |
117 message=r'reactor\.iterate cannot be used.*', | |
118 category=DeprecationWarning)] | |
119 | |
120 | |
121 class ReactorCleanupTests(unittest.TestCase): | |
122 def test_leftoverPendingCalls(self): | |
123 def _(): | |
124 print 'foo!' | |
125 reactor.callLater(10000.0, _) | |
126 | |
127 class SocketOpenTest(unittest.TestCase): | |
128 def test_socketsLeftOpen(self): | |
129 f = protocol.Factory() | |
130 f.protocol = protocol.Protocol | |
131 reactor.listenTCP(0, f) | |
132 | |
133 class TimingOutDeferred(unittest.TestCase): | |
134 def test_alpha(self): | |
135 pass | |
136 | |
137 def test_deferredThatNeverFires(self): | |
138 self.methodCalled = True | |
139 d = defer.Deferred() | |
140 return d | |
141 | |
142 def test_omega(self): | |
143 pass | |
144 | |
145 | |
146 def unexpectedException(self): | |
147 """i will raise an unexpected exception... | |
148 ... *CAUSE THAT'S THE KINDA GUY I AM* | |
149 | |
150 >>> 1/0 | |
151 """ | |
152 | |
OLD | NEW |