2
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
3
# See LICENSE for details.
6
from twisted.trial import unittest
7
from twisted.internet import error
10
class TestStringification(unittest.TestCase):
11
"""Test that the exceptions have useful stringifications.
15
#(output, exception[, args[, kwargs]]),
17
("An error occurred binding to an interface.",
20
("An error occurred binding to an interface: foo.",
21
error.BindError, ['foo']),
23
("An error occurred binding to an interface: foo bar.",
24
error.BindError, ['foo', 'bar']),
26
("Couldn't listen on eth0:4242: Foo.",
27
error.CannotListenError,
28
('eth0', 4242, socket.error('Foo'))),
30
("Message is too long to send.",
31
error.MessageLengthError),
33
("Message is too long to send: foo bar.",
34
error.MessageLengthError, ['foo', 'bar']),
36
("DNS lookup failed.",
37
error.DNSLookupError),
39
("DNS lookup failed: foo bar.",
40
error.DNSLookupError, ['foo', 'bar']),
42
("An error occurred while connecting.",
45
("An error occurred while connecting: someOsError.",
46
error.ConnectError, ['someOsError']),
48
("An error occurred while connecting: foo.",
49
error.ConnectError, [], {'string': 'foo'}),
51
("An error occurred while connecting: someOsError: foo.",
52
error.ConnectError, ['someOsError', 'foo']),
55
error.ConnectBindError),
57
("Couldn't bind: someOsError.",
58
error.ConnectBindError, ['someOsError']),
60
("Couldn't bind: someOsError: foo.",
61
error.ConnectBindError, ['someOsError', 'foo']),
63
("Hostname couldn't be looked up.",
64
error.UnknownHostError),
69
("Connection was refused by other side.",
70
error.ConnectionRefusedError),
72
("TCP connection timed out.",
73
error.TCPTimedOutError),
75
("File used for UNIX socket is no good.",
78
("Service name given as port is unknown.",
79
error.ServiceNameUnknownError),
81
("User aborted connection.",
84
("User timeout caused connection failure.",
87
("An SSL error occurred.",
90
("Connection to the other side was lost in a non-clean fashion.",
91
error.ConnectionLost),
93
("Connection to the other side was lost in a non-clean fashion: foo bar.",
94
error.ConnectionLost, ['foo', 'bar']),
96
("Connection was closed cleanly.",
97
error.ConnectionDone),
99
("Connection was closed cleanly: foo bar.",
100
error.ConnectionDone, ['foo', 'bar']),
102
("Uh.", #TODO nice docstring, you've got there.
103
error.ConnectionFdescWentAway),
105
("Tried to cancel an already-called event.",
106
error.AlreadyCalled),
108
("Tried to cancel an already-called event: foo bar.",
109
error.AlreadyCalled, ['foo', 'bar']),
111
("Tried to cancel an already-cancelled event.",
112
error.AlreadyCancelled),
114
("A process has ended without apparent errors: process finished with exit code 0.",
118
("A process has ended with a probable error condition: process ended.",
119
error.ProcessTerminated),
121
("A process has ended with a probable error condition: process ended with exit code 42.",
122
error.ProcessTerminated,
126
("A process has ended with a probable error condition: process ended by signal SIGBUS.",
127
error.ProcessTerminated,
129
{'signal': 'SIGBUS'}),
131
("The Connector was not connecting when it was asked to stop connecting.",
132
error.NotConnectingError),
134
("The Port was not listening when it was asked to stop listening.",
135
error.NotListeningError),
139
def testThemAll(self):
140
for entry in self.listOfTests:
152
self.failUnlessEqual(
153
str(exception(*args, **kwargs)),
156
if __name__ == '__main__':