1
# Copyright (c) 2001-2008 Twisted Matrix Laboratories.
2
# See LICENSE for details.
5
from twisted.trial import unittest
6
from twisted.internet import error
9
class TestStringification(unittest.TestCase):
10
"""Test that the exceptions have useful stringifications.
14
#(output, exception[, args[, kwargs]]),
16
("An error occurred binding to an interface.",
19
("An error occurred binding to an interface: foo.",
20
error.BindError, ['foo']),
22
("An error occurred binding to an interface: foo bar.",
23
error.BindError, ['foo', 'bar']),
25
("Couldn't listen on eth0:4242: Foo.",
26
error.CannotListenError,
27
('eth0', 4242, socket.error('Foo'))),
29
("Message is too long to send.",
30
error.MessageLengthError),
32
("Message is too long to send: foo bar.",
33
error.MessageLengthError, ['foo', 'bar']),
35
("DNS lookup failed.",
36
error.DNSLookupError),
38
("DNS lookup failed: foo bar.",
39
error.DNSLookupError, ['foo', 'bar']),
41
("An error occurred while connecting.",
44
("An error occurred while connecting: someOsError.",
45
error.ConnectError, ['someOsError']),
47
("An error occurred while connecting: foo.",
48
error.ConnectError, [], {'string': 'foo'}),
50
("An error occurred while connecting: someOsError: foo.",
51
error.ConnectError, ['someOsError', 'foo']),
54
error.ConnectBindError),
56
("Couldn't bind: someOsError.",
57
error.ConnectBindError, ['someOsError']),
59
("Couldn't bind: someOsError: foo.",
60
error.ConnectBindError, ['someOsError', 'foo']),
62
("Hostname couldn't be looked up.",
63
error.UnknownHostError),
68
("Connection was refused by other side.",
69
error.ConnectionRefusedError),
71
("TCP connection timed out.",
72
error.TCPTimedOutError),
74
("File used for UNIX socket is no good.",
77
("Service name given as port is unknown.",
78
error.ServiceNameUnknownError),
80
("User aborted connection.",
83
("User timeout caused connection failure.",
86
("An SSL error occurred.",
89
("Connection to the other side was lost in a non-clean fashion.",
90
error.ConnectionLost),
92
("Connection to the other side was lost in a non-clean fashion: foo bar.",
93
error.ConnectionLost, ['foo', 'bar']),
95
("Connection was closed cleanly.",
96
error.ConnectionDone),
98
("Connection was closed cleanly: foo bar.",
99
error.ConnectionDone, ['foo', 'bar']),
101
("Uh.", #TODO nice docstring, you've got there.
102
error.ConnectionFdescWentAway),
104
("Tried to cancel an already-called event.",
105
error.AlreadyCalled),
107
("Tried to cancel an already-called event: foo bar.",
108
error.AlreadyCalled, ['foo', 'bar']),
110
("Tried to cancel an already-cancelled event.",
111
error.AlreadyCancelled),
113
("A process has ended without apparent errors: process finished with exit code 0.",
117
("A process has ended with a probable error condition: process ended.",
118
error.ProcessTerminated),
120
("A process has ended with a probable error condition: process ended with exit code 42.",
121
error.ProcessTerminated,
125
("A process has ended with a probable error condition: process ended by signal SIGBUS.",
126
error.ProcessTerminated,
128
{'signal': 'SIGBUS'}),
130
("The Connector was not connecting when it was asked to stop connecting.",
131
error.NotConnectingError),
133
("The Port was not listening when it was asked to stop listening.",
134
error.NotListeningError),
138
def testThemAll(self):
139
for entry in self.listOfTests:
151
self.failUnlessEqual(
152
str(exception(*args, **kwargs)),
156
def test_connectionLostSubclassOfConnectionClosed(self):
158
L{error.ConnectionClosed} is a superclass of L{error.ConnectionLost}.
160
self.assertTrue(issubclass(error.ConnectionLost,
161
error.ConnectionClosed))
164
def test_connectionDoneSubclassOfConnectionClosed(self):
166
L{error.ConnectionClosed} is a superclass of L{error.ConnectionDone}.
168
self.assertTrue(issubclass(error.ConnectionDone,
169
error.ConnectionClosed))