Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_socket.py @ 28646:193b8aec00ce legacy-trunk
Changes from Jonathan Riehl to allow his pgen extension (PEP 269) to
work. This includes some more code that used to be part of pgen in
the main parser; I'm okay with that. I'll see if the Windows build
needs work next.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Apr 2003 14:55:42 +0000 |
| parents | b2b4797052c6 |
| children | 57e61588571b |
| rev | line source |
|---|---|
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1 #!/usr/bin/env python |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
2 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3 import unittest |
|
24364
aa0d2d51fbde
Get rid of relative imports in all unittests. Now anything that
Barry Warsaw <barry@python.org>
parents:
24326
diff
changeset
|
4 from test import test_support |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
5 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
6 import socket |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
7 import select |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
8 import time |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
9 import thread, threading |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
10 import Queue |
|
25152
0c9dfd5a06d4
Skip UDP testing for MacPython (for now), it hangs. This may be due to
Jack Jansen <jack.jansen@cwi.nl>
parents:
24772
diff
changeset
|
11 import sys |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
12 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
13 PORT = 50007 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
14 HOST = 'localhost' |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
15 MSG = 'Michael Gilfix was here\n' |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
16 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
17 class SocketTCPTest(unittest.TestCase): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
18 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
19 def setUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
20 self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
21 self.serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
22 self.serv.bind((HOST, PORT)) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
23 self.serv.listen(1) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
24 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
25 def tearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
26 self.serv.close() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
27 self.serv = None |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
28 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
29 class SocketUDPTest(unittest.TestCase): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
30 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
31 def setUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
32 self.serv = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
33 self.serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
34 self.serv.bind((HOST, PORT)) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
35 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
36 def tearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
37 self.serv.close() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
38 self.serv = None |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
39 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
40 class ThreadableTest: |
|
23909
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
41 """Threadable Test class |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
42 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
43 The ThreadableTest class makes it easy to create a threaded |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
44 client/server pair from an existing unit test. To create a |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
45 new threaded class from an existing unit test, use multiple |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
46 inheritance: |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
47 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
48 class NewClass (OldClass, ThreadableTest): |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
49 pass |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
50 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
51 This class defines two new fixture functions with obvious |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
52 purposes for overriding: |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
53 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
54 clientSetUp () |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
55 clientTearDown () |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
56 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
57 Any new test functions within the class must then define |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
58 tests in pairs, where the test name is preceeded with a |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
59 '_' to indicate the client portion of the test. Ex: |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
60 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
61 def testFoo(self): |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
62 # Server portion |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
63 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
64 def _testFoo(self): |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
65 # Client portion |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
66 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
67 Any exceptions raised by the clients during their tests |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
68 are caught and transferred to the main thread to alert |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
69 the testing framework. |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
70 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
71 Note, the server setup function cannot call any blocking |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
72 functions that rely on the client thread during setup, |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
73 unless serverExplicityReady() is called just before |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
74 the blocking call (such as in setting up a client/server |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
75 connection and performing the accept() in setUp(). |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
76 """ |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
77 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
78 def __init__(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
79 # Swap the true setup function |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
80 self.__setUp = self.setUp |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
81 self.__tearDown = self.tearDown |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
82 self.setUp = self._setUp |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
83 self.tearDown = self._tearDown |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
84 |
|
23909
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
85 def serverExplicitReady(self): |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
86 """This method allows the server to explicitly indicate that |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
87 it wants the client thread to proceed. This is useful if the |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
88 server is about to execute a blocking routine that is |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
89 dependent upon the client thread during its setup routine.""" |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
90 self.server_ready.set() |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
91 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
92 def _setUp(self): |
|
23909
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
93 self.server_ready = threading.Event() |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
94 self.client_ready = threading.Event() |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
95 self.done = threading.Event() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
96 self.queue = Queue.Queue(1) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
97 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
98 # Do some munging to start the client test. |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23814
diff
changeset
|
99 methodname = self.id() |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23814
diff
changeset
|
100 i = methodname.rfind('.') |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23814
diff
changeset
|
101 methodname = methodname[i+1:] |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23814
diff
changeset
|
102 test_method = getattr(self, '_' + methodname) |
|
23800
bf1555a92711
Remove some overly complicated ways to concatenate and repeat strings
Guido van Rossum <guido@python.org>
parents:
23799
diff
changeset
|
103 self.client_thread = thread.start_new_thread( |
|
bf1555a92711
Remove some overly complicated ways to concatenate and repeat strings
Guido van Rossum <guido@python.org>
parents:
23799
diff
changeset
|
104 self.clientRun, (test_method,)) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
105 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
106 self.__setUp() |
|
23909
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
107 if not self.server_ready.isSet(): |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
108 self.server_ready.set() |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
109 self.client_ready.wait() |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
110 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
111 def _tearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
112 self.__tearDown() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
113 self.done.wait() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
114 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
115 if not self.queue.empty(): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
116 msg = self.queue.get() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
117 self.fail(msg) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
118 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
119 def clientRun(self, test_func): |
|
23909
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
120 self.server_ready.wait() |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
121 self.client_ready.set() |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
122 self.clientSetUp() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
123 if not callable(test_func): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
124 raise TypeError, "test_func must be a callable function" |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
125 try: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
126 test_func() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
127 except Exception, strerror: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
128 self.queue.put(strerror) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
129 self.clientTearDown() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
130 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
131 def clientSetUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
132 raise NotImplementedError, "clientSetUp must be implemented." |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
133 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
134 def clientTearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
135 self.done.set() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
136 thread.exit() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
137 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
138 class ThreadedTCPSocketTest(SocketTCPTest, ThreadableTest): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
139 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
140 def __init__(self, methodName='runTest'): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
141 SocketTCPTest.__init__(self, methodName=methodName) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
142 ThreadableTest.__init__(self) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
143 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
144 def clientSetUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
145 self.cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
146 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
147 def clientTearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
148 self.cli.close() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
149 self.cli = None |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
150 ThreadableTest.clientTearDown(self) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
151 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
152 class ThreadedUDPSocketTest(SocketUDPTest, ThreadableTest): |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
153 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
154 def __init__(self, methodName='runTest'): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
155 SocketUDPTest.__init__(self, methodName=methodName) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
156 ThreadableTest.__init__(self) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
157 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
158 def clientSetUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
159 self.cli = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
160 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
161 class SocketConnectedTest(ThreadedTCPSocketTest): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
162 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
163 def __init__(self, methodName='runTest'): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
164 ThreadedTCPSocketTest.__init__(self, methodName=methodName) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
165 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
166 def setUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
167 ThreadedTCPSocketTest.setUp(self) |
|
23909
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
168 # Indicate explicitly we're ready for the client thread to |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
169 # proceed and then perform the blocking call to accept |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
170 self.serverExplicitReady() |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
171 conn, addr = self.serv.accept() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
172 self.cli_conn = conn |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
173 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
174 def tearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
175 self.cli_conn.close() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
176 self.cli_conn = None |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
177 ThreadedTCPSocketTest.tearDown(self) |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
178 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
179 def clientSetUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
180 ThreadedTCPSocketTest.clientSetUp(self) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
181 self.cli.connect((HOST, PORT)) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
182 self.serv_conn = self.cli |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
183 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
184 def clientTearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
185 self.serv_conn.close() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
186 self.serv_conn = None |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
187 ThreadedTCPSocketTest.clientTearDown(self) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
188 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
189 ####################################################################### |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
190 ## Begin Tests |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
191 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
192 class GeneralModuleTests(unittest.TestCase): |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
193 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
194 def testSocketError(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
195 # Testing socket module exceptions |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
196 def raise_error(*args, **kwargs): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
197 raise socket.error |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
198 def raise_herror(*args, **kwargs): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
199 raise socket.herror |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
200 def raise_gaierror(*args, **kwargs): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
201 raise socket.gaierror |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
202 self.failUnlessRaises(socket.error, raise_error, |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
203 "Error raising socket exception.") |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
204 self.failUnlessRaises(socket.error, raise_herror, |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
205 "Error raising socket exception.") |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
206 self.failUnlessRaises(socket.error, raise_gaierror, |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
207 "Error raising socket exception.") |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
208 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
209 def testCrucialConstants(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
210 # Testing for mission critical constants |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
211 socket.AF_INET |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
212 socket.SOCK_STREAM |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
213 socket.SOCK_DGRAM |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
214 socket.SOCK_RAW |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
215 socket.SOCK_RDM |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
216 socket.SOCK_SEQPACKET |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
217 socket.SOL_SOCKET |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
218 socket.SO_REUSEADDR |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
219 |
|
23831
f7306ae8662d
Temporarily disable the timeout and socket tests.
Guido van Rossum <guido@python.org>
parents:
23819
diff
changeset
|
220 def testHostnameRes(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
221 # Testing hostname resolution mechanisms |
|
23831
f7306ae8662d
Temporarily disable the timeout and socket tests.
Guido van Rossum <guido@python.org>
parents:
23819
diff
changeset
|
222 hostname = socket.gethostname() |
|
26799
507aa96a128f
Skip testHostnameRes() if gethostbyname() raises an exception.
Guido van Rossum <guido@python.org>
parents:
25285
diff
changeset
|
223 try: |
|
507aa96a128f
Skip testHostnameRes() if gethostbyname() raises an exception.
Guido van Rossum <guido@python.org>
parents:
25285
diff
changeset
|
224 ip = socket.gethostbyname(hostname) |
|
507aa96a128f
Skip testHostnameRes() if gethostbyname() raises an exception.
Guido van Rossum <guido@python.org>
parents:
25285
diff
changeset
|
225 except socket.error: |
|
507aa96a128f
Skip testHostnameRes() if gethostbyname() raises an exception.
Guido van Rossum <guido@python.org>
parents:
25285
diff
changeset
|
226 # Probably name lookup wasn't set up right; skip this test |
|
507aa96a128f
Skip testHostnameRes() if gethostbyname() raises an exception.
Guido van Rossum <guido@python.org>
parents:
25285
diff
changeset
|
227 return |
|
23831
f7306ae8662d
Temporarily disable the timeout and socket tests.
Guido van Rossum <guido@python.org>
parents:
23819
diff
changeset
|
228 self.assert_(ip.find('.') >= 0, "Error resolving host to ip.") |
|
26800
b2b4797052c6
Also skip testHostnameRes() if gethostbyaddr() raises an exception.
Guido van Rossum <guido@python.org>
parents:
26799
diff
changeset
|
229 try: |
|
b2b4797052c6
Also skip testHostnameRes() if gethostbyaddr() raises an exception.
Guido van Rossum <guido@python.org>
parents:
26799
diff
changeset
|
230 hname, aliases, ipaddrs = socket.gethostbyaddr(ip) |
|
b2b4797052c6
Also skip testHostnameRes() if gethostbyaddr() raises an exception.
Guido van Rossum <guido@python.org>
parents:
26799
diff
changeset
|
231 except socket.error: |
|
b2b4797052c6
Also skip testHostnameRes() if gethostbyaddr() raises an exception.
Guido van Rossum <guido@python.org>
parents:
26799
diff
changeset
|
232 # Probably a similar problem as above; skip this test |
|
b2b4797052c6
Also skip testHostnameRes() if gethostbyaddr() raises an exception.
Guido van Rossum <guido@python.org>
parents:
26799
diff
changeset
|
233 return |
|
23831
f7306ae8662d
Temporarily disable the timeout and socket tests.
Guido van Rossum <guido@python.org>
parents:
23819
diff
changeset
|
234 all_host_names = [hname] + aliases |
|
f7306ae8662d
Temporarily disable the timeout and socket tests.
Guido van Rossum <guido@python.org>
parents:
23819
diff
changeset
|
235 fqhn = socket.getfqdn() |
|
f7306ae8662d
Temporarily disable the timeout and socket tests.
Guido van Rossum <guido@python.org>
parents:
23819
diff
changeset
|
236 if not fqhn in all_host_names: |
|
f7306ae8662d
Temporarily disable the timeout and socket tests.
Guido van Rossum <guido@python.org>
parents:
23819
diff
changeset
|
237 self.fail("Error testing host resolution mechanisms.") |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
238 |
|
23799
2ad13ee6d850
Don't test for Java, test for sys.getrefcount.
Guido van Rossum <guido@python.org>
parents:
23798
diff
changeset
|
239 def testRefCountGetNameInfo(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
240 # Testing reference count for getnameinfo |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
241 import sys |
|
23799
2ad13ee6d850
Don't test for Java, test for sys.getrefcount.
Guido van Rossum <guido@python.org>
parents:
23798
diff
changeset
|
242 if hasattr(sys, "getrefcount"): |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
243 try: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
244 # On some versions, this loses a reference |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
245 orig = sys.getrefcount(__name__) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
246 socket.getnameinfo(__name__,0) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
247 except SystemError: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
248 if sys.getrefcount(__name__) <> orig: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
249 self.fail("socket.getnameinfo loses a reference") |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
250 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
251 def testInterpreterCrash(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
252 # Making sure getnameinfo doesn't crash the interpreter |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
253 try: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
254 # On some versions, this crashes the interpreter. |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
255 socket.getnameinfo(('x', 0, 0, 0), 0) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
256 except socket.error: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
257 pass |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
258 |
|
25285
4d6f8204234a
Since it tests both ntohl and ntohs, the test should not be called
Guido van Rossum <guido@python.org>
parents:
25256
diff
changeset
|
259 def testNtoH(self): |
|
25256
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
260 # This just checks that htons etc. are their own inverse, |
|
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
261 # when looking at the lower 16 or 32 bits. |
|
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
262 sizes = {socket.htonl: 32, socket.ntohl: 32, |
|
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
263 socket.htons: 16, socket.ntohs: 16} |
|
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
264 for func, size in sizes.items(): |
|
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
265 mask = (1L<<size) - 1 |
|
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
266 for i in (0, 1, 0xffff, ~0xffff, 2, 0x01234567, 0x76543210): |
|
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
267 self.assertEqual(i & mask, func(func(i&mask)) & mask) |
|
24450
747fa65a9b47
Repair testNtoH for large long arguments.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24375
diff
changeset
|
268 |
|
25256
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
269 swapped = func(mask) |
|
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
270 self.assertEqual(swapped & mask, mask) |
|
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
271 self.assertRaises(OverflowError, func, 1L<<34) |
|
24375
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24374
diff
changeset
|
272 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
273 def testGetServByName(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
274 # Testing getservbyname() |
|
24485
f05a311d7988
testGetServByName shouldn't check for getservbyname - the socket module
Skip Montanaro <skip@pobox.com>
parents:
24470
diff
changeset
|
275 # try a few protocols - not everyone has telnet enabled |
|
f05a311d7988
testGetServByName shouldn't check for getservbyname - the socket module
Skip Montanaro <skip@pobox.com>
parents:
24470
diff
changeset
|
276 found = 0 |
|
f05a311d7988
testGetServByName shouldn't check for getservbyname - the socket module
Skip Montanaro <skip@pobox.com>
parents:
24470
diff
changeset
|
277 for proto in ("telnet", "ssh", "www", "ftp"): |
|
f05a311d7988
testGetServByName shouldn't check for getservbyname - the socket module
Skip Montanaro <skip@pobox.com>
parents:
24470
diff
changeset
|
278 try: |
|
f05a311d7988
testGetServByName shouldn't check for getservbyname - the socket module
Skip Montanaro <skip@pobox.com>
parents:
24470
diff
changeset
|
279 socket.getservbyname(proto, 'tcp') |
|
f05a311d7988
testGetServByName shouldn't check for getservbyname - the socket module
Skip Montanaro <skip@pobox.com>
parents:
24470
diff
changeset
|
280 found = 1 |
|
f05a311d7988
testGetServByName shouldn't check for getservbyname - the socket module
Skip Montanaro <skip@pobox.com>
parents:
24470
diff
changeset
|
281 break |
|
f05a311d7988
testGetServByName shouldn't check for getservbyname - the socket module
Skip Montanaro <skip@pobox.com>
parents:
24470
diff
changeset
|
282 except socket.error: |
|
f05a311d7988
testGetServByName shouldn't check for getservbyname - the socket module
Skip Montanaro <skip@pobox.com>
parents:
24470
diff
changeset
|
283 pass |
|
f05a311d7988
testGetServByName shouldn't check for getservbyname - the socket module
Skip Montanaro <skip@pobox.com>
parents:
24470
diff
changeset
|
284 try: |
|
f05a311d7988
testGetServByName shouldn't check for getservbyname - the socket module
Skip Montanaro <skip@pobox.com>
parents:
24470
diff
changeset
|
285 socket.getservbyname(proto, 'udp') |
|
f05a311d7988
testGetServByName shouldn't check for getservbyname - the socket module
Skip Montanaro <skip@pobox.com>
parents:
24470
diff
changeset
|
286 found = 1 |
|
f05a311d7988
testGetServByName shouldn't check for getservbyname - the socket module
Skip Montanaro <skip@pobox.com>
parents:
24470
diff
changeset
|
287 break |
|
f05a311d7988
testGetServByName shouldn't check for getservbyname - the socket module
Skip Montanaro <skip@pobox.com>
parents:
24470
diff
changeset
|
288 except socket.error: |
|
f05a311d7988
testGetServByName shouldn't check for getservbyname - the socket module
Skip Montanaro <skip@pobox.com>
parents:
24470
diff
changeset
|
289 pass |
|
f05a311d7988
testGetServByName shouldn't check for getservbyname - the socket module
Skip Montanaro <skip@pobox.com>
parents:
24470
diff
changeset
|
290 if not found: |
|
f05a311d7988
testGetServByName shouldn't check for getservbyname - the socket module
Skip Montanaro <skip@pobox.com>
parents:
24470
diff
changeset
|
291 raise socket.error |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
292 |
|
24293
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
293 def testDefaultTimeout(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
294 # Testing default timeout |
|
24293
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
295 # The default timeout should initially be None |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
296 self.assertEqual(socket.getdefaulttimeout(), None) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
297 s = socket.socket() |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
298 self.assertEqual(s.gettimeout(), None) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
299 s.close() |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
300 |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
301 # Set the default timeout to 10, and see if it propagates |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
302 socket.setdefaulttimeout(10) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
303 self.assertEqual(socket.getdefaulttimeout(), 10) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
304 s = socket.socket() |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
305 self.assertEqual(s.gettimeout(), 10) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
306 s.close() |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
307 |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
308 # Reset the default timeout to None, and see if it propagates |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
309 socket.setdefaulttimeout(None) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
310 self.assertEqual(socket.getdefaulttimeout(), None) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
311 s = socket.socket() |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
312 self.assertEqual(s.gettimeout(), None) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
313 s.close() |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
314 |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
315 # Check that setting it to an invalid value raises ValueError |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
316 self.assertRaises(ValueError, socket.setdefaulttimeout, -1) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
317 |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
318 # Check that setting it to an invalid type raises TypeError |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
319 self.assertRaises(TypeError, socket.setdefaulttimeout, "spam") |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
320 |
|
24318
12815d05080c
Add test for previous core dump when sending on closed socket with
Guido van Rossum <guido@python.org>
parents:
24293
diff
changeset
|
321 # XXX The following don't test module-level functionality... |
|
24293
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
322 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
323 def testSockName(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
324 # Testing getsockname() |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
325 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
23798
1da6d67f4a05
Some provisional changes to get more tests to run on Windows (I hope).
Guido van Rossum <guido@python.org>
parents:
23797
diff
changeset
|
326 sock.bind(("0.0.0.0", PORT+1)) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
327 name = sock.getsockname() |
|
23798
1da6d67f4a05
Some provisional changes to get more tests to run on Windows (I hope).
Guido van Rossum <guido@python.org>
parents:
23797
diff
changeset
|
328 self.assertEqual(name, ("0.0.0.0", PORT+1)) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
329 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
330 def testGetSockOpt(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
331 # Testing getsockopt() |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
332 # We know a socket should start without reuse==0 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
333 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
334 reuse = sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR) |
|
23795
80d450e552f6
testSetSockOpt() should not require the reuse flag to be 1 -- any
Guido van Rossum <guido@python.org>
parents:
23794
diff
changeset
|
335 self.failIf(reuse != 0, "initial mode is reuse") |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
336 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
337 def testSetSockOpt(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
338 # Testing setsockopt() |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
339 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
340 sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
341 reuse = sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR) |
|
23795
80d450e552f6
testSetSockOpt() should not require the reuse flag to be 1 -- any
Guido van Rossum <guido@python.org>
parents:
23794
diff
changeset
|
342 self.failIf(reuse == 0, "failed to set reuse mode") |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
343 |
|
24318
12815d05080c
Add test for previous core dump when sending on closed socket with
Guido van Rossum <guido@python.org>
parents:
24293
diff
changeset
|
344 def testSendAfterClose(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
345 # testing send() after close() with timeout |
|
24318
12815d05080c
Add test for previous core dump when sending on closed socket with
Guido van Rossum <guido@python.org>
parents:
24293
diff
changeset
|
346 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
12815d05080c
Add test for previous core dump when sending on closed socket with
Guido van Rossum <guido@python.org>
parents:
24293
diff
changeset
|
347 sock.settimeout(1) |
|
12815d05080c
Add test for previous core dump when sending on closed socket with
Guido van Rossum <guido@python.org>
parents:
24293
diff
changeset
|
348 sock.close() |
|
12815d05080c
Add test for previous core dump when sending on closed socket with
Guido van Rossum <guido@python.org>
parents:
24293
diff
changeset
|
349 self.assertRaises(socket.error, sock.send, "spam") |
|
12815d05080c
Add test for previous core dump when sending on closed socket with
Guido van Rossum <guido@python.org>
parents:
24293
diff
changeset
|
350 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
351 class BasicTCPTest(SocketConnectedTest): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
352 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
353 def __init__(self, methodName='runTest'): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
354 SocketConnectedTest.__init__(self, methodName=methodName) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
355 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
356 def testRecv(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
357 # Testing large receive over TCP |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
358 msg = self.cli_conn.recv(1024) |
|
23794
1f1a6f7dd600
Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
359 self.assertEqual(msg, MSG) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
360 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
361 def _testRecv(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
362 self.serv_conn.send(MSG) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
363 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
364 def testOverFlowRecv(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
365 # Testing receive in chunks over TCP |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
366 seg1 = self.cli_conn.recv(len(MSG) - 3) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
367 seg2 = self.cli_conn.recv(1024) |
|
23800
bf1555a92711
Remove some overly complicated ways to concatenate and repeat strings
Guido van Rossum <guido@python.org>
parents:
23799
diff
changeset
|
368 msg = seg1 + seg2 |
|
23794
1f1a6f7dd600
Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
369 self.assertEqual(msg, MSG) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
370 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
371 def _testOverFlowRecv(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
372 self.serv_conn.send(MSG) |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
373 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
374 def testRecvFrom(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
375 # Testing large recvfrom() over TCP |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
376 msg, addr = self.cli_conn.recvfrom(1024) |
|
23794
1f1a6f7dd600
Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
377 self.assertEqual(msg, MSG) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
378 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
379 def _testRecvFrom(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
380 self.serv_conn.send(MSG) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
381 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
382 def testOverFlowRecvFrom(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
383 # Testing recvfrom() in chunks over TCP |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
384 seg1, addr = self.cli_conn.recvfrom(len(MSG)-3) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
385 seg2, addr = self.cli_conn.recvfrom(1024) |
|
23800
bf1555a92711
Remove some overly complicated ways to concatenate and repeat strings
Guido van Rossum <guido@python.org>
parents:
23799
diff
changeset
|
386 msg = seg1 + seg2 |
|
23794
1f1a6f7dd600
Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
387 self.assertEqual(msg, MSG) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
388 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
389 def _testOverFlowRecvFrom(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
390 self.serv_conn.send(MSG) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
391 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
392 def testSendAll(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
393 # Testing sendall() with a 2048 byte string over TCP |
|
24675
fec0b0aef14b
testSendAll(): loop until all data is read; this was necessary at
Guido van Rossum <guido@python.org>
parents:
24674
diff
changeset
|
394 msg = '' |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
395 while 1: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
396 read = self.cli_conn.recv(1024) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
397 if not read: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
398 break |
|
24675
fec0b0aef14b
testSendAll(): loop until all data is read; this was necessary at
Guido van Rossum <guido@python.org>
parents:
24674
diff
changeset
|
399 msg += read |
|
fec0b0aef14b
testSendAll(): loop until all data is read; this was necessary at
Guido van Rossum <guido@python.org>
parents:
24674
diff
changeset
|
400 self.assertEqual(msg, 'f' * 2048) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
401 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
402 def _testSendAll(self): |
|
23800
bf1555a92711
Remove some overly complicated ways to concatenate and repeat strings
Guido van Rossum <guido@python.org>
parents:
23799
diff
changeset
|
403 big_chunk = 'f' * 2048 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
404 self.serv_conn.sendall(big_chunk) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
405 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
406 def testFromFd(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
407 # Testing fromfd() |
| 23797 | 408 if not hasattr(socket, "fromfd"): |
|
23796
fcc36ee1924b
Allow absent fromfd(), for Windows.
Guido van Rossum <guido@python.org>
parents:
23795
diff
changeset
|
409 return # On Windows, this doesn't exist |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
410 fd = self.cli_conn.fileno() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
411 sock = socket.fromfd(fd, socket.AF_INET, socket.SOCK_STREAM) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
412 msg = sock.recv(1024) |
|
23794
1f1a6f7dd600
Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
413 self.assertEqual(msg, MSG) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
414 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
415 def _testFromFd(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
416 self.serv_conn.send(MSG) |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
417 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
418 def testShutdown(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
419 # Testing shutdown() |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
420 msg = self.cli_conn.recv(1024) |
|
23794
1f1a6f7dd600
Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
421 self.assertEqual(msg, MSG) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
422 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
423 def _testShutdown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
424 self.serv_conn.send(MSG) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
425 self.serv_conn.shutdown(2) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
426 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
427 class BasicUDPTest(ThreadedUDPSocketTest): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
428 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
429 def __init__(self, methodName='runTest'): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
430 ThreadedUDPSocketTest.__init__(self, methodName=methodName) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
431 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
432 def testSendtoAndRecv(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
433 # Testing sendto() and Recv() over UDP |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
434 msg = self.serv.recv(len(MSG)) |
|
23794
1f1a6f7dd600
Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
435 self.assertEqual(msg, MSG) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
436 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
437 def _testSendtoAndRecv(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
438 self.cli.sendto(MSG, 0, (HOST, PORT)) |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
439 |
|
23798
1da6d67f4a05
Some provisional changes to get more tests to run on Windows (I hope).
Guido van Rossum <guido@python.org>
parents:
23797
diff
changeset
|
440 def testRecvFrom(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
441 # Testing recvfrom() over UDP |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
442 msg, addr = self.serv.recvfrom(len(MSG)) |
|
23794
1f1a6f7dd600
Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
443 self.assertEqual(msg, MSG) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
444 |
|
23798
1da6d67f4a05
Some provisional changes to get more tests to run on Windows (I hope).
Guido van Rossum <guido@python.org>
parents:
23797
diff
changeset
|
445 def _testRecvFrom(self): |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
446 self.cli.sendto(MSG, 0, (HOST, PORT)) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
447 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
448 class NonBlockingTCPTests(ThreadedTCPSocketTest): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
449 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
450 def __init__(self, methodName='runTest'): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
451 ThreadedTCPSocketTest.__init__(self, methodName=methodName) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
452 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
453 def testSetBlocking(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
454 # Testing whether set blocking works |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
455 self.serv.setblocking(0) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
456 start = time.time() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
457 try: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
458 self.serv.accept() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
459 except socket.error: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
460 pass |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
461 end = time.time() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
462 self.assert_((end - start) < 1.0, "Error setting non-blocking mode.") |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
463 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
464 def _testSetBlocking(self): |
|
17208
c8817a9bbbdd
Make socket.getservbyname test optional on socket module having that
Barry Warsaw <barry@python.org>
parents:
16519
diff
changeset
|
465 pass |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
466 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
467 def testAccept(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
468 # Testing non-blocking accept |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
469 self.serv.setblocking(0) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
470 try: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
471 conn, addr = self.serv.accept() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
472 except socket.error: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
473 pass |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
474 else: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
475 self.fail("Error trying to do non-blocking accept.") |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
476 read, write, err = select.select([self.serv], [], []) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
477 if self.serv in read: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
478 conn, addr = self.serv.accept() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
479 else: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
480 self.fail("Error trying to do accept after select.") |
|
20853
77bb2ae067c2
Correct getnameinfo refcounting and tuple parsing. Fixes #476648.
Martin v. Löwis <martin@v.loewis.de>
parents:
20733
diff
changeset
|
481 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
482 def _testAccept(self): |
|
24318
12815d05080c
Add test for previous core dump when sending on closed socket with
Guido van Rossum <guido@python.org>
parents:
24293
diff
changeset
|
483 time.sleep(0.1) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
484 self.cli.connect((HOST, PORT)) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
485 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
486 def testConnect(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
487 # Testing non-blocking connect |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
488 conn, addr = self.serv.accept() |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
489 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
490 def _testConnect(self): |
|
23818
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
491 self.cli.settimeout(10) |
|
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
492 self.cli.connect((HOST, PORT)) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
493 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
494 def testRecv(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
495 # Testing non-blocking recv |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
496 conn, addr = self.serv.accept() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
497 conn.setblocking(0) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
498 try: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
499 msg = conn.recv(len(MSG)) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
500 except socket.error: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
501 pass |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
502 else: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
503 self.fail("Error trying to do non-blocking recv.") |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
504 read, write, err = select.select([conn], [], []) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
505 if conn in read: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
506 msg = conn.recv(len(MSG)) |
|
23794
1f1a6f7dd600
Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
507 self.assertEqual(msg, MSG) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
508 else: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
509 self.fail("Error during select call to non-blocking socket.") |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
510 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
511 def _testRecv(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
512 self.cli.connect((HOST, PORT)) |
|
24318
12815d05080c
Add test for previous core dump when sending on closed socket with
Guido van Rossum <guido@python.org>
parents:
24293
diff
changeset
|
513 time.sleep(0.1) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
514 self.cli.send(MSG) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
515 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
516 class FileObjectClassTestCase(SocketConnectedTest): |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21315
diff
changeset
|
517 |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
518 bufsize = -1 # Use default buffer size |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
519 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
520 def __init__(self, methodName='runTest'): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
521 SocketConnectedTest.__init__(self, methodName=methodName) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
522 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
523 def setUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
524 SocketConnectedTest.setUp(self) |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
525 self.serv_file = self.cli_conn.makefile('rb', self.bufsize) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
526 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
527 def tearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
528 self.serv_file.close() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
529 self.serv_file = None |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
530 SocketConnectedTest.tearDown(self) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
531 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
532 def clientSetUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
533 SocketConnectedTest.clientSetUp(self) |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
534 self.cli_file = self.serv_conn.makefile('wb') |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21315
diff
changeset
|
535 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
536 def clientTearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
537 self.cli_file.close() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
538 self.cli_file = None |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
539 SocketConnectedTest.clientTearDown(self) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
540 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
541 def testSmallRead(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
542 # Performing small file read test |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
543 first_seg = self.serv_file.read(len(MSG)-3) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
544 second_seg = self.serv_file.read(3) |
|
23800
bf1555a92711
Remove some overly complicated ways to concatenate and repeat strings
Guido van Rossum <guido@python.org>
parents:
23799
diff
changeset
|
545 msg = first_seg + second_seg |
|
23794
1f1a6f7dd600
Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
546 self.assertEqual(msg, MSG) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
547 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
548 def _testSmallRead(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
549 self.cli_file.write(MSG) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
550 self.cli_file.flush() |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21315
diff
changeset
|
551 |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
552 def testFullRead(self): |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
553 # read until EOF |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
554 msg = self.serv_file.read() |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
555 self.assertEqual(msg, MSG) |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
556 |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
557 def _testFullRead(self): |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
558 self.cli_file.write(MSG) |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
559 self.cli_file.close() |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
560 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
561 def testUnbufferedRead(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
562 # Performing unbuffered file read test |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
563 buf = '' |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
564 while 1: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
565 char = self.serv_file.read(1) |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
566 if not char: |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
567 break |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
568 buf += char |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
569 self.assertEqual(buf, MSG) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
570 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
571 def _testUnbufferedRead(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
572 self.cli_file.write(MSG) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
573 self.cli_file.flush() |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21315
diff
changeset
|
574 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
575 def testReadline(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
576 # Performing file readline test |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
577 line = self.serv_file.readline() |
|
23794
1f1a6f7dd600
Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
578 self.assertEqual(line, MSG) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
579 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
580 def _testReadline(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
581 self.cli_file.write(MSG) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
582 self.cli_file.flush() |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21315
diff
changeset
|
583 |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
584 class UnbufferedFileObjectClassTestCase(FileObjectClassTestCase): |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
585 |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
586 """Repeat the tests from FileObjectClassTestCase with bufsize==0. |
|
24674
3269bdd65988
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
24655
diff
changeset
|
587 |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
588 In this case (and in this case only), it should be possible to |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
589 create a file object, read a line from it, create another file |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
590 object, read another line from it, without loss of data in the |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
591 first file object's buffer. Note that httplib relies on this |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
592 when reading multiple requests from the same socket.""" |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
593 |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
594 bufsize = 0 # Use unbuffered mode |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
595 |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
596 def testUnbufferedReadline(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
597 # Read a line, create a new file object, read another line with it |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
598 line = self.serv_file.readline() # first line |
|
24648
edf757213a92
Tighten the unbuffered readline test to distinguish between the two lines.
Guido van Rossum <guido@python.org>
parents:
24639
diff
changeset
|
599 self.assertEqual(line, "A. " + MSG) # first line |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
600 self.serv_file = self.cli_conn.makefile('rb', 0) |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
601 line = self.serv_file.readline() # second line |
|
24648
edf757213a92
Tighten the unbuffered readline test to distinguish between the two lines.
Guido van Rossum <guido@python.org>
parents:
24639
diff
changeset
|
602 self.assertEqual(line, "B. " + MSG) # second line |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
603 |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
604 def _testUnbufferedReadline(self): |
|
24648
edf757213a92
Tighten the unbuffered readline test to distinguish between the two lines.
Guido van Rossum <guido@python.org>
parents:
24639
diff
changeset
|
605 self.cli_file.write("A. " + MSG) |
|
edf757213a92
Tighten the unbuffered readline test to distinguish between the two lines.
Guido van Rossum <guido@python.org>
parents:
24639
diff
changeset
|
606 self.cli_file.write("B. " + MSG) |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
607 self.cli_file.flush() |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
608 |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
609 class LineBufferedFileObjectClassTestCase(FileObjectClassTestCase): |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
610 |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
611 bufsize = 1 # Default-buffered for reading; line-buffered for writing |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
612 |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
613 |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
614 class SmallBufferedFileObjectClassTestCase(FileObjectClassTestCase): |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
615 |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
616 bufsize = 2 # Exercise the buffering code |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
617 |
|
24451
22570e76cca1
Enable test_socket again, if only to prevent mistakes like Jeremy
Guido van Rossum <guido@python.org>
parents:
24450
diff
changeset
|
618 def test_main(): |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
619 suite = unittest.TestSuite() |
|
24639
fb1d0e55b152
Oops. I accidentally commented out some tests.
Guido van Rossum <guido@python.org>
parents:
24634
diff
changeset
|
620 suite.addTest(unittest.makeSuite(GeneralModuleTests)) |
|
fb1d0e55b152
Oops. I accidentally commented out some tests.
Guido van Rossum <guido@python.org>
parents:
24634
diff
changeset
|
621 suite.addTest(unittest.makeSuite(BasicTCPTest)) |
|
25152
0c9dfd5a06d4
Skip UDP testing for MacPython (for now), it hangs. This may be due to
Jack Jansen <jack.jansen@cwi.nl>
parents:
24772
diff
changeset
|
622 if sys.platform != 'mac': |
|
0c9dfd5a06d4
Skip UDP testing for MacPython (for now), it hangs. This may be due to
Jack Jansen <jack.jansen@cwi.nl>
parents:
24772
diff
changeset
|
623 suite.addTest(unittest.makeSuite(BasicUDPTest)) |
|
24639
fb1d0e55b152
Oops. I accidentally commented out some tests.
Guido van Rossum <guido@python.org>
parents:
24634
diff
changeset
|
624 suite.addTest(unittest.makeSuite(NonBlockingTCPTests)) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
625 suite.addTest(unittest.makeSuite(FileObjectClassTestCase)) |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
626 suite.addTest(unittest.makeSuite(UnbufferedFileObjectClassTestCase)) |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
627 suite.addTest(unittest.makeSuite(LineBufferedFileObjectClassTestCase)) |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
628 suite.addTest(unittest.makeSuite(SmallBufferedFileObjectClassTestCase)) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
629 test_support.run_suite(suite) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
630 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
631 if __name__ == "__main__": |
|
24451
22570e76cca1
Enable test_socket again, if only to prevent mistakes like Jeremy
Guido van Rossum <guido@python.org>
parents:
24450
diff
changeset
|
632 test_main() |
