R. David Murray | a21e4ca | 2009-03-31 23:16:50 +0000 | [diff] [blame] | 1 | # test asynchat |
Guido van Rossum | 6617252 | 2001-04-06 16:32:22 +0000 | [diff] [blame] | 2 | |
R. David Murray | a21e4ca | 2009-03-31 23:16:50 +0000 | [diff] [blame] | 3 | from test import support |
Serhiy Storchaka | 1699491 | 2020-04-25 10:06:29 +0300 | [diff] [blame] | 4 | from test.support import socket_helper |
Hai Shi | e80697d | 2020-05-28 06:10:27 +0800 | [diff] [blame] | 5 | from test.support import threading_helper |
R. David Murray | a21e4ca | 2009-03-31 23:16:50 +0000 | [diff] [blame] | 6 | |
Victor Stinner | 45cff66 | 2014-07-24 18:49:36 +0200 | [diff] [blame] | 7 | import errno |
Victor Stinner | fd5d1b5 | 2014-07-08 00:16:54 +0200 | [diff] [blame] | 8 | import socket |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 9 | import sys |
Antoine Pitrou | a6a4dc8 | 2017-09-07 18:56:24 +0200 | [diff] [blame] | 10 | import threading |
Victor Stinner | fd5d1b5 | 2014-07-08 00:16:54 +0200 | [diff] [blame] | 11 | import time |
| 12 | import unittest |
Victor Stinner | 45cff66 | 2014-07-24 18:49:36 +0200 | [diff] [blame] | 13 | import unittest.mock |
Guido van Rossum | 6617252 | 2001-04-06 16:32:22 +0000 | [diff] [blame] | 14 | |
Miss Islington (bot) | 8bec9fb | 2021-06-24 16:38:01 -0700 | [diff] [blame^] | 15 | import warnings |
| 16 | with warnings.catch_warnings(): |
| 17 | warnings.simplefilter('ignore', DeprecationWarning) |
| 18 | import asynchat |
| 19 | import asyncore |
| 20 | |
Serhiy Storchaka | 1699491 | 2020-04-25 10:06:29 +0300 | [diff] [blame] | 21 | HOST = socket_helper.HOST |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 22 | SERVER_QUIT = b'QUIT\n' |
Guido van Rossum | 6617252 | 2001-04-06 16:32:22 +0000 | [diff] [blame] | 23 | |
Guido van Rossum | 6617252 | 2001-04-06 16:32:22 +0000 | [diff] [blame] | 24 | |
Antoine Pitrou | a6a4dc8 | 2017-09-07 18:56:24 +0200 | [diff] [blame] | 25 | class echo_server(threading.Thread): |
| 26 | # parameter to determine the number of bytes passed back to the |
| 27 | # client each send |
| 28 | chunk_size = 1 |
Christian Heimes | af98da1 | 2008-01-27 15:18:18 +0000 | [diff] [blame] | 29 | |
Antoine Pitrou | a6a4dc8 | 2017-09-07 18:56:24 +0200 | [diff] [blame] | 30 | def __init__(self, event): |
| 31 | threading.Thread.__init__(self) |
| 32 | self.event = event |
| 33 | self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
Serhiy Storchaka | 1699491 | 2020-04-25 10:06:29 +0300 | [diff] [blame] | 34 | self.port = socket_helper.bind_port(self.sock) |
Antoine Pitrou | a6a4dc8 | 2017-09-07 18:56:24 +0200 | [diff] [blame] | 35 | # This will be set if the client wants us to wait before echoing |
| 36 | # data back. |
| 37 | self.start_resend_event = None |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 38 | |
Antoine Pitrou | a6a4dc8 | 2017-09-07 18:56:24 +0200 | [diff] [blame] | 39 | def run(self): |
| 40 | self.sock.listen() |
| 41 | self.event.set() |
| 42 | conn, client = self.sock.accept() |
| 43 | self.buffer = b"" |
| 44 | # collect data until quit message is seen |
| 45 | while SERVER_QUIT not in self.buffer: |
| 46 | data = conn.recv(1) |
| 47 | if not data: |
| 48 | break |
| 49 | self.buffer = self.buffer + data |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 50 | |
Antoine Pitrou | a6a4dc8 | 2017-09-07 18:56:24 +0200 | [diff] [blame] | 51 | # remove the SERVER_QUIT message |
| 52 | self.buffer = self.buffer.replace(SERVER_QUIT, b'') |
Collin Winter | 8641c56 | 2010-03-17 23:49:15 +0000 | [diff] [blame] | 53 | |
Antoine Pitrou | a6a4dc8 | 2017-09-07 18:56:24 +0200 | [diff] [blame] | 54 | if self.start_resend_event: |
| 55 | self.start_resend_event.wait() |
| 56 | |
| 57 | # re-send entire set of collected data |
| 58 | try: |
| 59 | # this may fail on some tests, such as test_close_when_done, |
| 60 | # since the client closes the channel when it's done sending |
| 61 | while self.buffer: |
| 62 | n = conn.send(self.buffer[:self.chunk_size]) |
| 63 | time.sleep(0.001) |
| 64 | self.buffer = self.buffer[n:] |
| 65 | except: |
| 66 | pass |
| 67 | |
| 68 | conn.close() |
| 69 | self.sock.close() |
| 70 | |
| 71 | class echo_client(asynchat.async_chat): |
| 72 | |
| 73 | def __init__(self, terminator, server_port): |
| 74 | asynchat.async_chat.__init__(self) |
| 75 | self.contents = [] |
| 76 | self.create_socket(socket.AF_INET, socket.SOCK_STREAM) |
| 77 | self.connect((HOST, server_port)) |
| 78 | self.set_terminator(terminator) |
| 79 | self.buffer = b"" |
| 80 | |
Adam Johnson | 892221b | 2019-11-19 19:45:20 +0000 | [diff] [blame] | 81 | def handle_connect(self): |
| 82 | pass |
Antoine Pitrou | a6a4dc8 | 2017-09-07 18:56:24 +0200 | [diff] [blame] | 83 | |
Adam Johnson | 892221b | 2019-11-19 19:45:20 +0000 | [diff] [blame] | 84 | if sys.platform == 'darwin': |
| 85 | # select.poll returns a select.POLLHUP at the end of the tests |
| 86 | # on darwin, so just ignore it |
| 87 | def handle_expt(self): |
| 88 | pass |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 89 | |
Antoine Pitrou | a6a4dc8 | 2017-09-07 18:56:24 +0200 | [diff] [blame] | 90 | def collect_incoming_data(self, data): |
| 91 | self.buffer += data |
Guido van Rossum | 6617252 | 2001-04-06 16:32:22 +0000 | [diff] [blame] | 92 | |
Antoine Pitrou | a6a4dc8 | 2017-09-07 18:56:24 +0200 | [diff] [blame] | 93 | def found_terminator(self): |
| 94 | self.contents.append(self.buffer) |
| 95 | self.buffer = b"" |
Guido van Rossum | 6617252 | 2001-04-06 16:32:22 +0000 | [diff] [blame] | 96 | |
Antoine Pitrou | a6a4dc8 | 2017-09-07 18:56:24 +0200 | [diff] [blame] | 97 | def start_echo_server(): |
| 98 | event = threading.Event() |
| 99 | s = echo_server(event) |
| 100 | s.start() |
| 101 | event.wait() |
| 102 | event.clear() |
| 103 | time.sleep(0.01) # Give server time to start accepting. |
| 104 | return s, event |
Guido van Rossum | 6617252 | 2001-04-06 16:32:22 +0000 | [diff] [blame] | 105 | |
Guido van Rossum | 6617252 | 2001-04-06 16:32:22 +0000 | [diff] [blame] | 106 | |
Andrew M. Kuchling | 5ac2534 | 2005-06-09 14:56:31 +0000 | [diff] [blame] | 107 | class TestAsynchat(unittest.TestCase): |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 108 | usepoll = False |
| 109 | |
Victor Stinner | fd5d1b5 | 2014-07-08 00:16:54 +0200 | [diff] [blame] | 110 | def setUp(self): |
Hai Shi | e80697d | 2020-05-28 06:10:27 +0800 | [diff] [blame] | 111 | self._threads = threading_helper.threading_setup() |
Andrew M. Kuchling | 5ac2534 | 2005-06-09 14:56:31 +0000 | [diff] [blame] | 112 | |
Victor Stinner | fd5d1b5 | 2014-07-08 00:16:54 +0200 | [diff] [blame] | 113 | def tearDown(self): |
Hai Shi | e80697d | 2020-05-28 06:10:27 +0800 | [diff] [blame] | 114 | threading_helper.threading_cleanup(*self._threads) |
Andrew M. Kuchling | 5ac2534 | 2005-06-09 14:56:31 +0000 | [diff] [blame] | 115 | |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 116 | def line_terminator_check(self, term, server_chunk): |
Christian Heimes | af98da1 | 2008-01-27 15:18:18 +0000 | [diff] [blame] | 117 | event = threading.Event() |
| 118 | s = echo_server(event) |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 119 | s.chunk_size = server_chunk |
Andrew M. Kuchling | 5ac2534 | 2005-06-09 14:56:31 +0000 | [diff] [blame] | 120 | s.start() |
Christian Heimes | af98da1 | 2008-01-27 15:18:18 +0000 | [diff] [blame] | 121 | event.wait() |
| 122 | event.clear() |
Victor Stinner | fd5d1b5 | 2014-07-08 00:16:54 +0200 | [diff] [blame] | 123 | time.sleep(0.01) # Give server time to start accepting. |
Christian Heimes | 5e69685 | 2008-04-09 08:37:03 +0000 | [diff] [blame] | 124 | c = echo_client(term, s.port) |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 125 | c.push(b"hello ") |
Josiah Carlson | d74900e | 2008-07-07 04:15:08 +0000 | [diff] [blame] | 126 | c.push(b"world" + term) |
| 127 | c.push(b"I'm not dead yet!" + term) |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 128 | c.push(SERVER_QUIT) |
| 129 | asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) |
Hai Shi | e80697d | 2020-05-28 06:10:27 +0800 | [diff] [blame] | 130 | threading_helper.join_thread(s) |
Andrew M. Kuchling | 5ac2534 | 2005-06-09 14:56:31 +0000 | [diff] [blame] | 131 | |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 132 | self.assertEqual(c.contents, [b"hello world", b"I'm not dead yet!"]) |
Andrew M. Kuchling | 5ac2534 | 2005-06-09 14:56:31 +0000 | [diff] [blame] | 133 | |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 134 | # the line terminator tests below check receiving variously-sized |
| 135 | # chunks back from the server in order to exercise all branches of |
| 136 | # async_chat.handle_read |
| 137 | |
| 138 | def test_line_terminator1(self): |
| 139 | # test one-character terminator |
Victor Stinner | fd5d1b5 | 2014-07-08 00:16:54 +0200 | [diff] [blame] | 140 | for l in (1, 2, 3): |
Josiah Carlson | d74900e | 2008-07-07 04:15:08 +0000 | [diff] [blame] | 141 | self.line_terminator_check(b'\n', l) |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 142 | |
| 143 | def test_line_terminator2(self): |
| 144 | # test two-character terminator |
Victor Stinner | fd5d1b5 | 2014-07-08 00:16:54 +0200 | [diff] [blame] | 145 | for l in (1, 2, 3): |
Josiah Carlson | d74900e | 2008-07-07 04:15:08 +0000 | [diff] [blame] | 146 | self.line_terminator_check(b'\r\n', l) |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 147 | |
| 148 | def test_line_terminator3(self): |
| 149 | # test three-character terminator |
Victor Stinner | fd5d1b5 | 2014-07-08 00:16:54 +0200 | [diff] [blame] | 150 | for l in (1, 2, 3): |
Josiah Carlson | d74900e | 2008-07-07 04:15:08 +0000 | [diff] [blame] | 151 | self.line_terminator_check(b'qqq', l) |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 152 | |
| 153 | def numeric_terminator_check(self, termlen): |
Andrew M. Kuchling | 5ac2534 | 2005-06-09 14:56:31 +0000 | [diff] [blame] | 154 | # Try reading a fixed number of bytes |
Christian Heimes | af98da1 | 2008-01-27 15:18:18 +0000 | [diff] [blame] | 155 | s, event = start_echo_server() |
Christian Heimes | 5e69685 | 2008-04-09 08:37:03 +0000 | [diff] [blame] | 156 | c = echo_client(termlen, s.port) |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 157 | data = b"hello world, I'm not dead yet!\n" |
| 158 | c.push(data) |
| 159 | c.push(SERVER_QUIT) |
| 160 | asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) |
Hai Shi | e80697d | 2020-05-28 06:10:27 +0800 | [diff] [blame] | 161 | threading_helper.join_thread(s) |
Andrew M. Kuchling | 5ac2534 | 2005-06-09 14:56:31 +0000 | [diff] [blame] | 162 | |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 163 | self.assertEqual(c.contents, [data[:termlen]]) |
| 164 | |
| 165 | def test_numeric_terminator1(self): |
| 166 | # check that ints & longs both work (since type is |
| 167 | # explicitly checked in async_chat.handle_read) |
| 168 | self.numeric_terminator_check(1) |
| 169 | |
| 170 | def test_numeric_terminator2(self): |
| 171 | self.numeric_terminator_check(6) |
| 172 | |
| 173 | def test_none_terminator(self): |
| 174 | # Try reading a fixed number of bytes |
Christian Heimes | af98da1 | 2008-01-27 15:18:18 +0000 | [diff] [blame] | 175 | s, event = start_echo_server() |
Christian Heimes | 5e69685 | 2008-04-09 08:37:03 +0000 | [diff] [blame] | 176 | c = echo_client(None, s.port) |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 177 | data = b"hello world, I'm not dead yet!\n" |
| 178 | c.push(data) |
| 179 | c.push(SERVER_QUIT) |
| 180 | asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) |
Hai Shi | e80697d | 2020-05-28 06:10:27 +0800 | [diff] [blame] | 181 | threading_helper.join_thread(s) |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 182 | |
| 183 | self.assertEqual(c.contents, []) |
| 184 | self.assertEqual(c.buffer, data) |
| 185 | |
| 186 | def test_simple_producer(self): |
Christian Heimes | af98da1 | 2008-01-27 15:18:18 +0000 | [diff] [blame] | 187 | s, event = start_echo_server() |
Christian Heimes | 5e69685 | 2008-04-09 08:37:03 +0000 | [diff] [blame] | 188 | c = echo_client(b'\n', s.port) |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 189 | data = b"hello world\nI'm not dead yet!\n" |
| 190 | p = asynchat.simple_producer(data+SERVER_QUIT, buffer_size=8) |
| 191 | c.push_with_producer(p) |
| 192 | asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) |
Hai Shi | e80697d | 2020-05-28 06:10:27 +0800 | [diff] [blame] | 193 | threading_helper.join_thread(s) |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 194 | |
| 195 | self.assertEqual(c.contents, [b"hello world", b"I'm not dead yet!"]) |
| 196 | |
| 197 | def test_string_producer(self): |
Christian Heimes | af98da1 | 2008-01-27 15:18:18 +0000 | [diff] [blame] | 198 | s, event = start_echo_server() |
Christian Heimes | 5e69685 | 2008-04-09 08:37:03 +0000 | [diff] [blame] | 199 | c = echo_client(b'\n', s.port) |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 200 | data = b"hello world\nI'm not dead yet!\n" |
| 201 | c.push_with_producer(data+SERVER_QUIT) |
| 202 | asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) |
Hai Shi | e80697d | 2020-05-28 06:10:27 +0800 | [diff] [blame] | 203 | threading_helper.join_thread(s) |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 204 | |
| 205 | self.assertEqual(c.contents, [b"hello world", b"I'm not dead yet!"]) |
| 206 | |
| 207 | def test_empty_line(self): |
| 208 | # checks that empty lines are handled correctly |
Christian Heimes | af98da1 | 2008-01-27 15:18:18 +0000 | [diff] [blame] | 209 | s, event = start_echo_server() |
Christian Heimes | 5e69685 | 2008-04-09 08:37:03 +0000 | [diff] [blame] | 210 | c = echo_client(b'\n', s.port) |
Josiah Carlson | d74900e | 2008-07-07 04:15:08 +0000 | [diff] [blame] | 211 | c.push(b"hello world\n\nI'm not dead yet!\n") |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 212 | c.push(SERVER_QUIT) |
| 213 | asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) |
Hai Shi | e80697d | 2020-05-28 06:10:27 +0800 | [diff] [blame] | 214 | threading_helper.join_thread(s) |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 215 | |
| 216 | self.assertEqual(c.contents, |
| 217 | [b"hello world", b"", b"I'm not dead yet!"]) |
| 218 | |
| 219 | def test_close_when_done(self): |
Christian Heimes | af98da1 | 2008-01-27 15:18:18 +0000 | [diff] [blame] | 220 | s, event = start_echo_server() |
Collin Winter | 8641c56 | 2010-03-17 23:49:15 +0000 | [diff] [blame] | 221 | s.start_resend_event = threading.Event() |
Christian Heimes | 5e69685 | 2008-04-09 08:37:03 +0000 | [diff] [blame] | 222 | c = echo_client(b'\n', s.port) |
Josiah Carlson | d74900e | 2008-07-07 04:15:08 +0000 | [diff] [blame] | 223 | c.push(b"hello world\nI'm not dead yet!\n") |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 224 | c.push(SERVER_QUIT) |
| 225 | c.close_when_done() |
| 226 | asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) |
Collin Winter | 8641c56 | 2010-03-17 23:49:15 +0000 | [diff] [blame] | 227 | |
| 228 | # Only allow the server to start echoing data back to the client after |
| 229 | # the client has closed its connection. This prevents a race condition |
| 230 | # where the server echoes all of its data before we can check that it |
| 231 | # got any down below. |
| 232 | s.start_resend_event.set() |
Hai Shi | e80697d | 2020-05-28 06:10:27 +0800 | [diff] [blame] | 233 | threading_helper.join_thread(s) |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 234 | |
| 235 | self.assertEqual(c.contents, []) |
| 236 | # the server might have been able to send a byte or two back, but this |
| 237 | # at least checks that it received something and didn't just fail |
| 238 | # (which could still result in the client not having received anything) |
Alexandre Vassalotti | 953f558 | 2009-07-22 21:29:01 +0000 | [diff] [blame] | 239 | self.assertGreater(len(s.buffer), 0) |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 240 | |
Victor Stinner | d9e810a | 2014-07-08 00:00:30 +0200 | [diff] [blame] | 241 | def test_push(self): |
| 242 | # Issue #12523: push() should raise a TypeError if it doesn't get |
| 243 | # a bytes string |
| 244 | s, event = start_echo_server() |
| 245 | c = echo_client(b'\n', s.port) |
| 246 | data = b'bytes\n' |
| 247 | c.push(data) |
| 248 | c.push(bytearray(data)) |
| 249 | c.push(memoryview(data)) |
| 250 | self.assertRaises(TypeError, c.push, 10) |
| 251 | self.assertRaises(TypeError, c.push, 'unicode') |
| 252 | c.push(SERVER_QUIT) |
| 253 | asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) |
Hai Shi | e80697d | 2020-05-28 06:10:27 +0800 | [diff] [blame] | 254 | threading_helper.join_thread(s) |
Victor Stinner | d9e810a | 2014-07-08 00:00:30 +0200 | [diff] [blame] | 255 | self.assertEqual(c.contents, [b'bytes', b'bytes', b'bytes']) |
| 256 | |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 257 | |
| 258 | class TestAsynchat_WithPoll(TestAsynchat): |
| 259 | usepoll = True |
| 260 | |
Victor Stinner | fd5d1b5 | 2014-07-08 00:16:54 +0200 | [diff] [blame] | 261 | |
Victor Stinner | 45cff66 | 2014-07-24 18:49:36 +0200 | [diff] [blame] | 262 | class TestAsynchatMocked(unittest.TestCase): |
| 263 | def test_blockingioerror(self): |
| 264 | # Issue #16133: handle_read() must ignore BlockingIOError |
| 265 | sock = unittest.mock.Mock() |
| 266 | sock.recv.side_effect = BlockingIOError(errno.EAGAIN) |
| 267 | |
| 268 | dispatcher = asynchat.async_chat() |
| 269 | dispatcher.set_socket(sock) |
| 270 | self.addCleanup(dispatcher.del_channel) |
| 271 | |
| 272 | with unittest.mock.patch.object(dispatcher, 'handle_error') as error: |
| 273 | dispatcher.handle_read() |
| 274 | self.assertFalse(error.called) |
| 275 | |
| 276 | |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 277 | class TestHelperFunctions(unittest.TestCase): |
| 278 | def test_find_prefix_at_end(self): |
| 279 | self.assertEqual(asynchat.find_prefix_at_end("qwerty\r", "\r\n"), 1) |
| 280 | self.assertEqual(asynchat.find_prefix_at_end("qwertydkjf", "\r\n"), 0) |
| 281 | |
Victor Stinner | fd5d1b5 | 2014-07-08 00:16:54 +0200 | [diff] [blame] | 282 | |
Victor Stinner | 630a4f6 | 2014-07-08 00:26:36 +0200 | [diff] [blame] | 283 | class TestNotConnected(unittest.TestCase): |
| 284 | def test_disallow_negative_terminator(self): |
| 285 | # Issue #11259 |
| 286 | client = asynchat.async_chat() |
| 287 | self.assertRaises(ValueError, client.set_terminator, -1) |
| 288 | |
| 289 | |
| 290 | |
Andrew M. Kuchling | 5ac2534 | 2005-06-09 14:56:31 +0000 | [diff] [blame] | 291 | if __name__ == "__main__": |
Brett Cannon | 3e9a9ae | 2013-06-12 21:25:59 -0400 | [diff] [blame] | 292 | unittest.main() |