1
# -*- test-case-name: twisted.trial.test.test_tests -*-
2
# Copyright (c) 2001-2009 Twisted Matrix Laboratories.
3
# See LICENSE for details.
5
from twisted.trial import unittest, util
6
from twisted.internet import reactor, protocol, defer
9
class FoolishError(Exception):
13
class TestFailureInSetUp(unittest.TestCase):
15
raise FoolishError, "I am a broken setUp method"
21
class TestFailureInTearDown(unittest.TestCase):
23
raise FoolishError, "I am a broken tearDown method"
29
class TestRegularFail(unittest.TestCase):
33
def test_subfail(self):
37
self.fail("I fail inside")
39
class TestFailureInDeferredChain(unittest.TestCase):
42
d.addCallback(self._later)
43
reactor.callLater(0, d.callback, None)
45
def _later(self, res):
46
self.fail("I fail later")
50
class ErrorTest(unittest.TestCase):
52
A test case which has a L{test_foo} which will raise an error.
54
@ivar ran: boolean indicating whether L{test_foo} has been run.
60
Set C{self.ran} to True and raise a C{ZeroDivisionError}
67
class TestSkipTestCase(unittest.TestCase):
70
TestSkipTestCase.skip = "skipping this test"
73
class DelayedCall(unittest.TestCase):
74
hiddenExceptionMsg = "something blew up"
77
raise RuntimeError(self.hiddenExceptionMsg)
79
def testHiddenException(self):
81
What happens if an error is raised in a DelayedCall and an error is
82
also raised in the test?
84
L{test_reporter.TestErrorReporting.testHiddenException} checks that
85
both errors get reported.
87
Note that this behaviour is deprecated. A B{real} test would return a
88
Deferred that got triggered by the callLater. This would guarantee the
89
delayed call error gets reported.
91
reactor.callLater(0, self.go)
93
self.fail("Deliberate failure to mask the hidden exception")
94
testHiddenException.suppress = [util.suppress(
95
message=r'reactor\.iterate cannot be used.*',
96
category=DeprecationWarning)]
99
class ReactorCleanupTests(unittest.TestCase):
100
def test_leftoverPendingCalls(self):
103
reactor.callLater(10000.0, _)
105
class SocketOpenTest(unittest.TestCase):
106
def test_socketsLeftOpen(self):
107
f = protocol.Factory()
108
f.protocol = protocol.Protocol
109
reactor.listenTCP(0, f)
111
class TimingOutDeferred(unittest.TestCase):
112
def test_alpha(self):
115
def test_deferredThatNeverFires(self):
116
self.methodCalled = True
120
def test_omega(self):
124
def unexpectedException(self):
125
"""i will raise an unexpected exception...
126
... *CAUSE THAT'S THE KINDA GUY I AM*