1
# -*- test-case-name: twisted.trial.test.test_tests -*-
2
from twisted.trial import unittest, util
3
from twisted.internet import reactor, protocol, defer
6
class FoolishError(Exception):
10
class TestFailureInSetUp(unittest.TestCase):
12
raise FoolishError, "I am a broken setUp method"
18
class TestFailureInTearDown(unittest.TestCase):
20
raise FoolishError, "I am a broken tearDown method"
26
class TestFailureInSetUpClass(unittest.TestCase):
28
raise FoolishError, "I am a broken setUpClass method"
34
class TestFailureInTearDownClass(unittest.TestCase):
35
def tearDownClass(self):
36
raise FoolishError, "I am a broken setUp method"
42
class TestRegularFail(unittest.TestCase):
46
def test_subfail(self):
50
self.fail("I fail inside")
52
class TestFailureInDeferredChain(unittest.TestCase):
55
d.addCallback(self._later)
56
reactor.callLater(0, d.callback, None)
58
def _later(self, res):
59
self.fail("I fail later")
62
class TestSkipTestCase(unittest.TestCase):
65
TestSkipTestCase.skip = "skipping this test"
68
class TestSkipTestCase2(unittest.TestCase):
71
raise unittest.SkipTest, "thi stest is fukct"
73
def test_thisTestWillBeSkipped(self):
77
class DelayedCall(unittest.TestCase):
78
hiddenExceptionMsg = "something blew up"
81
raise RuntimeError(self.hiddenExceptionMsg)
83
def testHiddenException(self):
85
What happens if an error is raised in a DelayedCall and an error is
86
also raised in the test?
88
L{test_reporter.TestErrorReporting.testHiddenException} checks that
89
both errors get reported.
91
Note that this behaviour is deprecated. A B{real} test would return a
92
Deferred that got triggered by the callLater. This would guarantee the
93
delayed call error gets reported.
95
reactor.callLater(0, self.go)
97
self.fail("Deliberate failure to mask the hidden exception")
98
testHiddenException.suppress = [util.suppress(
99
message=r'reactor\.iterate cannot be used.*',
100
category=DeprecationWarning)]
103
class ReactorCleanupTests(unittest.TestCase):
104
def test_leftoverPendingCalls(self):
107
reactor.callLater(10000.0, _)
109
class SocketOpenTest(unittest.TestCase):
110
def test_socketsLeftOpen(self):
111
f = protocol.Factory()
112
f.protocol = protocol.Protocol
113
reactor.listenTCP(0, f)
115
class TimingOutDeferred(unittest.TestCase):
116
def test_alpha(self):
119
def test_deferredThatNeverFires(self):
120
self.methodCalled = True
124
def test_omega(self):
128
def unexpectedException(self):
129
"""i will raise an unexpected exception...
130
... *CAUSE THAT'S THE KINDA GUY I AM*