Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_socket.py @ 24042:63fbbed10714 legacy-trunk
Simplify HTTPSConnection constructor.
See discussion in SF bug 458463.
| author | Jeremy Hylton <jeremy@alum.mit.edu> |
|---|---|
| date | Fri, 28 Jun 2002 23:38:14 +0000 |
| parents | e558a40b6b52 |
| children | 640370f08e2a |
| 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 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
4 import test_support |
|
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 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
11 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
12 PORT = 50007 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
13 HOST = 'localhost' |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
14 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
|
15 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
16 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
|
17 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
18 def setUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
19 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
|
20 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
|
21 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
|
22 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
|
23 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
24 def tearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
25 self.serv.close() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
26 self.serv = None |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
27 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
28 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
|
29 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
30 def setUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
31 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
|
32 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
|
33 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
|
34 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
35 def tearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
36 self.serv.close() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
37 self.serv = None |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
38 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
39 class ThreadableTest: |
|
23909
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
40 """Threadable Test class |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
41 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
42 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
|
43 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
|
44 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
|
45 inheritance: |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
46 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
47 class NewClass (OldClass, ThreadableTest): |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
48 pass |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
49 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
50 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
|
51 purposes for overriding: |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
52 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
53 clientSetUp () |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
54 clientTearDown () |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
55 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
56 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
|
57 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
|
58 '_' 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
|
59 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
60 def testFoo(self): |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
61 # Server portion |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
62 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
63 def _testFoo(self): |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
64 # Client portion |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
65 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
66 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
|
67 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
|
68 the testing framework. |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
69 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
70 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
|
71 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
|
72 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
|
73 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
|
74 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
|
75 """ |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
76 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
77 def __init__(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
78 # 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
|
79 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
|
80 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
|
81 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
|
82 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
|
83 |
|
23909
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
84 def serverExplicitReady(self): |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
85 """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
|
86 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
|
87 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
|
88 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
|
89 self.server_ready.set() |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
90 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
91 def _setUp(self): |
|
23909
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
92 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
|
93 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
|
94 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
|
95 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
|
96 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
97 # 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
|
98 methodname = self.id() |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23814
diff
changeset
|
99 i = methodname.rfind('.') |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23814
diff
changeset
|
100 methodname = methodname[i+1:] |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23814
diff
changeset
|
101 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
|
102 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
|
103 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
|
104 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
105 self.__setUp() |
|
23909
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
106 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
|
107 self.server_ready.set() |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
108 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
|
109 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
110 def _tearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
111 self.__tearDown() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
112 self.done.wait() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
113 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
114 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
|
115 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
|
116 self.fail(msg) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
117 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
118 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
|
119 self.server_ready.wait() |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
120 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
|
121 self.clientSetUp() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
122 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
|
123 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
|
124 try: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
125 test_func() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
126 except Exception, strerror: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
127 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
|
128 self.clientTearDown() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
129 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
130 def clientSetUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
131 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
|
132 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
133 def clientTearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
134 self.done.set() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
135 thread.exit() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
136 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
137 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
|
138 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
139 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
|
140 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
|
141 ThreadableTest.__init__(self) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
142 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
143 def clientSetUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
144 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
|
145 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
146 def clientTearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
147 self.cli.close() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
148 self.cli = None |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
149 ThreadableTest.clientTearDown(self) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
150 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
151 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
|
152 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
153 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
|
154 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
|
155 ThreadableTest.__init__(self) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
156 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
157 def clientSetUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
158 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
|
159 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
160 class SocketConnectedTest(ThreadedTCPSocketTest): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
161 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
162 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
|
163 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
|
164 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
165 def setUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
166 ThreadedTCPSocketTest.setUp(self) |
|
23909
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
167 # 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
|
168 # 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
|
169 self.serverExplicitReady() |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
170 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
|
171 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
|
172 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
173 def tearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
174 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
|
175 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
|
176 ThreadedTCPSocketTest.tearDown(self) |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
177 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
178 def clientSetUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
179 ThreadedTCPSocketTest.clientSetUp(self) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
180 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
|
181 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
|
182 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
183 def clientTearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
184 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
|
185 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
|
186 ThreadedTCPSocketTest.clientTearDown(self) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
187 |
|
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 ## Begin Tests |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
190 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
191 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
|
192 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
193 def testSocketError(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
194 """Testing that socket module exceptions.""" |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
195 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
|
196 raise socket.error |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
197 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
|
198 raise socket.herror |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
199 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
|
200 raise socket.gaierror |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
201 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
|
202 "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
|
203 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
|
204 "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
|
205 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
|
206 "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
|
207 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
208 def testCrucialConstants(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
209 """Testing for mission critical constants.""" |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
210 socket.AF_INET |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
211 socket.SOCK_STREAM |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
212 socket.SOCK_DGRAM |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
213 socket.SOCK_RAW |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
214 socket.SOCK_RDM |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
215 socket.SOCK_SEQPACKET |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
216 socket.SOL_SOCKET |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
217 socket.SO_REUSEADDR |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
218 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
219 def testNonCrucialConstants(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
220 """Testing for existance of non-crucial constants.""" |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
221 for const in ( |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
222 "AF_UNIX", |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
223 |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
224 "SO_DEBUG", "SO_ACCEPTCONN", "SO_REUSEADDR", "SO_KEEPALIVE", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
225 "SO_DONTROUTE", "SO_BROADCAST", "SO_USELOOPBACK", "SO_LINGER", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
226 "SO_OOBINLINE", "SO_REUSEPORT", "SO_SNDBUF", "SO_RCVBUF", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
227 "SO_SNDLOWAT", "SO_RCVLOWAT", "SO_SNDTIMEO", "SO_RCVTIMEO", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
228 "SO_ERROR", "SO_TYPE", "SOMAXCONN", |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
229 |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
230 "MSG_OOB", "MSG_PEEK", "MSG_DONTROUTE", "MSG_EOR", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
231 "MSG_TRUNC", "MSG_CTRUNC", "MSG_WAITALL", "MSG_BTAG", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
232 "MSG_ETAG", |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
233 |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
234 "SOL_SOCKET", |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
235 |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
236 "IPPROTO_IP", "IPPROTO_ICMP", "IPPROTO_IGMP", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
237 "IPPROTO_GGP", "IPPROTO_TCP", "IPPROTO_EGP", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
238 "IPPROTO_PUP", "IPPROTO_UDP", "IPPROTO_IDP", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
239 "IPPROTO_HELLO", "IPPROTO_ND", "IPPROTO_TP", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
240 "IPPROTO_XTP", "IPPROTO_EON", "IPPROTO_BIP", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
241 "IPPROTO_RAW", "IPPROTO_MAX", |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
242 |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
243 "IPPORT_RESERVED", "IPPORT_USERRESERVED", |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
244 |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
245 "INADDR_ANY", "INADDR_BROADCAST", "INADDR_LOOPBACK", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
246 "INADDR_UNSPEC_GROUP", "INADDR_ALLHOSTS_GROUP", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
247 "INADDR_MAX_LOCAL_GROUP", "INADDR_NONE", |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
248 |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
249 "IP_OPTIONS", "IP_HDRINCL", "IP_TOS", "IP_TTL", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
250 "IP_RECVOPTS", "IP_RECVRETOPTS", "IP_RECVDSTADDR", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
251 "IP_RETOPTS", "IP_MULTICAST_IF", "IP_MULTICAST_TTL", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
252 "IP_MULTICAST_LOOP", "IP_ADD_MEMBERSHIP", |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
253 "IP_DROP_MEMBERSHIP", |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
254 ): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
255 try: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
256 getattr(socket, const) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
257 except AttributeError: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
258 pass |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
259 |
|
23831
f7306ae8662d
Temporarily disable the timeout and socket tests.
Guido van Rossum <guido@python.org>
parents:
23819
diff
changeset
|
260 def testHostnameRes(self): |
|
f7306ae8662d
Temporarily disable the timeout and socket tests.
Guido van Rossum <guido@python.org>
parents:
23819
diff
changeset
|
261 """Testing hostname resolution mechanisms.""" |
|
f7306ae8662d
Temporarily disable the timeout and socket tests.
Guido van Rossum <guido@python.org>
parents:
23819
diff
changeset
|
262 hostname = socket.gethostname() |
|
f7306ae8662d
Temporarily disable the timeout and socket tests.
Guido van Rossum <guido@python.org>
parents:
23819
diff
changeset
|
263 ip = socket.gethostbyname(hostname) |
|
f7306ae8662d
Temporarily disable the timeout and socket tests.
Guido van Rossum <guido@python.org>
parents:
23819
diff
changeset
|
264 self.assert_(ip.find('.') >= 0, "Error resolving host to ip.") |
|
f7306ae8662d
Temporarily disable the timeout and socket tests.
Guido van Rossum <guido@python.org>
parents:
23819
diff
changeset
|
265 hname, aliases, ipaddrs = socket.gethostbyaddr(ip) |
|
f7306ae8662d
Temporarily disable the timeout and socket tests.
Guido van Rossum <guido@python.org>
parents:
23819
diff
changeset
|
266 all_host_names = [hname] + aliases |
|
f7306ae8662d
Temporarily disable the timeout and socket tests.
Guido van Rossum <guido@python.org>
parents:
23819
diff
changeset
|
267 fqhn = socket.getfqdn() |
|
f7306ae8662d
Temporarily disable the timeout and socket tests.
Guido van Rossum <guido@python.org>
parents:
23819
diff
changeset
|
268 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
|
269 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
|
270 |
|
23799
2ad13ee6d850
Don't test for Java, test for sys.getrefcount.
Guido van Rossum <guido@python.org>
parents:
23798
diff
changeset
|
271 def testRefCountGetNameInfo(self): |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
272 """Testing reference count for getnameinfo.""" |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
273 import sys |
|
23799
2ad13ee6d850
Don't test for Java, test for sys.getrefcount.
Guido van Rossum <guido@python.org>
parents:
23798
diff
changeset
|
274 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
|
275 try: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
276 # 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
|
277 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
|
278 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
|
279 except SystemError: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
280 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
|
281 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
|
282 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
283 def testInterpreterCrash(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
284 """Making sure getnameinfo doesn't crash the interpreter.""" |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
285 try: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
286 # 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
|
287 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
|
288 except socket.error: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
289 pass |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
290 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
291 def testGetServByName(self): |
|
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
|
292 """Testing getservbyname().""" |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
293 if hasattr(socket, 'getservbyname'): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
294 socket.getservbyname('telnet', 'tcp') |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
295 try: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
296 socket.getservbyname('telnet', 'udp') |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
297 except socket.error: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
298 pass |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
299 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
300 def testSockName(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
301 """Testing getsockname().""" |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
302 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
|
303 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
|
304 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
|
305 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
|
306 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
307 def testGetSockOpt(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
308 """Testing getsockopt().""" |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
309 # 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
|
310 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
|
311 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
|
312 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
|
313 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
314 def testSetSockOpt(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
315 """Testing setsockopt().""" |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
316 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
|
317 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
|
318 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
|
319 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
|
320 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
321 class BasicTCPTest(SocketConnectedTest): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
322 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
323 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
|
324 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
|
325 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
326 def testRecv(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
327 """Testing large receive over TCP.""" |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
328 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
|
329 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
|
330 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
331 def _testRecv(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
332 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
|
333 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
334 def testOverFlowRecv(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
335 """Testing receive in chunks over TCP.""" |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
336 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
|
337 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
|
338 msg = seg1 + seg2 |
|
23794
1f1a6f7dd600
Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
339 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
|
340 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
341 def _testOverFlowRecv(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
342 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
|
343 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
344 def testRecvFrom(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
345 """Testing large recvfrom() over TCP.""" |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
346 msg, addr = self.cli_conn.recvfrom(1024) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
347 hostname, port = addr |
|
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
|
348 ##self.assertEqual(hostname, socket.gethostbyname('localhost')) |
|
23794
1f1a6f7dd600
Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
349 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
|
350 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
351 def _testRecvFrom(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
352 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
|
353 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
354 def testOverFlowRecvFrom(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
355 """Testing recvfrom() in chunks over TCP.""" |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
356 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
|
357 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
|
358 msg = seg1 + seg2 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
359 hostname, port = addr |
|
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
|
360 ##self.assertEqual(hostname, socket.gethostbyname('localhost')) |
|
23794
1f1a6f7dd600
Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
361 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
|
362 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
363 def _testOverFlowRecvFrom(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
364 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
|
365 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
366 def testSendAll(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
367 """Testing sendall() with a 2048 byte string over TCP.""" |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
368 while 1: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
369 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
|
370 if not read: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
371 break |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
372 self.assert_(len(read) == 1024, "Error performing sendall.") |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
373 read = filter(lambda x: x == 'f', read) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
374 self.assert_(len(read) == 1024, "Error performing sendall.") |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
375 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
376 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
|
377 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
|
378 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
|
379 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
380 def testFromFd(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
381 """Testing fromfd().""" |
| 23797 | 382 if not hasattr(socket, "fromfd"): |
|
23796
fcc36ee1924b
Allow absent fromfd(), for Windows.
Guido van Rossum <guido@python.org>
parents:
23795
diff
changeset
|
383 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
|
384 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
|
385 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
|
386 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
|
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 _testFromFd(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) |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
391 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
392 def testShutdown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
393 """Testing shutdown().""" |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
394 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
|
395 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
|
396 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
397 def _testShutdown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
398 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
|
399 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
|
400 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
401 class BasicUDPTest(ThreadedUDPSocketTest): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
402 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
403 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
|
404 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
|
405 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
406 def testSendtoAndRecv(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
407 """Testing sendto() and Recv() over UDP.""" |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
408 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
|
409 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
|
410 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
411 def _testSendtoAndRecv(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
412 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
|
413 |
|
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
|
414 def testRecvFrom(self): |
| 23814 | 415 """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
|
416 msg, addr = self.serv.recvfrom(len(MSG)) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
417 hostname, port = addr |
|
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
|
418 ##self.assertEqual(hostname, socket.gethostbyname('localhost')) |
|
23794
1f1a6f7dd600
Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
419 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
|
420 |
|
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
|
421 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
|
422 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
|
423 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
424 class NonBlockingTCPTests(ThreadedTCPSocketTest): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
425 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
426 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
|
427 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
|
428 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
429 def testSetBlocking(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
430 """Testing whether set blocking works.""" |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
431 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
|
432 start = time.time() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
433 try: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
434 self.serv.accept() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
435 except socket.error: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
436 pass |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
437 end = time.time() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
438 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
|
439 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
440 def _testSetBlocking(self): |
|
17208
c8817a9bbbdd
Make socket.getservbyname test optional on socket module having that
Barry Warsaw <barry@python.org>
parents:
16519
diff
changeset
|
441 pass |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
442 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
443 def testAccept(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
444 """Testing non-blocking accept.""" |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
445 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
|
446 try: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
447 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
|
448 except socket.error: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
449 pass |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
450 else: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
451 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
|
452 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
|
453 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
|
454 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
|
455 else: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
456 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
|
457 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
458 def _testAccept(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
459 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
|
460 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
461 def testConnect(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
462 """Testing non-blocking connect.""" |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
463 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
|
464 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
465 def _testConnect(self): |
|
23818
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
466 self.cli.settimeout(10) |
|
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
467 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
|
468 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
469 def testRecv(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
470 """Testing non-blocking recv.""" |
|
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 conn.setblocking(0) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
473 try: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
474 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
|
475 except socket.error: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
476 pass |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
477 else: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
478 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
|
479 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
|
480 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
|
481 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
|
482 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
|
483 else: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
484 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
|
485 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
486 def _testRecv(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
487 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
|
488 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
|
489 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
490 class FileObjectClassTestCase(SocketConnectedTest): |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21315
diff
changeset
|
491 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
492 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
|
493 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
|
494 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
495 def setUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
496 SocketConnectedTest.setUp(self) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
497 self.serv_file = socket._fileobject(self.cli_conn, 'rb', 8192) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
498 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
499 def tearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
500 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
|
501 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
|
502 SocketConnectedTest.tearDown(self) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
503 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
504 def clientSetUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
505 SocketConnectedTest.clientSetUp(self) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
506 self.cli_file = socket._fileobject(self.serv_conn, 'rb', 8192) |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21315
diff
changeset
|
507 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
508 def clientTearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
509 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
|
510 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
|
511 SocketConnectedTest.clientTearDown(self) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
512 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
513 def testSmallRead(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
514 """Performing small file read test.""" |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
515 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
|
516 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
|
517 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
|
518 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
|
519 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
520 def _testSmallRead(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
521 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
|
522 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
|
523 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
524 def testUnbufferedRead(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
525 """Performing unbuffered file read test.""" |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
526 buf = '' |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
527 while 1: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
528 char = self.serv_file.read(1) |
|
23794
1f1a6f7dd600
Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
529 self.failIf(not char) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
530 buf += char |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
531 if buf == MSG: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
532 break |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
533 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
534 def _testUnbufferedRead(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
535 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
|
536 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
|
537 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
538 def testReadline(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
539 """Performing file readline test.""" |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
540 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
|
541 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
|
542 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
543 def _testReadline(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
544 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
|
545 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
|
546 |
|
23931
e558a40b6b52
I get failures half of the time that I run this, so I'll disable
Guido van Rossum <guido@python.org>
parents:
23909
diff
changeset
|
547 def main(): |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
548 suite = unittest.TestSuite() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
549 suite.addTest(unittest.makeSuite(GeneralModuleTests)) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
550 suite.addTest(unittest.makeSuite(BasicTCPTest)) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
551 suite.addTest(unittest.makeSuite(BasicUDPTest)) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
552 suite.addTest(unittest.makeSuite(NonBlockingTCPTests)) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
553 suite.addTest(unittest.makeSuite(FileObjectClassTestCase)) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
554 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
|
555 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
556 if __name__ == "__main__": |
|
23931
e558a40b6b52
I get failures half of the time that I run this, so I'll disable
Guido van Rossum <guido@python.org>
parents:
23909
diff
changeset
|
557 main() |
