~landscape/zope3/ztk-1.1.3

« back to all changes in this revision

Viewing changes to src/twisted/test/test_error.py

  • Committer: Andreas Hasenack
  • Date: 2009-07-20 17:49:16 UTC
  • Revision ID: andreas@canonical.com-20090720174916-g2tn6qmietz2hn0u
Revert twisted removal, it breaks several dozen tests [trivial]

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
 
3
# See LICENSE for details.
 
4
 
 
5
 
 
6
from twisted.trial import unittest
 
7
from twisted.internet import error
 
8
import socket
 
9
 
 
10
class TestStringification(unittest.TestCase):
 
11
    """Test that the exceptions have useful stringifications.
 
12
    """
 
13
 
 
14
    listOfTests = [
 
15
        #(output, exception[, args[, kwargs]]),
 
16
 
 
17
        ("An error occurred binding to an interface.",
 
18
         error.BindError),
 
19
 
 
20
        ("An error occurred binding to an interface: foo.",
 
21
         error.BindError, ['foo']),
 
22
 
 
23
        ("An error occurred binding to an interface: foo bar.",
 
24
         error.BindError, ['foo', 'bar']),
 
25
 
 
26
        ("Couldn't listen on eth0:4242: Foo.",
 
27
         error.CannotListenError,
 
28
         ('eth0', 4242, socket.error('Foo'))),
 
29
 
 
30
        ("Message is too long to send.",
 
31
         error.MessageLengthError),
 
32
 
 
33
        ("Message is too long to send: foo bar.",
 
34
         error.MessageLengthError, ['foo', 'bar']),
 
35
 
 
36
        ("DNS lookup failed.",
 
37
         error.DNSLookupError),
 
38
 
 
39
        ("DNS lookup failed: foo bar.",
 
40
         error.DNSLookupError, ['foo', 'bar']),
 
41
 
 
42
        ("An error occurred while connecting.",
 
43
         error.ConnectError),
 
44
 
 
45
        ("An error occurred while connecting: someOsError.",
 
46
         error.ConnectError, ['someOsError']),
 
47
 
 
48
        ("An error occurred while connecting: foo.",
 
49
         error.ConnectError, [], {'string': 'foo'}),
 
50
 
 
51
        ("An error occurred while connecting: someOsError: foo.",
 
52
         error.ConnectError, ['someOsError', 'foo']),
 
53
 
 
54
        ("Couldn't bind.",
 
55
         error.ConnectBindError),
 
56
 
 
57
        ("Couldn't bind: someOsError.",
 
58
         error.ConnectBindError, ['someOsError']),
 
59
 
 
60
        ("Couldn't bind: someOsError: foo.",
 
61
         error.ConnectBindError, ['someOsError', 'foo']),
 
62
 
 
63
        ("Hostname couldn't be looked up.",
 
64
         error.UnknownHostError),
 
65
 
 
66
        ("No route to host.",
 
67
         error.NoRouteError),
 
68
 
 
69
        ("Connection was refused by other side.",
 
70
         error.ConnectionRefusedError),
 
71
 
 
72
        ("TCP connection timed out.",
 
73
         error.TCPTimedOutError),
 
74
 
 
75
        ("File used for UNIX socket is no good.",
 
76
         error.BadFileError),
 
77
 
 
78
        ("Service name given as port is unknown.",
 
79
         error.ServiceNameUnknownError),
 
80
 
 
81
        ("User aborted connection.",
 
82
         error.UserError),
 
83
 
 
84
        ("User timeout caused connection failure.",
 
85
         error.TimeoutError),
 
86
 
 
87
        ("An SSL error occurred.",
 
88
         error.SSLError),
 
89
 
 
90
        ("Connection to the other side was lost in a non-clean fashion.",
 
91
         error.ConnectionLost),
 
92
 
 
93
        ("Connection to the other side was lost in a non-clean fashion: foo bar.",
 
94
         error.ConnectionLost, ['foo', 'bar']),
 
95
 
 
96
        ("Connection was closed cleanly.",
 
97
         error.ConnectionDone),
 
98
 
 
99
        ("Connection was closed cleanly: foo bar.",
 
100
         error.ConnectionDone, ['foo', 'bar']),
 
101
 
 
102
        ("Uh.", #TODO nice docstring, you've got there.
 
103
         error.ConnectionFdescWentAway),
 
104
 
 
105
        ("Tried to cancel an already-called event.",
 
106
         error.AlreadyCalled),
 
107
 
 
108
        ("Tried to cancel an already-called event: foo bar.",
 
109
         error.AlreadyCalled, ['foo', 'bar']),
 
110
 
 
111
        ("Tried to cancel an already-cancelled event.",
 
112
         error.AlreadyCancelled),
 
113
 
 
114
        ("A process has ended without apparent errors: process finished with exit code 0.",
 
115
         error.ProcessDone,
 
116
         [None]),
 
117
 
 
118
        ("A process has ended with a probable error condition: process ended.",
 
119
         error.ProcessTerminated),
 
120
 
 
121
        ("A process has ended with a probable error condition: process ended with exit code 42.",
 
122
         error.ProcessTerminated,
 
123
         [],
 
124
         {'exitCode': 42}),
 
125
 
 
126
        ("A process has ended with a probable error condition: process ended by signal SIGBUS.",
 
127
         error.ProcessTerminated,
 
128
         [],
 
129
         {'signal': 'SIGBUS'}),
 
130
 
 
131
        ("The Connector was not connecting when it was asked to stop connecting.",
 
132
         error.NotConnectingError),
 
133
 
 
134
        ("The Port was not listening when it was asked to stop listening.",
 
135
         error.NotListeningError),
 
136
 
 
137
        ]
 
138
 
 
139
    def testThemAll(self):
 
140
        for entry in self.listOfTests:
 
141
            output = entry[0]
 
142
            exception = entry[1]
 
143
            try:
 
144
                args = entry[2]
 
145
            except IndexError:
 
146
                args = ()
 
147
            try:
 
148
                kwargs = entry[3]
 
149
            except IndexError:
 
150
                kwargs = {}
 
151
 
 
152
            self.failUnlessEqual(
 
153
                str(exception(*args, **kwargs)),
 
154
                output)
 
155
 
 
156
if __name__ == '__main__':
 
157
    unittest.main()