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