Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_asynchat.py @ 54294:dba767bc3155 legacy-trunk
remove mention of old ctypes version
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sat, 23 May 2009 20:59:09 +0000 |
| parents | f2c90fd05d66 |
| children | acafa5142bf9 |
| rev | line source |
|---|---|
|
52456
f2c90fd05d66
Add import_function method to test.test_support, and modify a number of
R. David Murray <rdmurray@bitdance.com>
parents:
46362
diff
changeset
|
1 # test asynchat |
|
17327
760754418ee0
Add test for asynchat. This also tests asyncore.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 |
|
17328
080828bf8dbd
After testing the test on Unix, several improvements:
Guido van Rossum <guido@python.org>
parents:
17327
diff
changeset
|
3 import asyncore, asynchat, socket, threading, time |
|
35052
ec4c16fe7384
Convert asynchat test to unittest; exercise the client using a numeric value as the terminator
Andrew M. Kuchling <amk@amk.ca>
parents:
31515
diff
changeset
|
4 import unittest |
|
42409
3a015355b07a
When running asynchat tests on OS X (darwin), the test client now
Facundo Batista <facundobatista@gmail.com>
parents:
42400
diff
changeset
|
5 import sys |
|
35052
ec4c16fe7384
Convert asynchat test to unittest; exercise the client using a numeric value as the terminator
Andrew M. Kuchling <amk@amk.ca>
parents:
31515
diff
changeset
|
6 from test import test_support |
|
17327
760754418ee0
Add test for asynchat. This also tests asyncore.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 |
|
52456
f2c90fd05d66
Add import_function method to test.test_support, and modify a number of
R. David Murray <rdmurray@bitdance.com>
parents:
46362
diff
changeset
|
8 # Skip tests if thread module does not exist. |
|
f2c90fd05d66
Add import_function method to test.test_support, and modify a number of
R. David Murray <rdmurray@bitdance.com>
parents:
46362
diff
changeset
|
9 test_support.import_module('thread') |
|
f2c90fd05d66
Add import_function method to test.test_support, and modify a number of
R. David Murray <rdmurray@bitdance.com>
parents:
46362
diff
changeset
|
10 |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
44990
diff
changeset
|
11 HOST = test_support.HOST |
|
42400
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
12 SERVER_QUIT = 'QUIT\n' |
|
17327
760754418ee0
Add test for asynchat. This also tests asyncore.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 |
|
760754418ee0
Add test for asynchat. This also tests asyncore.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 class echo_server(threading.Thread): |
|
42400
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
15 # parameter to determine the number of bytes passed back to the |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
16 # client each send |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
17 chunk_size = 1 |
|
17327
760754418ee0
Add test for asynchat. This also tests asyncore.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 |
|
44990
5b17b44be1bf
Eliminate the sleeps that assume the server will start in .5 seconds.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42409
diff
changeset
|
19 def __init__(self, event): |
|
5b17b44be1bf
Eliminate the sleeps that assume the server will start in .5 seconds.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42409
diff
changeset
|
20 threading.Thread.__init__(self) |
|
5b17b44be1bf
Eliminate the sleeps that assume the server will start in .5 seconds.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42409
diff
changeset
|
21 self.event = event |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
44990
diff
changeset
|
22 self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
44990
diff
changeset
|
23 self.port = test_support.bind_port(self.sock) |
|
44990
5b17b44be1bf
Eliminate the sleeps that assume the server will start in .5 seconds.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42409
diff
changeset
|
24 |
|
17327
760754418ee0
Add test for asynchat. This also tests asyncore.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
25 def run(self): |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
44990
diff
changeset
|
26 self.sock.listen(1) |
|
44990
5b17b44be1bf
Eliminate the sleeps that assume the server will start in .5 seconds.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42409
diff
changeset
|
27 self.event.set() |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
44990
diff
changeset
|
28 conn, client = self.sock.accept() |
|
42400
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
29 self.buffer = "" |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
30 # collect data until quit message is seen |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
31 while SERVER_QUIT not in self.buffer: |
|
35052
ec4c16fe7384
Convert asynchat test to unittest; exercise the client using a numeric value as the terminator
Andrew M. Kuchling <amk@amk.ca>
parents:
31515
diff
changeset
|
32 data = conn.recv(1) |
|
17327
760754418ee0
Add test for asynchat. This also tests asyncore.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 if not data: |
|
760754418ee0
Add test for asynchat. This also tests asyncore.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
34 break |
|
42400
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
35 self.buffer = self.buffer + data |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
36 |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
37 # remove the SERVER_QUIT message |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
38 self.buffer = self.buffer.replace(SERVER_QUIT, '') |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
39 |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
40 # re-send entire set of collected data |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
41 try: |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
42 # this may fail on some tests, such as test_close_when_done, since |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
43 # the client closes the channel when it's done sending |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
44 while self.buffer: |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
45 n = conn.send(self.buffer[:self.chunk_size]) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
46 time.sleep(0.001) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
47 self.buffer = self.buffer[n:] |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
48 except: |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
49 pass |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
50 |
|
17327
760754418ee0
Add test for asynchat. This also tests asyncore.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
51 conn.close() |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
44990
diff
changeset
|
52 self.sock.close() |
|
17327
760754418ee0
Add test for asynchat. This also tests asyncore.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
53 |
|
760754418ee0
Add test for asynchat. This also tests asyncore.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
54 class echo_client(asynchat.async_chat): |
|
760754418ee0
Add test for asynchat. This also tests asyncore.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
44990
diff
changeset
|
56 def __init__(self, terminator, server_port): |
|
17327
760754418ee0
Add test for asynchat. This also tests asyncore.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 asynchat.async_chat.__init__(self) |
|
42400
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
58 self.contents = [] |
|
17327
760754418ee0
Add test for asynchat. This also tests asyncore.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
59 self.create_socket(socket.AF_INET, socket.SOCK_STREAM) |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
44990
diff
changeset
|
60 self.connect((HOST, server_port)) |
|
35052
ec4c16fe7384
Convert asynchat test to unittest; exercise the client using a numeric value as the terminator
Andrew M. Kuchling <amk@amk.ca>
parents:
31515
diff
changeset
|
61 self.set_terminator(terminator) |
|
42400
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
62 self.buffer = '' |
|
17327
760754418ee0
Add test for asynchat. This also tests asyncore.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
63 |
|
760754418ee0
Add test for asynchat. This also tests asyncore.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
64 def handle_connect(self): |
|
35052
ec4c16fe7384
Convert asynchat test to unittest; exercise the client using a numeric value as the terminator
Andrew M. Kuchling <amk@amk.ca>
parents:
31515
diff
changeset
|
65 pass |
|
42409
3a015355b07a
When running asynchat tests on OS X (darwin), the test client now
Facundo Batista <facundobatista@gmail.com>
parents:
42400
diff
changeset
|
66 |
|
3a015355b07a
When running asynchat tests on OS X (darwin), the test client now
Facundo Batista <facundobatista@gmail.com>
parents:
42400
diff
changeset
|
67 if sys.platform == 'darwin': |
|
3a015355b07a
When running asynchat tests on OS X (darwin), the test client now
Facundo Batista <facundobatista@gmail.com>
parents:
42400
diff
changeset
|
68 # select.poll returns a select.POLLHUP at the end of the tests |
|
3a015355b07a
When running asynchat tests on OS X (darwin), the test client now
Facundo Batista <facundobatista@gmail.com>
parents:
42400
diff
changeset
|
69 # on darwin, so just ignore it |
|
3a015355b07a
When running asynchat tests on OS X (darwin), the test client now
Facundo Batista <facundobatista@gmail.com>
parents:
42400
diff
changeset
|
70 def handle_expt(self): |
|
3a015355b07a
When running asynchat tests on OS X (darwin), the test client now
Facundo Batista <facundobatista@gmail.com>
parents:
42400
diff
changeset
|
71 pass |
|
17327
760754418ee0
Add test for asynchat. This also tests asyncore.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
72 |
|
760754418ee0
Add test for asynchat. This also tests asyncore.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
73 def collect_incoming_data(self, data): |
|
42400
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
74 self.buffer += data |
|
17327
760754418ee0
Add test for asynchat. This also tests asyncore.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 |
|
760754418ee0
Add test for asynchat. This also tests asyncore.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
76 def found_terminator(self): |
|
42400
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
77 self.contents.append(self.buffer) |
|
17327
760754418ee0
Add test for asynchat. This also tests asyncore.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 self.buffer = "" |
|
760754418ee0
Add test for asynchat. This also tests asyncore.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
79 |
|
35052
ec4c16fe7384
Convert asynchat test to unittest; exercise the client using a numeric value as the terminator
Andrew M. Kuchling <amk@amk.ca>
parents:
31515
diff
changeset
|
80 |
|
44990
5b17b44be1bf
Eliminate the sleeps that assume the server will start in .5 seconds.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42409
diff
changeset
|
81 def start_echo_server(): |
|
5b17b44be1bf
Eliminate the sleeps that assume the server will start in .5 seconds.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42409
diff
changeset
|
82 event = threading.Event() |
|
5b17b44be1bf
Eliminate the sleeps that assume the server will start in .5 seconds.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42409
diff
changeset
|
83 s = echo_server(event) |
|
5b17b44be1bf
Eliminate the sleeps that assume the server will start in .5 seconds.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42409
diff
changeset
|
84 s.start() |
|
5b17b44be1bf
Eliminate the sleeps that assume the server will start in .5 seconds.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42409
diff
changeset
|
85 event.wait() |
|
5b17b44be1bf
Eliminate the sleeps that assume the server will start in .5 seconds.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42409
diff
changeset
|
86 event.clear() |
|
5b17b44be1bf
Eliminate the sleeps that assume the server will start in .5 seconds.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42409
diff
changeset
|
87 time.sleep(0.01) # Give server time to start accepting. |
|
5b17b44be1bf
Eliminate the sleeps that assume the server will start in .5 seconds.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42409
diff
changeset
|
88 return s, event |
|
5b17b44be1bf
Eliminate the sleeps that assume the server will start in .5 seconds.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42409
diff
changeset
|
89 |
|
5b17b44be1bf
Eliminate the sleeps that assume the server will start in .5 seconds.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42409
diff
changeset
|
90 |
|
35052
ec4c16fe7384
Convert asynchat test to unittest; exercise the client using a numeric value as the terminator
Andrew M. Kuchling <amk@amk.ca>
parents:
31515
diff
changeset
|
91 class TestAsynchat(unittest.TestCase): |
|
42400
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
92 usepoll = False |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
93 |
|
35052
ec4c16fe7384
Convert asynchat test to unittest; exercise the client using a numeric value as the terminator
Andrew M. Kuchling <amk@amk.ca>
parents:
31515
diff
changeset
|
94 def setUp (self): |
|
ec4c16fe7384
Convert asynchat test to unittest; exercise the client using a numeric value as the terminator
Andrew M. Kuchling <amk@amk.ca>
parents:
31515
diff
changeset
|
95 pass |
|
ec4c16fe7384
Convert asynchat test to unittest; exercise the client using a numeric value as the terminator
Andrew M. Kuchling <amk@amk.ca>
parents:
31515
diff
changeset
|
96 |
|
ec4c16fe7384
Convert asynchat test to unittest; exercise the client using a numeric value as the terminator
Andrew M. Kuchling <amk@amk.ca>
parents:
31515
diff
changeset
|
97 def tearDown (self): |
|
ec4c16fe7384
Convert asynchat test to unittest; exercise the client using a numeric value as the terminator
Andrew M. Kuchling <amk@amk.ca>
parents:
31515
diff
changeset
|
98 pass |
|
ec4c16fe7384
Convert asynchat test to unittest; exercise the client using a numeric value as the terminator
Andrew M. Kuchling <amk@amk.ca>
parents:
31515
diff
changeset
|
99 |
|
42400
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
100 def line_terminator_check(self, term, server_chunk): |
|
44990
5b17b44be1bf
Eliminate the sleeps that assume the server will start in .5 seconds.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42409
diff
changeset
|
101 event = threading.Event() |
|
5b17b44be1bf
Eliminate the sleeps that assume the server will start in .5 seconds.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42409
diff
changeset
|
102 s = echo_server(event) |
|
42400
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
103 s.chunk_size = server_chunk |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
104 s.start() |
|
44990
5b17b44be1bf
Eliminate the sleeps that assume the server will start in .5 seconds.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42409
diff
changeset
|
105 event.wait() |
|
5b17b44be1bf
Eliminate the sleeps that assume the server will start in .5 seconds.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42409
diff
changeset
|
106 event.clear() |
|
5b17b44be1bf
Eliminate the sleeps that assume the server will start in .5 seconds.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42409
diff
changeset
|
107 time.sleep(0.01) # Give server time to start accepting. |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
44990
diff
changeset
|
108 c = echo_client(term, s.port) |
|
42400
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
109 c.push("hello ") |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
110 c.push("world%s" % term) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
111 c.push("I'm not dead yet!%s" % term) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
112 c.push(SERVER_QUIT) |
|
42409
3a015355b07a
When running asynchat tests on OS X (darwin), the test client now
Facundo Batista <facundobatista@gmail.com>
parents:
42400
diff
changeset
|
113 asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) |
|
42400
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
114 s.join() |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
115 |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
116 self.assertEqual(c.contents, ["hello world", "I'm not dead yet!"]) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
117 |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
118 # the line terminator tests below check receiving variously-sized |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
119 # chunks back from the server in order to exercise all branches of |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
120 # async_chat.handle_read |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
121 |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
122 def test_line_terminator1(self): |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
123 # test one-character terminator |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
124 for l in (1,2,3): |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
125 self.line_terminator_check('\n', l) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
126 |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
127 def test_line_terminator2(self): |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
128 # test two-character terminator |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
129 for l in (1,2,3): |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
130 self.line_terminator_check('\r\n', l) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
131 |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
132 def test_line_terminator3(self): |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
133 # test three-character terminator |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
134 for l in (1,2,3): |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
135 self.line_terminator_check('qqq', l) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
136 |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
137 def numeric_terminator_check(self, termlen): |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
138 # Try reading a fixed number of bytes |
|
44990
5b17b44be1bf
Eliminate the sleeps that assume the server will start in .5 seconds.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42409
diff
changeset
|
139 s, event = start_echo_server() |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
44990
diff
changeset
|
140 c = echo_client(termlen, s.port) |
|
42400
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
141 data = "hello world, I'm not dead yet!\n" |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
142 c.push(data) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
143 c.push(SERVER_QUIT) |
|
42409
3a015355b07a
When running asynchat tests on OS X (darwin), the test client now
Facundo Batista <facundobatista@gmail.com>
parents:
42400
diff
changeset
|
144 asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) |
|
35115
bfc91d4af645
test_asynchat is no longer expected to produce output.
Michael W. Hudson <mwh@python.net>
parents:
35052
diff
changeset
|
145 s.join() |
|
35052
ec4c16fe7384
Convert asynchat test to unittest; exercise the client using a numeric value as the terminator
Andrew M. Kuchling <amk@amk.ca>
parents:
31515
diff
changeset
|
146 |
|
42400
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
147 self.assertEqual(c.contents, [data[:termlen]]) |
|
17327
760754418ee0
Add test for asynchat. This also tests asyncore.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
148 |
|
42400
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
149 def test_numeric_terminator1(self): |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
150 # check that ints & longs both work (since type is |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
151 # explicitly checked in async_chat.handle_read) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
152 self.numeric_terminator_check(1) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
153 self.numeric_terminator_check(1L) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
154 |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
155 def test_numeric_terminator2(self): |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
156 self.numeric_terminator_check(6L) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
157 |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
158 def test_none_terminator(self): |
|
35052
ec4c16fe7384
Convert asynchat test to unittest; exercise the client using a numeric value as the terminator
Andrew M. Kuchling <amk@amk.ca>
parents:
31515
diff
changeset
|
159 # Try reading a fixed number of bytes |
|
44990
5b17b44be1bf
Eliminate the sleeps that assume the server will start in .5 seconds.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42409
diff
changeset
|
160 s, event = start_echo_server() |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
44990
diff
changeset
|
161 c = echo_client(None, s.port) |
|
42400
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
162 data = "hello world, I'm not dead yet!\n" |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
163 c.push(data) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
164 c.push(SERVER_QUIT) |
|
42409
3a015355b07a
When running asynchat tests on OS X (darwin), the test client now
Facundo Batista <facundobatista@gmail.com>
parents:
42400
diff
changeset
|
165 asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) |
|
42400
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
166 s.join() |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
167 |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
168 self.assertEqual(c.contents, []) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
169 self.assertEqual(c.buffer, data) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
170 |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
171 def test_simple_producer(self): |
|
44990
5b17b44be1bf
Eliminate the sleeps that assume the server will start in .5 seconds.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42409
diff
changeset
|
172 s, event = start_echo_server() |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
44990
diff
changeset
|
173 c = echo_client('\n', s.port) |
|
42400
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
174 data = "hello world\nI'm not dead yet!\n" |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
175 p = asynchat.simple_producer(data+SERVER_QUIT, buffer_size=8) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
176 c.push_with_producer(p) |
|
42409
3a015355b07a
When running asynchat tests on OS X (darwin), the test client now
Facundo Batista <facundobatista@gmail.com>
parents:
42400
diff
changeset
|
177 asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) |
|
42400
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
178 s.join() |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
179 |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
180 self.assertEqual(c.contents, ["hello world", "I'm not dead yet!"]) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
181 |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
182 def test_string_producer(self): |
|
44990
5b17b44be1bf
Eliminate the sleeps that assume the server will start in .5 seconds.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42409
diff
changeset
|
183 s, event = start_echo_server() |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
44990
diff
changeset
|
184 c = echo_client('\n', s.port) |
|
42400
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
185 data = "hello world\nI'm not dead yet!\n" |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
186 c.push_with_producer(data+SERVER_QUIT) |
|
42409
3a015355b07a
When running asynchat tests on OS X (darwin), the test client now
Facundo Batista <facundobatista@gmail.com>
parents:
42400
diff
changeset
|
187 asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) |
|
42400
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
188 s.join() |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
189 |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
190 self.assertEqual(c.contents, ["hello world", "I'm not dead yet!"]) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
191 |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
192 def test_empty_line(self): |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
193 # checks that empty lines are handled correctly |
|
44990
5b17b44be1bf
Eliminate the sleeps that assume the server will start in .5 seconds.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42409
diff
changeset
|
194 s, event = start_echo_server() |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
44990
diff
changeset
|
195 c = echo_client('\n', s.port) |
|
42400
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
196 c.push("hello world\n\nI'm not dead yet!\n") |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
197 c.push(SERVER_QUIT) |
|
42409
3a015355b07a
When running asynchat tests on OS X (darwin), the test client now
Facundo Batista <facundobatista@gmail.com>
parents:
42400
diff
changeset
|
198 asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) |
|
35115
bfc91d4af645
test_asynchat is no longer expected to produce output.
Michael W. Hudson <mwh@python.net>
parents:
35052
diff
changeset
|
199 s.join() |
|
35052
ec4c16fe7384
Convert asynchat test to unittest; exercise the client using a numeric value as the terminator
Andrew M. Kuchling <amk@amk.ca>
parents:
31515
diff
changeset
|
200 |
|
42400
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
201 self.assertEqual(c.contents, ["hello world", "", "I'm not dead yet!"]) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
202 |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
203 def test_close_when_done(self): |
|
44990
5b17b44be1bf
Eliminate the sleeps that assume the server will start in .5 seconds.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42409
diff
changeset
|
204 s, event = start_echo_server() |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
44990
diff
changeset
|
205 c = echo_client('\n', s.port) |
|
42400
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
206 c.push("hello world\nI'm not dead yet!\n") |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
207 c.push(SERVER_QUIT) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
208 c.close_when_done() |
|
42409
3a015355b07a
When running asynchat tests on OS X (darwin), the test client now
Facundo Batista <facundobatista@gmail.com>
parents:
42400
diff
changeset
|
209 asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) |
|
42400
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
210 s.join() |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
211 |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
212 self.assertEqual(c.contents, []) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
213 # the server might have been able to send a byte or two back, but this |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
214 # at least checks that it received something and didn't just fail |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
215 # (which could still result in the client not having received anything) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
216 self.assertTrue(len(s.buffer) > 0) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
217 |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
218 |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
219 class TestAsynchat_WithPoll(TestAsynchat): |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
220 usepoll = True |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
221 |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
222 class TestHelperFunctions(unittest.TestCase): |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
223 def test_find_prefix_at_end(self): |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
224 self.assertEqual(asynchat.find_prefix_at_end("qwerty\r", "\r\n"), 1) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
225 self.assertEqual(asynchat.find_prefix_at_end("qwertydkjf", "\r\n"), 0) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
226 |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
227 class TestFifo(unittest.TestCase): |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
228 def test_basic(self): |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
229 f = asynchat.fifo() |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
230 f.push(7) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
231 f.push('a') |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
232 self.assertEqual(len(f), 2) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
233 self.assertEqual(f.first(), 7) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
234 self.assertEqual(f.pop(), (1, 7)) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
235 self.assertEqual(len(f), 1) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
236 self.assertEqual(f.first(), 'a') |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
237 self.assertEqual(f.is_empty(), False) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
238 self.assertEqual(f.pop(), (1, 'a')) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
239 self.assertEqual(len(f), 0) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
240 self.assertEqual(f.is_empty(), True) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
241 self.assertEqual(f.pop(), (0, None)) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
242 |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
243 def test_given_list(self): |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
244 f = asynchat.fifo(['x', 17, 3]) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
245 self.assertEqual(len(f), 3) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
246 self.assertEqual(f.pop(), (1, 'x')) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
247 self.assertEqual(f.pop(), (1, 17)) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
248 self.assertEqual(f.pop(), (1, 3)) |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
249 self.assertEqual(f.pop(), (0, None)) |
|
35052
ec4c16fe7384
Convert asynchat test to unittest; exercise the client using a numeric value as the terminator
Andrew M. Kuchling <amk@amk.ca>
parents:
31515
diff
changeset
|
250 |
|
ec4c16fe7384
Convert asynchat test to unittest; exercise the client using a numeric value as the terminator
Andrew M. Kuchling <amk@amk.ca>
parents:
31515
diff
changeset
|
251 |
|
ec4c16fe7384
Convert asynchat test to unittest; exercise the client using a numeric value as the terminator
Andrew M. Kuchling <amk@amk.ca>
parents:
31515
diff
changeset
|
252 def test_main(verbose=None): |
|
42400
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
253 test_support.run_unittest(TestAsynchat, TestAsynchat_WithPoll, |
|
8ad8a334be0f
Added tests for asynchat classes simple_producer & fifo, and the
Facundo Batista <facundobatista@gmail.com>
parents:
38785
diff
changeset
|
254 TestHelperFunctions, TestFifo) |
|
35052
ec4c16fe7384
Convert asynchat test to unittest; exercise the client using a numeric value as the terminator
Andrew M. Kuchling <amk@amk.ca>
parents:
31515
diff
changeset
|
255 |
|
ec4c16fe7384
Convert asynchat test to unittest; exercise the client using a numeric value as the terminator
Andrew M. Kuchling <amk@amk.ca>
parents:
31515
diff
changeset
|
256 if __name__ == "__main__": |
|
ec4c16fe7384
Convert asynchat test to unittest; exercise the client using a numeric value as the terminator
Andrew M. Kuchling <amk@amk.ca>
parents:
31515
diff
changeset
|
257 test_main(verbose=True) |
