~hardware-certification/zope3/certify-staging-2.5

« back to all changes in this revision

Viewing changes to src/twisted/trial/test/.svn/text-base/erroneous.py.svn-base

  • Committer: Marc Tardif
  • Date: 2008-04-26 19:03:34 UTC
  • Revision ID: cr3@lime-20080426190334-u16xo4llz56vliqf
Initial import.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
class TestSkipTestCase(unittest.TestCase):
 
63
    pass
 
64
 
 
65
TestSkipTestCase.skip = "skipping this test"
 
66
 
 
67
 
 
68
class TestSkipTestCase2(unittest.TestCase):
 
69
    
 
70
    def setUpClass(self):
 
71
        raise unittest.SkipTest, "thi stest is fukct"
 
72
 
 
73
    def test_thisTestWillBeSkipped(self):
 
74
        pass
 
75
 
 
76
 
 
77
class DelayedCall(unittest.TestCase):
 
78
    hiddenExceptionMsg = "something blew up"
 
79
    
 
80
    def go(self):
 
81
        raise RuntimeError(self.hiddenExceptionMsg)
 
82
 
 
83
    def testHiddenException(self):
 
84
        """
 
85
        What happens if an error is raised in a DelayedCall and an error is
 
86
        also raised in the test?
 
87
 
 
88
        L{test_reporter.TestErrorReporting.testHiddenException} checks that
 
89
        both errors get reported.
 
90
 
 
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.
 
94
        """
 
95
        reactor.callLater(0, self.go)
 
96
        reactor.iterate(0.01)
 
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)]
 
101
 
 
102
 
 
103
class ReactorCleanupTests(unittest.TestCase):
 
104
    def test_leftoverPendingCalls(self):
 
105
        def _():
 
106
            print 'foo!'
 
107
        reactor.callLater(10000.0, _)
 
108
 
 
109
class SocketOpenTest(unittest.TestCase):
 
110
    def test_socketsLeftOpen(self):
 
111
        f = protocol.Factory()
 
112
        f.protocol = protocol.Protocol
 
113
        reactor.listenTCP(0, f)
 
114
 
 
115
class TimingOutDeferred(unittest.TestCase):
 
116
    def test_alpha(self):
 
117
        pass
 
118
 
 
119
    def test_deferredThatNeverFires(self):
 
120
        self.methodCalled = True
 
121
        d = defer.Deferred()
 
122
        return d
 
123
 
 
124
    def test_omega(self):
 
125
        pass
 
126
 
 
127
 
 
128
def unexpectedException(self):
 
129
    """i will raise an unexpected exception...
 
130
    ... *CAUSE THAT'S THE KINDA GUY I AM*
 
131
    
 
132
    >>> 1/0
 
133
    """
 
134