Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_socket.py @ 49258:25f809123df6 legacy-trunk
Issue #3925: Ignores shutil.rmtree error on cygwin too.
Reviewed by Benjamin Peterson.
| author | Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> |
|---|---|
| date | Sun, 21 Sep 2008 20:48:41 +0000 |
| parents | c349f9fbc704 |
| children | d0086c176e82 3378eafd27df |
| rev | line source |
|---|---|
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1 #!/usr/bin/env python |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
2 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3 import unittest |
|
24364
aa0d2d51fbde
Get rid of relative imports in all unittests. Now anything that
Barry Warsaw <barry@python.org>
parents:
24326
diff
changeset
|
4 from test import test_support |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
5 |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
6 import errno |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
7 import socket |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
8 import select |
|
46148
59d082591f56
Print more information the next time test_socket throws the wrong exception.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44770
diff
changeset
|
9 import thread, threading |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
10 import time |
|
46148
59d082591f56
Print more information the next time test_socket throws the wrong exception.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44770
diff
changeset
|
11 import traceback |
|
47248
9acb314b9072
Queue renaming reversal part 3: move module into place and
Georg Brandl <georg@python.org>
parents:
46897
diff
changeset
|
12 import Queue |
|
25152
0c9dfd5a06d4
Skip UDP testing for MacPython (for now), it hangs. This may be due to
Jack Jansen <jack.jansen@cwi.nl>
parents:
24772
diff
changeset
|
13 import sys |
|
44478
73bc002252bf
socket.ioctl is only available on Windows
Christian Heimes <christian@cheimes.de>
parents:
43703
diff
changeset
|
14 import os |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37853
diff
changeset
|
15 import array |
|
32160
aec9c98a47d2
Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents:
31833
diff
changeset
|
16 from weakref import proxy |
|
39354
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
17 import signal |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
18 |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
19 HOST = test_support.HOST |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
20 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
|
21 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
22 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
|
23 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
24 def setUp(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 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
26 self.port = test_support.bind_port(self.serv) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
27 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
|
28 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
29 def tearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
30 self.serv.close() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
31 self.serv = None |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
32 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
33 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
|
34 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
35 def setUp(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 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
37 self.port = test_support.bind_port(self.serv) |
|
23790
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 def tearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
40 self.serv.close() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
41 self.serv = None |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
42 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
43 class ThreadableTest: |
|
23909
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
44 """Threadable Test class |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
45 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
46 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
|
47 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
|
48 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
|
49 inheritance: |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
50 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
51 class NewClass (OldClass, ThreadableTest): |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
52 pass |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
53 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
54 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
|
55 purposes for overriding: |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
56 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
57 clientSetUp () |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
58 clientTearDown () |
|
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 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
|
61 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
|
62 '_' 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
|
63 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
64 def testFoo(self): |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
65 # Server portion |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
66 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
67 def _testFoo(self): |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
68 # Client portion |
|
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 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
|
71 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
|
72 the testing framework. |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
73 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
74 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
|
75 functions that rely on the client thread during setup, |
|
41288
a73aa0b821ca
Added a 'create_connect()' function to socket.py, which creates a
Facundo Batista <facundobatista@gmail.com>
parents:
40684
diff
changeset
|
76 unless serverExplicitReady() is called just before |
|
23909
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
77 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
|
78 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
|
79 """ |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
80 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
81 def __init__(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
82 # 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
|
83 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
|
84 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
|
85 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
|
86 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
|
87 |
|
23909
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
88 def serverExplicitReady(self): |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
89 """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
|
90 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
|
91 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
|
92 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
|
93 self.server_ready.set() |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
94 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
95 def _setUp(self): |
|
23909
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
96 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
|
97 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
|
98 self.done = threading.Event() |
|
47248
9acb314b9072
Queue renaming reversal part 3: move module into place and
Georg Brandl <georg@python.org>
parents:
46897
diff
changeset
|
99 self.queue = Queue.Queue(1) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
100 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
101 # 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
|
102 methodname = self.id() |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23814
diff
changeset
|
103 i = methodname.rfind('.') |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23814
diff
changeset
|
104 methodname = methodname[i+1:] |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23814
diff
changeset
|
105 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
|
106 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
|
107 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
|
108 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
109 self.__setUp() |
|
47598
c349f9fbc704
give the threading API PEP 8 names
Benjamin Peterson <benjamin@python.org>
parents:
47372
diff
changeset
|
110 if not self.server_ready.is_set(): |
|
23909
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
111 self.server_ready.set() |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
112 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
|
113 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
114 def _tearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
115 self.__tearDown() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
116 self.done.wait() |
|
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 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
|
119 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
|
120 self.fail(msg) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
121 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
122 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
|
123 self.server_ready.wait() |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
124 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
|
125 self.clientSetUp() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
126 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
|
127 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
|
128 try: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
129 test_func() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
130 except Exception, strerror: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
131 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
|
132 self.clientTearDown() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
133 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
134 def clientSetUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
135 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
|
136 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
137 def clientTearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
138 self.done.set() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
139 thread.exit() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
140 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
141 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
|
142 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
143 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
|
144 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
|
145 ThreadableTest.__init__(self) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
146 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
147 def clientSetUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
148 self.cli = 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
|
149 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
150 def clientTearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
151 self.cli.close() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
152 self.cli = None |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
153 ThreadableTest.clientTearDown(self) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
154 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
155 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
|
156 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
157 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
|
158 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
|
159 ThreadableTest.__init__(self) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
160 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
161 def clientSetUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
162 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
|
163 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
164 class SocketConnectedTest(ThreadedTCPSocketTest): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
165 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
166 def __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
|
167 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
|
168 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
169 def setUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
170 ThreadedTCPSocketTest.setUp(self) |
|
23909
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
171 # 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
|
172 # 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
|
173 self.serverExplicitReady() |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
174 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
|
175 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
|
176 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
177 def tearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
178 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
|
179 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
|
180 ThreadedTCPSocketTest.tearDown(self) |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
181 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
182 def clientSetUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
183 ThreadedTCPSocketTest.clientSetUp(self) |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
184 self.cli.connect((HOST, self.port)) |
|
23790
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 = self.cli |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
186 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
187 def clientTearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
188 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
|
189 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
|
190 ThreadedTCPSocketTest.clientTearDown(self) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
191 |
|
33063
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
192 class SocketPairTest(unittest.TestCase, ThreadableTest): |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
193 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
194 def __init__(self, methodName='runTest'): |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
195 unittest.TestCase.__init__(self, methodName=methodName) |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
196 ThreadableTest.__init__(self) |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
197 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
198 def setUp(self): |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
199 self.serv, self.cli = socket.socketpair() |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
200 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
201 def tearDown(self): |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
202 self.serv.close() |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
203 self.serv = None |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
204 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
205 def clientSetUp(self): |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
206 pass |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
207 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
208 def clientTearDown(self): |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
209 self.cli.close() |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
210 self.cli = None |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
211 ThreadableTest.clientTearDown(self) |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
212 |
|
33076
836e77266f97
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
33063
diff
changeset
|
213 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
214 ####################################################################### |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
215 ## Begin Tests |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
216 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
217 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
|
218 |
|
32160
aec9c98a47d2
Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents:
31833
diff
changeset
|
219 def test_weakref(self): |
|
aec9c98a47d2
Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents:
31833
diff
changeset
|
220 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
aec9c98a47d2
Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents:
31833
diff
changeset
|
221 p = proxy(s) |
|
aec9c98a47d2
Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents:
31833
diff
changeset
|
222 self.assertEqual(p.fileno(), s.fileno()) |
|
aec9c98a47d2
Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents:
31833
diff
changeset
|
223 s.close() |
|
aec9c98a47d2
Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents:
31833
diff
changeset
|
224 s = None |
|
aec9c98a47d2
Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents:
31833
diff
changeset
|
225 try: |
|
aec9c98a47d2
Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents:
31833
diff
changeset
|
226 p.fileno() |
|
aec9c98a47d2
Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents:
31833
diff
changeset
|
227 except ReferenceError: |
|
aec9c98a47d2
Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents:
31833
diff
changeset
|
228 pass |
|
aec9c98a47d2
Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents:
31833
diff
changeset
|
229 else: |
|
aec9c98a47d2
Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents:
31833
diff
changeset
|
230 self.fail('Socket proxy still exists') |
|
aec9c98a47d2
Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents:
31833
diff
changeset
|
231 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
232 def testSocketError(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
233 # Testing socket module exceptions |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
234 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
|
235 raise socket.error |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
236 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
|
237 raise socket.herror |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
238 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
|
239 raise socket.gaierror |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
240 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
|
241 "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
|
242 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
|
243 "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
|
244 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
|
245 "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
|
246 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
247 def testCrucialConstants(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
248 # Testing for mission critical constants |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
249 socket.AF_INET |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
250 socket.SOCK_STREAM |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
251 socket.SOCK_DGRAM |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
252 socket.SOCK_RAW |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
253 socket.SOCK_RDM |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
254 socket.SOCK_SEQPACKET |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
255 socket.SOL_SOCKET |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
256 socket.SO_REUSEADDR |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
257 |
|
23831
f7306ae8662d
Temporarily disable the timeout and socket tests.
Guido van Rossum <guido@python.org>
parents:
23819
diff
changeset
|
258 def testHostnameRes(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
259 # Testing hostname resolution mechanisms |
|
23831
f7306ae8662d
Temporarily disable the timeout and socket tests.
Guido van Rossum <guido@python.org>
parents:
23819
diff
changeset
|
260 hostname = socket.gethostname() |
|
26799
507aa96a128f
Skip testHostnameRes() if gethostbyname() raises an exception.
Guido van Rossum <guido@python.org>
parents:
25285
diff
changeset
|
261 try: |
|
507aa96a128f
Skip testHostnameRes() if gethostbyname() raises an exception.
Guido van Rossum <guido@python.org>
parents:
25285
diff
changeset
|
262 ip = socket.gethostbyname(hostname) |
|
507aa96a128f
Skip testHostnameRes() if gethostbyname() raises an exception.
Guido van Rossum <guido@python.org>
parents:
25285
diff
changeset
|
263 except socket.error: |
|
507aa96a128f
Skip testHostnameRes() if gethostbyname() raises an exception.
Guido van Rossum <guido@python.org>
parents:
25285
diff
changeset
|
264 # Probably name lookup wasn't set up right; skip this test |
|
507aa96a128f
Skip testHostnameRes() if gethostbyname() raises an exception.
Guido van Rossum <guido@python.org>
parents:
25285
diff
changeset
|
265 return |
|
23831
f7306ae8662d
Temporarily disable the timeout and socket tests.
Guido van Rossum <guido@python.org>
parents:
23819
diff
changeset
|
266 self.assert_(ip.find('.') >= 0, "Error resolving host to ip.") |
|
26800
b2b4797052c6
Also skip testHostnameRes() if gethostbyaddr() raises an exception.
Guido van Rossum <guido@python.org>
parents:
26799
diff
changeset
|
267 try: |
|
b2b4797052c6
Also skip testHostnameRes() if gethostbyaddr() raises an exception.
Guido van Rossum <guido@python.org>
parents:
26799
diff
changeset
|
268 hname, aliases, ipaddrs = socket.gethostbyaddr(ip) |
|
b2b4797052c6
Also skip testHostnameRes() if gethostbyaddr() raises an exception.
Guido van Rossum <guido@python.org>
parents:
26799
diff
changeset
|
269 except socket.error: |
|
b2b4797052c6
Also skip testHostnameRes() if gethostbyaddr() raises an exception.
Guido van Rossum <guido@python.org>
parents:
26799
diff
changeset
|
270 # Probably a similar problem as above; skip this test |
|
b2b4797052c6
Also skip testHostnameRes() if gethostbyaddr() raises an exception.
Guido van Rossum <guido@python.org>
parents:
26799
diff
changeset
|
271 return |
|
34739
0c82a7ef9554
Fix test_socket's test for socket.getfqdn() to also accept the result from
Brett Cannon <bcannon@gmail.com>
parents:
34014
diff
changeset
|
272 all_host_names = [hostname, hname] + aliases |
|
37422
e956e16e7444
Deal with openbsd's different style of default /etc/hosts by forcing the fqdn
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37227
diff
changeset
|
273 fqhn = socket.getfqdn(ip) |
|
23831
f7306ae8662d
Temporarily disable the timeout and socket tests.
Guido van Rossum <guido@python.org>
parents:
23819
diff
changeset
|
274 if not fqhn in all_host_names: |
| 37227 | 275 self.fail("Error testing host resolution mechanisms. (fqdn: %s, all: %s)" % (fqhn, repr(all_host_names))) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
276 |
|
23799
2ad13ee6d850
Don't test for Java, test for sys.getrefcount.
Guido van Rossum <guido@python.org>
parents:
23798
diff
changeset
|
277 def testRefCountGetNameInfo(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
278 # Testing reference count for getnameinfo |
|
23799
2ad13ee6d850
Don't test for Java, test for sys.getrefcount.
Guido van Rossum <guido@python.org>
parents:
23798
diff
changeset
|
279 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
|
280 try: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
281 # 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
|
282 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
|
283 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
|
284 except SystemError: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
285 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
|
286 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
|
287 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
288 def testInterpreterCrash(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
289 # Making sure getnameinfo doesn't crash the interpreter |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
290 try: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
291 # 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
|
292 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
|
293 except socket.error: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
294 pass |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
295 |
|
25285
4d6f8204234a
Since it tests both ntohl and ntohs, the test should not be called
Guido van Rossum <guido@python.org>
parents:
25256
diff
changeset
|
296 def testNtoH(self): |
|
25256
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
297 # This just checks that htons etc. are their own inverse, |
|
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
298 # when looking at the lower 16 or 32 bits. |
|
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
299 sizes = {socket.htonl: 32, socket.ntohl: 32, |
|
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
300 socket.htons: 16, socket.ntohs: 16} |
|
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
301 for func, size in sizes.items(): |
|
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
302 mask = (1L<<size) - 1 |
|
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
303 for i in (0, 1, 0xffff, ~0xffff, 2, 0x01234567, 0x76543210): |
|
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
304 self.assertEqual(i & mask, func(func(i&mask)) & mask) |
|
24450
747fa65a9b47
Repair testNtoH for large long arguments.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24375
diff
changeset
|
305 |
|
25256
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
306 swapped = func(mask) |
|
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
307 self.assertEqual(swapped & mask, mask) |
|
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
308 self.assertRaises(OverflowError, func, 1L<<34) |
|
24375
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24374
diff
changeset
|
309 |
|
40632
6efe3a4b10ac
Patch #1635058 by Mark Roberts: ensure that htonl and friends never accept or
Guido van Rossum <guido@python.org>
parents:
39354
diff
changeset
|
310 def testNtoHErrors(self): |
|
6efe3a4b10ac
Patch #1635058 by Mark Roberts: ensure that htonl and friends never accept or
Guido van Rossum <guido@python.org>
parents:
39354
diff
changeset
|
311 good_values = [ 1, 2, 3, 1L, 2L, 3L ] |
|
6efe3a4b10ac
Patch #1635058 by Mark Roberts: ensure that htonl and friends never accept or
Guido van Rossum <guido@python.org>
parents:
39354
diff
changeset
|
312 bad_values = [ -1, -2, -3, -1L, -2L, -3L ] |
|
6efe3a4b10ac
Patch #1635058 by Mark Roberts: ensure that htonl and friends never accept or
Guido van Rossum <guido@python.org>
parents:
39354
diff
changeset
|
313 for k in good_values: |
|
6efe3a4b10ac
Patch #1635058 by Mark Roberts: ensure that htonl and friends never accept or
Guido van Rossum <guido@python.org>
parents:
39354
diff
changeset
|
314 socket.ntohl(k) |
|
6efe3a4b10ac
Patch #1635058 by Mark Roberts: ensure that htonl and friends never accept or
Guido van Rossum <guido@python.org>
parents:
39354
diff
changeset
|
315 socket.ntohs(k) |
|
6efe3a4b10ac
Patch #1635058 by Mark Roberts: ensure that htonl and friends never accept or
Guido van Rossum <guido@python.org>
parents:
39354
diff
changeset
|
316 socket.htonl(k) |
|
6efe3a4b10ac
Patch #1635058 by Mark Roberts: ensure that htonl and friends never accept or
Guido van Rossum <guido@python.org>
parents:
39354
diff
changeset
|
317 socket.htons(k) |
|
6efe3a4b10ac
Patch #1635058 by Mark Roberts: ensure that htonl and friends never accept or
Guido van Rossum <guido@python.org>
parents:
39354
diff
changeset
|
318 for k in bad_values: |
|
6efe3a4b10ac
Patch #1635058 by Mark Roberts: ensure that htonl and friends never accept or
Guido van Rossum <guido@python.org>
parents:
39354
diff
changeset
|
319 self.assertRaises(OverflowError, socket.ntohl, k) |
|
6efe3a4b10ac
Patch #1635058 by Mark Roberts: ensure that htonl and friends never accept or
Guido van Rossum <guido@python.org>
parents:
39354
diff
changeset
|
320 self.assertRaises(OverflowError, socket.ntohs, k) |
|
6efe3a4b10ac
Patch #1635058 by Mark Roberts: ensure that htonl and friends never accept or
Guido van Rossum <guido@python.org>
parents:
39354
diff
changeset
|
321 self.assertRaises(OverflowError, socket.htonl, k) |
|
6efe3a4b10ac
Patch #1635058 by Mark Roberts: ensure that htonl and friends never accept or
Guido van Rossum <guido@python.org>
parents:
39354
diff
changeset
|
322 self.assertRaises(OverflowError, socket.htons, k) |
|
6efe3a4b10ac
Patch #1635058 by Mark Roberts: ensure that htonl and friends never accept or
Guido van Rossum <guido@python.org>
parents:
39354
diff
changeset
|
323 |
|
32429
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
324 def testGetServBy(self): |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
325 eq = self.assertEqual |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
326 # Find one service that exists, then check all the related interfaces. |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
327 # I've ordered this by protocols that have both a tcp and udp |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
328 # protocol, at least for modern Linuxes. |
|
34014
8daa5a448403
Add 'linux2' as one of the platforms that does not use the echo service as one
Brett Cannon <bcannon@gmail.com>
parents:
33180
diff
changeset
|
329 if sys.platform in ('linux2', 'freebsd4', 'freebsd5', 'freebsd6', |
|
43703
365913d7af7d
Enable platform-specific tweaks for FreeBSD 8 (exactly same to FreeBSD 7's yet)
Hye-Shik Chang <hyeshik@gmail.com>
parents:
41532
diff
changeset
|
330 'freebsd7', 'freebsd8', 'darwin'): |
|
32630
059dae06585b
FreeBSD's services file contains an additional echo service entry, with
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
32508
diff
changeset
|
331 # avoid the 'echo' service on this platform, as there is an |
|
059dae06585b
FreeBSD's services file contains an additional echo service entry, with
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
32508
diff
changeset
|
332 # assumption breaking non-standard port/protocol entry |
|
059dae06585b
FreeBSD's services file contains an additional echo service entry, with
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
32508
diff
changeset
|
333 services = ('daytime', 'qotd', 'domain') |
|
059dae06585b
FreeBSD's services file contains an additional echo service entry, with
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
32508
diff
changeset
|
334 else: |
|
059dae06585b
FreeBSD's services file contains an additional echo service entry, with
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
32508
diff
changeset
|
335 services = ('echo', 'daytime', 'domain') |
|
059dae06585b
FreeBSD's services file contains an additional echo service entry, with
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
32508
diff
changeset
|
336 for service in services: |
|
24485
f05a311d7988
testGetServByName shouldn't check for getservbyname - the socket module
Skip Montanaro <skip@pobox.com>
parents:
24470
diff
changeset
|
337 try: |
|
32429
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
338 port = socket.getservbyname(service, 'tcp') |
|
24485
f05a311d7988
testGetServByName shouldn't check for getservbyname - the socket module
Skip Montanaro <skip@pobox.com>
parents:
24470
diff
changeset
|
339 break |
|
f05a311d7988
testGetServByName shouldn't check for getservbyname - the socket module
Skip Montanaro <skip@pobox.com>
parents:
24470
diff
changeset
|
340 except socket.error: |
|
f05a311d7988
testGetServByName shouldn't check for getservbyname - the socket module
Skip Montanaro <skip@pobox.com>
parents:
24470
diff
changeset
|
341 pass |
|
31503
eb48b2503f20
Fix indentation error in testGetServByName and rewrite loop to avoid clumsy
Skip Montanaro <skip@pobox.com>
parents:
29662
diff
changeset
|
342 else: |
|
eb48b2503f20
Fix indentation error in testGetServByName and rewrite loop to avoid clumsy
Skip Montanaro <skip@pobox.com>
parents:
29662
diff
changeset
|
343 raise socket.error |
|
32429
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
344 # Try same call with optional protocol omitted |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
345 port2 = socket.getservbyname(service) |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
346 eq(port, port2) |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
347 # Try udp, but don't barf it it doesn't exist |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
348 try: |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
349 udpport = socket.getservbyname(service, 'udp') |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
350 except socket.error: |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
351 udpport = None |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
352 else: |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
353 eq(udpport, port) |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
354 # Now make sure the lookup by port returns the same service name |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
355 eq(socket.getservbyport(port2), service) |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
356 eq(socket.getservbyport(port, 'tcp'), service) |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
357 if udpport is not None: |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
358 eq(socket.getservbyport(udpport, 'udp'), service) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
359 |
|
24293
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
360 def testDefaultTimeout(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
361 # Testing default timeout |
|
24293
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
362 # The default timeout should initially be None |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
363 self.assertEqual(socket.getdefaulttimeout(), None) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
364 s = socket.socket() |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
365 self.assertEqual(s.gettimeout(), None) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
366 s.close() |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
367 |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
368 # Set the default timeout to 10, and see if it propagates |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
369 socket.setdefaulttimeout(10) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
370 self.assertEqual(socket.getdefaulttimeout(), 10) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
371 s = socket.socket() |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
372 self.assertEqual(s.gettimeout(), 10) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
373 s.close() |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
374 |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
375 # Reset the default timeout to None, and see if it propagates |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
376 socket.setdefaulttimeout(None) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
377 self.assertEqual(socket.getdefaulttimeout(), None) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
378 s = socket.socket() |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
379 self.assertEqual(s.gettimeout(), None) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
380 s.close() |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
381 |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
382 # Check that setting it to an invalid value raises ValueError |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
383 self.assertRaises(ValueError, socket.setdefaulttimeout, -1) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
384 |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
385 # Check that setting it to an invalid type raises TypeError |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
386 self.assertRaises(TypeError, socket.setdefaulttimeout, "spam") |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
387 |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
388 def testIPv4toString(self): |
|
28833
fa159fef2730
Skip testing inet_ntop() an inet_pton() if they aren't defined.
Guido van Rossum <guido@python.org>
parents:
28818
diff
changeset
|
389 if not hasattr(socket, 'inet_pton'): |
|
fa159fef2730
Skip testing inet_ntop() an inet_pton() if they aren't defined.
Guido van Rossum <guido@python.org>
parents:
28818
diff
changeset
|
390 return # No inet_pton() on this platform |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
391 from socket import inet_aton as f, inet_pton, AF_INET |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
392 g = lambda a: inet_pton(AF_INET, a) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
393 |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
394 self.assertEquals('\x00\x00\x00\x00', f('0.0.0.0')) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
395 self.assertEquals('\xff\x00\xff\x00', f('255.0.255.0')) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
396 self.assertEquals('\xaa\xaa\xaa\xaa', f('170.170.170.170')) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
397 self.assertEquals('\x01\x02\x03\x04', f('1.2.3.4')) |
|
35453
3855a960a6aa
patch [ 756021 ] Allow socket.inet_aton("255.255.255.255") on Windows
Georg Brandl <georg@python.org>
parents:
35238
diff
changeset
|
398 self.assertEquals('\xff\xff\xff\xff', f('255.255.255.255')) |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
399 |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
400 self.assertEquals('\x00\x00\x00\x00', g('0.0.0.0')) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
401 self.assertEquals('\xff\x00\xff\x00', g('255.0.255.0')) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
402 self.assertEquals('\xaa\xaa\xaa\xaa', g('170.170.170.170')) |
|
35453
3855a960a6aa
patch [ 756021 ] Allow socket.inet_aton("255.255.255.255") on Windows
Georg Brandl <georg@python.org>
parents:
35238
diff
changeset
|
403 self.assertEquals('\xff\xff\xff\xff', g('255.255.255.255')) |
|
29087
526f37fb380d
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
28917
diff
changeset
|
404 |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
405 def testIPv6toString(self): |
|
28833
fa159fef2730
Skip testing inet_ntop() an inet_pton() if they aren't defined.
Guido van Rossum <guido@python.org>
parents:
28818
diff
changeset
|
406 if not hasattr(socket, 'inet_pton'): |
|
fa159fef2730
Skip testing inet_ntop() an inet_pton() if they aren't defined.
Guido van Rossum <guido@python.org>
parents:
28818
diff
changeset
|
407 return # No inet_pton() on this platform |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
408 try: |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
409 from socket import inet_pton, AF_INET6, has_ipv6 |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
410 if not has_ipv6: |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
411 return |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
412 except ImportError: |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
413 return |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
414 f = lambda a: inet_pton(AF_INET6, a) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
415 |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
416 self.assertEquals('\x00' * 16, f('::')) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
417 self.assertEquals('\x00' * 16, f('0::0')) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
418 self.assertEquals('\x00\x01' + '\x00' * 14, f('1::')) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
419 self.assertEquals( |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
420 '\x45\xef\x76\xcb\x00\x1a\x56\xef\xaf\xeb\x0b\xac\x19\x24\xae\xae', |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
421 f('45ef:76cb:1a:56ef:afeb:bac:1924:aeae') |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
422 ) |
|
29087
526f37fb380d
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
28917
diff
changeset
|
423 |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
424 def testStringToIPv4(self): |
|
28833
fa159fef2730
Skip testing inet_ntop() an inet_pton() if they aren't defined.
Guido van Rossum <guido@python.org>
parents:
28818
diff
changeset
|
425 if not hasattr(socket, 'inet_ntop'): |
|
fa159fef2730
Skip testing inet_ntop() an inet_pton() if they aren't defined.
Guido van Rossum <guido@python.org>
parents:
28818
diff
changeset
|
426 return # No inet_ntop() on this platform |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
427 from socket import inet_ntoa as f, inet_ntop, AF_INET |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
428 g = lambda a: inet_ntop(AF_INET, a) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
429 |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
430 self.assertEquals('1.0.1.0', f('\x01\x00\x01\x00')) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
431 self.assertEquals('170.85.170.85', f('\xaa\x55\xaa\x55')) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
432 self.assertEquals('255.255.255.255', f('\xff\xff\xff\xff')) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
433 self.assertEquals('1.2.3.4', f('\x01\x02\x03\x04')) |
|
29087
526f37fb380d
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
28917
diff
changeset
|
434 |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
435 self.assertEquals('1.0.1.0', g('\x01\x00\x01\x00')) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
436 self.assertEquals('170.85.170.85', g('\xaa\x55\xaa\x55')) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
437 self.assertEquals('255.255.255.255', g('\xff\xff\xff\xff')) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
438 |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
439 def testStringToIPv6(self): |
|
28833
fa159fef2730
Skip testing inet_ntop() an inet_pton() if they aren't defined.
Guido van Rossum <guido@python.org>
parents:
28818
diff
changeset
|
440 if not hasattr(socket, 'inet_ntop'): |
|
fa159fef2730
Skip testing inet_ntop() an inet_pton() if they aren't defined.
Guido van Rossum <guido@python.org>
parents:
28818
diff
changeset
|
441 return # No inet_ntop() on this platform |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
442 try: |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
443 from socket import inet_ntop, AF_INET6, has_ipv6 |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
444 if not has_ipv6: |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
445 return |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
446 except ImportError: |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
447 return |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
448 f = lambda a: inet_ntop(AF_INET6, a) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
449 |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
450 self.assertEquals('::', f('\x00' * 16)) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
451 self.assertEquals('::1', f('\x00' * 15 + '\x01')) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
452 self.assertEquals( |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
453 'aef:b01:506:1001:ffff:9997:55:170', |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
454 f('\x0a\xef\x0b\x01\x05\x06\x10\x01\xff\xff\x99\x97\x00\x55\x01\x70') |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
455 ) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
456 |
|
24318
12815d05080c
Add test for previous core dump when sending on closed socket with
Guido van Rossum <guido@python.org>
parents:
24293
diff
changeset
|
457 # XXX The following don't test module-level functionality... |
|
24293
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
458 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
459 def testSockName(self): |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
460 # Testing getsockname(). Use a temporary socket to elicit an unused |
|
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
461 # ephemeral port that we can use later in the test. |
|
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
462 tempsock = socket.socket() |
|
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
463 tempsock.bind(("0.0.0.0", 0)) |
|
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
464 (host, port) = tempsock.getsockname() |
|
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
465 tempsock.close() |
|
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
466 del tempsock |
|
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
467 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
468 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
469 sock.bind(("0.0.0.0", port)) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
470 name = sock.getsockname() |
|
38757
1fa78fd1e933
Get test to pass on S/390. Shout if you think this change is incorrect.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38580
diff
changeset
|
471 # XXX(nnorwitz): http://tinyurl.com/os5jz seems to indicate |
|
1fa78fd1e933
Get test to pass on S/390. Shout if you think this change is incorrect.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38580
diff
changeset
|
472 # it reasonable to get the host's addr in addition to 0.0.0.0. |
|
1fa78fd1e933
Get test to pass on S/390. Shout if you think this change is incorrect.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38580
diff
changeset
|
473 # At least for eCos. This is required for the S/390 to pass. |
|
1fa78fd1e933
Get test to pass on S/390. Shout if you think this change is incorrect.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38580
diff
changeset
|
474 my_ip_addr = socket.gethostbyname(socket.gethostname()) |
|
1fa78fd1e933
Get test to pass on S/390. Shout if you think this change is incorrect.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38580
diff
changeset
|
475 self.assert_(name[0] in ("0.0.0.0", my_ip_addr), '%s invalid' % name[0]) |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
476 self.assertEqual(name[1], port) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
477 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
478 def testGetSockOpt(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
479 # Testing getsockopt() |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
480 # 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
|
481 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
|
482 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
|
483 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
|
484 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
485 def testSetSockOpt(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
486 # Testing setsockopt() |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
487 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
|
488 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
|
489 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
|
490 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
|
491 |
|
24318
12815d05080c
Add test for previous core dump when sending on closed socket with
Guido van Rossum <guido@python.org>
parents:
24293
diff
changeset
|
492 def testSendAfterClose(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
493 # testing send() after close() with timeout |
|
24318
12815d05080c
Add test for previous core dump when sending on closed socket with
Guido van Rossum <guido@python.org>
parents:
24293
diff
changeset
|
494 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
12815d05080c
Add test for previous core dump when sending on closed socket with
Guido van Rossum <guido@python.org>
parents:
24293
diff
changeset
|
495 sock.settimeout(1) |
|
12815d05080c
Add test for previous core dump when sending on closed socket with
Guido van Rossum <guido@python.org>
parents:
24293
diff
changeset
|
496 sock.close() |
|
12815d05080c
Add test for previous core dump when sending on closed socket with
Guido van Rossum <guido@python.org>
parents:
24293
diff
changeset
|
497 self.assertRaises(socket.error, sock.send, "spam") |
|
12815d05080c
Add test for previous core dump when sending on closed socket with
Guido van Rossum <guido@python.org>
parents:
24293
diff
changeset
|
498 |
|
37123
251ecec04f1b
Correct API design mistake from rev. 43126: make socket attributes readonly properties.
Georg Brandl <georg@python.org>
parents:
37069
diff
changeset
|
499 def testNewAttributes(self): |
|
251ecec04f1b
Correct API design mistake from rev. 43126: make socket attributes readonly properties.
Georg Brandl <georg@python.org>
parents:
37069
diff
changeset
|
500 # testing .family, .type and .protocol |
|
37069
dd49847a60d3
RFE #567972: Socket objects' family, type and proto properties are
Georg Brandl <georg@python.org>
parents:
35453
diff
changeset
|
501 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
37123
251ecec04f1b
Correct API design mistake from rev. 43126: make socket attributes readonly properties.
Georg Brandl <georg@python.org>
parents:
37069
diff
changeset
|
502 self.assertEqual(sock.family, socket.AF_INET) |
|
251ecec04f1b
Correct API design mistake from rev. 43126: make socket attributes readonly properties.
Georg Brandl <georg@python.org>
parents:
37069
diff
changeset
|
503 self.assertEqual(sock.type, socket.SOCK_STREAM) |
|
251ecec04f1b
Correct API design mistake from rev. 43126: make socket attributes readonly properties.
Georg Brandl <georg@python.org>
parents:
37069
diff
changeset
|
504 self.assertEqual(sock.proto, 0) |
|
37069
dd49847a60d3
RFE #567972: Socket objects' family, type and proto properties are
Georg Brandl <georg@python.org>
parents:
35453
diff
changeset
|
505 sock.close() |
|
dd49847a60d3
RFE #567972: Socket objects' family, type and proto properties are
Georg Brandl <georg@python.org>
parents:
35453
diff
changeset
|
506 |
|
44478
73bc002252bf
socket.ioctl is only available on Windows
Christian Heimes <christian@cheimes.de>
parents:
43703
diff
changeset
|
507 def test_sock_ioctl(self): |
|
73bc002252bf
socket.ioctl is only available on Windows
Christian Heimes <christian@cheimes.de>
parents:
43703
diff
changeset
|
508 if os.name != "nt": |
|
73bc002252bf
socket.ioctl is only available on Windows
Christian Heimes <christian@cheimes.de>
parents:
43703
diff
changeset
|
509 return |
|
73bc002252bf
socket.ioctl is only available on Windows
Christian Heimes <christian@cheimes.de>
parents:
43703
diff
changeset
|
510 self.assert_(hasattr(socket.socket, 'ioctl')) |
|
73bc002252bf
socket.ioctl is only available on Windows
Christian Heimes <christian@cheimes.de>
parents:
43703
diff
changeset
|
511 self.assert_(hasattr(socket, 'SIO_RCVALL')) |
|
73bc002252bf
socket.ioctl is only available on Windows
Christian Heimes <christian@cheimes.de>
parents:
43703
diff
changeset
|
512 self.assert_(hasattr(socket, 'RCVALL_ON')) |
|
73bc002252bf
socket.ioctl is only available on Windows
Christian Heimes <christian@cheimes.de>
parents:
43703
diff
changeset
|
513 self.assert_(hasattr(socket, 'RCVALL_OFF')) |
|
73bc002252bf
socket.ioctl is only available on Windows
Christian Heimes <christian@cheimes.de>
parents:
43703
diff
changeset
|
514 |
|
73bc002252bf
socket.ioctl is only available on Windows
Christian Heimes <christian@cheimes.de>
parents:
43703
diff
changeset
|
515 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
516 class BasicTCPTest(SocketConnectedTest): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
517 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
518 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
|
519 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
|
520 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
521 def testRecv(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
522 # Testing large receive over TCP |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
523 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
|
524 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
|
525 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
526 def _testRecv(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
527 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
|
528 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
529 def testOverFlowRecv(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
530 # Testing receive in chunks over TCP |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
531 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
|
532 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
|
533 msg = seg1 + seg2 |
|
23794
1f1a6f7dd600
Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
534 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
|
535 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
536 def _testOverFlowRecv(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
537 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
|
538 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
539 def testRecvFrom(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
540 # Testing large recvfrom() over TCP |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
541 msg, addr = self.cli_conn.recvfrom(1024) |
|
23794
1f1a6f7dd600
Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
542 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
|
543 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
544 def _testRecvFrom(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
545 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
|
546 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
547 def testOverFlowRecvFrom(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
548 # Testing recvfrom() in chunks over TCP |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
549 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
|
550 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
|
551 msg = seg1 + seg2 |
|
23794
1f1a6f7dd600
Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
552 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
|
553 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
554 def _testOverFlowRecvFrom(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
555 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
|
556 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
557 def testSendAll(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
558 # Testing sendall() with a 2048 byte string over TCP |
|
24675
fec0b0aef14b
testSendAll(): loop until all data is read; this was necessary at
Guido van Rossum <guido@python.org>
parents:
24674
diff
changeset
|
559 msg = '' |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
560 while 1: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
561 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
|
562 if not read: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
563 break |
|
24675
fec0b0aef14b
testSendAll(): loop until all data is read; this was necessary at
Guido van Rossum <guido@python.org>
parents:
24674
diff
changeset
|
564 msg += read |
|
fec0b0aef14b
testSendAll(): loop until all data is read; this was necessary at
Guido van Rossum <guido@python.org>
parents:
24674
diff
changeset
|
565 self.assertEqual(msg, 'f' * 2048) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
566 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
567 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
|
568 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
|
569 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
|
570 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
571 def testFromFd(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
572 # Testing fromfd() |
| 23797 | 573 if not hasattr(socket, "fromfd"): |
|
23796
fcc36ee1924b
Allow absent fromfd(), for Windows.
Guido van Rossum <guido@python.org>
parents:
23795
diff
changeset
|
574 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
|
575 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
|
576 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
|
577 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
|
578 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
|
579 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
580 def _testFromFd(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
581 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
|
582 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
583 def testShutdown(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
584 # Testing shutdown() |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
585 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
|
586 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
|
587 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
588 def _testShutdown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
589 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
|
590 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
|
591 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
592 class BasicUDPTest(ThreadedUDPSocketTest): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
593 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
594 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
|
595 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
|
596 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
597 def testSendtoAndRecv(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
598 # Testing sendto() and Recv() over UDP |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
599 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
|
600 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
|
601 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
602 def _testSendtoAndRecv(self): |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
603 self.cli.sendto(MSG, 0, (HOST, self.port)) |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
604 |
|
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
|
605 def testRecvFrom(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
606 # 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
|
607 msg, addr = self.serv.recvfrom(len(MSG)) |
|
23794
1f1a6f7dd600
Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
608 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
|
609 |
|
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
|
610 def _testRecvFrom(self): |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
611 self.cli.sendto(MSG, 0, (HOST, self.port)) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
612 |
|
41313
d144f81574c0
Bug 1688393. Adds a control of negative values in
Facundo Batista <facundobatista@gmail.com>
parents:
41300
diff
changeset
|
613 def testRecvFromNegative(self): |
|
d144f81574c0
Bug 1688393. Adds a control of negative values in
Facundo Batista <facundobatista@gmail.com>
parents:
41300
diff
changeset
|
614 # Negative lengths passed to recvfrom should give ValueError. |
|
d144f81574c0
Bug 1688393. Adds a control of negative values in
Facundo Batista <facundobatista@gmail.com>
parents:
41300
diff
changeset
|
615 self.assertRaises(ValueError, self.serv.recvfrom, -1) |
|
d144f81574c0
Bug 1688393. Adds a control of negative values in
Facundo Batista <facundobatista@gmail.com>
parents:
41300
diff
changeset
|
616 |
|
d144f81574c0
Bug 1688393. Adds a control of negative values in
Facundo Batista <facundobatista@gmail.com>
parents:
41300
diff
changeset
|
617 def _testRecvFromNegative(self): |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
618 self.cli.sendto(MSG, 0, (HOST, self.port)) |
|
41313
d144f81574c0
Bug 1688393. Adds a control of negative values in
Facundo Batista <facundobatista@gmail.com>
parents:
41300
diff
changeset
|
619 |
|
38976
c547f6e91c58
Release all forwarded functions in .close. Fixes #1513223.
Martin v. Löwis <martin@v.loewis.de>
parents:
38867
diff
changeset
|
620 class TCPCloserTest(ThreadedTCPSocketTest): |
|
c547f6e91c58
Release all forwarded functions in .close. Fixes #1513223.
Martin v. Löwis <martin@v.loewis.de>
parents:
38867
diff
changeset
|
621 |
|
c547f6e91c58
Release all forwarded functions in .close. Fixes #1513223.
Martin v. Löwis <martin@v.loewis.de>
parents:
38867
diff
changeset
|
622 def testClose(self): |
|
c547f6e91c58
Release all forwarded functions in .close. Fixes #1513223.
Martin v. Löwis <martin@v.loewis.de>
parents:
38867
diff
changeset
|
623 conn, addr = self.serv.accept() |
|
c547f6e91c58
Release all forwarded functions in .close. Fixes #1513223.
Martin v. Löwis <martin@v.loewis.de>
parents:
38867
diff
changeset
|
624 conn.close() |
|
c547f6e91c58
Release all forwarded functions in .close. Fixes #1513223.
Martin v. Löwis <martin@v.loewis.de>
parents:
38867
diff
changeset
|
625 |
|
c547f6e91c58
Release all forwarded functions in .close. Fixes #1513223.
Martin v. Löwis <martin@v.loewis.de>
parents:
38867
diff
changeset
|
626 sd = self.cli |
|
c547f6e91c58
Release all forwarded functions in .close. Fixes #1513223.
Martin v. Löwis <martin@v.loewis.de>
parents:
38867
diff
changeset
|
627 read, write, err = select.select([sd], [], [], 1.0) |
|
c547f6e91c58
Release all forwarded functions in .close. Fixes #1513223.
Martin v. Löwis <martin@v.loewis.de>
parents:
38867
diff
changeset
|
628 self.assertEqual(read, [sd]) |
|
c547f6e91c58
Release all forwarded functions in .close. Fixes #1513223.
Martin v. Löwis <martin@v.loewis.de>
parents:
38867
diff
changeset
|
629 self.assertEqual(sd.recv(1), '') |
|
c547f6e91c58
Release all forwarded functions in .close. Fixes #1513223.
Martin v. Löwis <martin@v.loewis.de>
parents:
38867
diff
changeset
|
630 |
|
c547f6e91c58
Release all forwarded functions in .close. Fixes #1513223.
Martin v. Löwis <martin@v.loewis.de>
parents:
38867
diff
changeset
|
631 def _testClose(self): |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
632 self.cli.connect((HOST, self.port)) |
|
38976
c547f6e91c58
Release all forwarded functions in .close. Fixes #1513223.
Martin v. Löwis <martin@v.loewis.de>
parents:
38867
diff
changeset
|
633 time.sleep(1.0) |
|
c547f6e91c58
Release all forwarded functions in .close. Fixes #1513223.
Martin v. Löwis <martin@v.loewis.de>
parents:
38867
diff
changeset
|
634 |
|
33063
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
635 class BasicSocketPairTest(SocketPairTest): |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
636 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
637 def __init__(self, methodName='runTest'): |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
638 SocketPairTest.__init__(self, methodName=methodName) |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
639 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
640 def testRecv(self): |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
641 msg = self.serv.recv(1024) |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
642 self.assertEqual(msg, MSG) |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
643 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
644 def _testRecv(self): |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
645 self.cli.send(MSG) |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
646 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
647 def testSend(self): |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
648 self.serv.send(MSG) |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
649 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
650 def _testSend(self): |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
651 msg = self.cli.recv(1024) |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
652 self.assertEqual(msg, MSG) |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
653 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
654 class NonBlockingTCPTests(ThreadedTCPSocketTest): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
655 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
656 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
|
657 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
|
658 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
659 def testSetBlocking(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
660 # Testing whether set blocking works |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
661 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
|
662 start = time.time() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
663 try: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
664 self.serv.accept() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
665 except socket.error: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
666 pass |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
667 end = time.time() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
668 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
|
669 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
670 def _testSetBlocking(self): |
|
17208
c8817a9bbbdd
Make socket.getservbyname test optional on socket module having that
Barry Warsaw <barry@python.org>
parents:
16519
diff
changeset
|
671 pass |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
672 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
673 def testAccept(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
674 # Testing non-blocking accept |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
675 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
|
676 try: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
677 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
|
678 except socket.error: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
679 pass |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
680 else: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
681 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
|
682 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
|
683 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
|
684 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
|
685 else: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
686 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
|
687 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
688 def _testAccept(self): |
|
24318
12815d05080c
Add test for previous core dump when sending on closed socket with
Guido van Rossum <guido@python.org>
parents:
24293
diff
changeset
|
689 time.sleep(0.1) |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
690 self.cli.connect((HOST, self.port)) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
691 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
692 def testConnect(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
693 # Testing non-blocking connect |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
694 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
|
695 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
696 def _testConnect(self): |
|
23818
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
697 self.cli.settimeout(10) |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
698 self.cli.connect((HOST, self.port)) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
699 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
700 def testRecv(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
701 # Testing non-blocking recv |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
702 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
|
703 conn.setblocking(0) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
704 try: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
705 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
|
706 except socket.error: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
707 pass |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
708 else: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
709 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
|
710 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
|
711 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
|
712 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
|
713 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
|
714 else: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
715 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
|
716 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
717 def _testRecv(self): |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
718 self.cli.connect((HOST, self.port)) |
|
24318
12815d05080c
Add test for previous core dump when sending on closed socket with
Guido van Rossum <guido@python.org>
parents:
24293
diff
changeset
|
719 time.sleep(0.1) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
720 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
|
721 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
722 class FileObjectClassTestCase(SocketConnectedTest): |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21315
diff
changeset
|
723 |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
724 bufsize = -1 # Use default buffer size |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
725 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
726 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
|
727 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
|
728 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
729 def setUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
730 SocketConnectedTest.setUp(self) |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
731 self.serv_file = self.cli_conn.makefile('rb', self.bufsize) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
732 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
733 def tearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
734 self.serv_file.close() |
|
31833
a910b822b12c
SF bug 924242: socket._fileobject._getclosed() returns wrong value
Tim Peters <tim.peters@gmail.com>
parents:
31503
diff
changeset
|
735 self.assert_(self.serv_file.closed) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
736 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
|
737 SocketConnectedTest.tearDown(self) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
738 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
739 def clientSetUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
740 SocketConnectedTest.clientSetUp(self) |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
741 self.cli_file = self.serv_conn.makefile('wb') |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21315
diff
changeset
|
742 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
743 def clientTearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
744 self.cli_file.close() |
|
31833
a910b822b12c
SF bug 924242: socket._fileobject._getclosed() returns wrong value
Tim Peters <tim.peters@gmail.com>
parents:
31503
diff
changeset
|
745 self.assert_(self.cli_file.closed) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
746 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
|
747 SocketConnectedTest.clientTearDown(self) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
748 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
749 def testSmallRead(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
750 # Performing small file read test |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
751 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
|
752 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
|
753 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
|
754 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
|
755 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
756 def _testSmallRead(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
757 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
|
758 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
|
759 |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
760 def testFullRead(self): |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
761 # read until EOF |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
762 msg = self.serv_file.read() |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
763 self.assertEqual(msg, MSG) |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
764 |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
765 def _testFullRead(self): |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
766 self.cli_file.write(MSG) |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
767 self.cli_file.close() |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
768 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
769 def testUnbufferedRead(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
770 # Performing unbuffered file read test |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
771 buf = '' |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
772 while 1: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
773 char = self.serv_file.read(1) |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
774 if not char: |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
775 break |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
776 buf += char |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
777 self.assertEqual(buf, MSG) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
778 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
779 def _testUnbufferedRead(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
780 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
|
781 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
|
782 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
783 def testReadline(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
784 # Performing file readline test |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
785 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
|
786 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
|
787 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
788 def _testReadline(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
789 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
|
790 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
|
791 |
|
46684
2729e977fdd9
Fix a bug introduced in r62627. see issue2760 and issue2632.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46362
diff
changeset
|
792 def testReadlineAfterRead(self): |
|
2729e977fdd9
Fix a bug introduced in r62627. see issue2760 and issue2632.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46362
diff
changeset
|
793 a_baloo_is = self.serv_file.read(len("A baloo is")) |
|
2729e977fdd9
Fix a bug introduced in r62627. see issue2760 and issue2632.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46362
diff
changeset
|
794 self.assertEqual("A baloo is", a_baloo_is) |
|
2729e977fdd9
Fix a bug introduced in r62627. see issue2760 and issue2632.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46362
diff
changeset
|
795 _a_bear = self.serv_file.read(len(" a bear")) |
|
2729e977fdd9
Fix a bug introduced in r62627. see issue2760 and issue2632.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46362
diff
changeset
|
796 self.assertEqual(" a bear", _a_bear) |
|
2729e977fdd9
Fix a bug introduced in r62627. see issue2760 and issue2632.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46362
diff
changeset
|
797 line = self.serv_file.readline() |
|
2729e977fdd9
Fix a bug introduced in r62627. see issue2760 and issue2632.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46362
diff
changeset
|
798 self.assertEqual("\n", line) |
|
2729e977fdd9
Fix a bug introduced in r62627. see issue2760 and issue2632.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46362
diff
changeset
|
799 line = self.serv_file.readline() |
|
2729e977fdd9
Fix a bug introduced in r62627. see issue2760 and issue2632.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46362
diff
changeset
|
800 self.assertEqual("A BALOO IS A BEAR.\n", line) |
|
2729e977fdd9
Fix a bug introduced in r62627. see issue2760 and issue2632.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46362
diff
changeset
|
801 line = self.serv_file.readline() |
|
2729e977fdd9
Fix a bug introduced in r62627. see issue2760 and issue2632.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46362
diff
changeset
|
802 self.assertEqual(MSG, line) |
|
2729e977fdd9
Fix a bug introduced in r62627. see issue2760 and issue2632.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46362
diff
changeset
|
803 |
|
2729e977fdd9
Fix a bug introduced in r62627. see issue2760 and issue2632.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46362
diff
changeset
|
804 def _testReadlineAfterRead(self): |
|
2729e977fdd9
Fix a bug introduced in r62627. see issue2760 and issue2632.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46362
diff
changeset
|
805 self.cli_file.write("A baloo is a bear\n") |
|
2729e977fdd9
Fix a bug introduced in r62627. see issue2760 and issue2632.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46362
diff
changeset
|
806 self.cli_file.write("A BALOO IS A BEAR.\n") |
|
2729e977fdd9
Fix a bug introduced in r62627. see issue2760 and issue2632.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46362
diff
changeset
|
807 self.cli_file.write(MSG) |
|
2729e977fdd9
Fix a bug introduced in r62627. see issue2760 and issue2632.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46362
diff
changeset
|
808 self.cli_file.flush() |
|
2729e977fdd9
Fix a bug introduced in r62627. see issue2760 and issue2632.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46362
diff
changeset
|
809 |
|
2729e977fdd9
Fix a bug introduced in r62627. see issue2760 and issue2632.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46362
diff
changeset
|
810 def testReadlineAfterReadNoNewline(self): |
|
2729e977fdd9
Fix a bug introduced in r62627. see issue2760 and issue2632.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46362
diff
changeset
|
811 end_of_ = self.serv_file.read(len("End Of ")) |
|
2729e977fdd9
Fix a bug introduced in r62627. see issue2760 and issue2632.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46362
diff
changeset
|
812 self.assertEqual("End Of ", end_of_) |
|
2729e977fdd9
Fix a bug introduced in r62627. see issue2760 and issue2632.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46362
diff
changeset
|
813 line = self.serv_file.readline() |
|
2729e977fdd9
Fix a bug introduced in r62627. see issue2760 and issue2632.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46362
diff
changeset
|
814 self.assertEqual("Line", line) |
|
2729e977fdd9
Fix a bug introduced in r62627. see issue2760 and issue2632.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46362
diff
changeset
|
815 |
|
2729e977fdd9
Fix a bug introduced in r62627. see issue2760 and issue2632.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46362
diff
changeset
|
816 def _testReadlineAfterReadNoNewline(self): |
|
2729e977fdd9
Fix a bug introduced in r62627. see issue2760 and issue2632.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46362
diff
changeset
|
817 self.cli_file.write("End Of Line") |
|
2729e977fdd9
Fix a bug introduced in r62627. see issue2760 and issue2632.
Gregory P. Smith <greg@mad-scientist.com>
parents:
46362
diff
changeset
|
818 |
|
31833
a910b822b12c
SF bug 924242: socket._fileobject._getclosed() returns wrong value
Tim Peters <tim.peters@gmail.com>
parents:
31503
diff
changeset
|
819 def testClosedAttr(self): |
|
a910b822b12c
SF bug 924242: socket._fileobject._getclosed() returns wrong value
Tim Peters <tim.peters@gmail.com>
parents:
31503
diff
changeset
|
820 self.assert_(not self.serv_file.closed) |
|
a910b822b12c
SF bug 924242: socket._fileobject._getclosed() returns wrong value
Tim Peters <tim.peters@gmail.com>
parents:
31503
diff
changeset
|
821 |
|
a910b822b12c
SF bug 924242: socket._fileobject._getclosed() returns wrong value
Tim Peters <tim.peters@gmail.com>
parents:
31503
diff
changeset
|
822 def _testClosedAttr(self): |
|
a910b822b12c
SF bug 924242: socket._fileobject._getclosed() returns wrong value
Tim Peters <tim.peters@gmail.com>
parents:
31503
diff
changeset
|
823 self.assert_(not self.cli_file.closed) |
|
a910b822b12c
SF bug 924242: socket._fileobject._getclosed() returns wrong value
Tim Peters <tim.peters@gmail.com>
parents:
31503
diff
changeset
|
824 |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
825 class UnbufferedFileObjectClassTestCase(FileObjectClassTestCase): |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
826 |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
827 """Repeat the tests from FileObjectClassTestCase with bufsize==0. |
|
24674
3269bdd65988
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
24655
diff
changeset
|
828 |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
829 In this case (and in this case only), it should be possible to |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
830 create a file object, read a line from it, create another file |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
831 object, read another line from it, without loss of data in the |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
832 first file object's buffer. Note that httplib relies on this |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
833 when reading multiple requests from the same socket.""" |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
834 |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
835 bufsize = 0 # Use unbuffered mode |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
836 |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
837 def testUnbufferedReadline(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
838 # Read a line, create a new file object, read another line with it |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
839 line = self.serv_file.readline() # first line |
|
24648
edf757213a92
Tighten the unbuffered readline test to distinguish between the two lines.
Guido van Rossum <guido@python.org>
parents:
24639
diff
changeset
|
840 self.assertEqual(line, "A. " + MSG) # first line |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
841 self.serv_file = self.cli_conn.makefile('rb', 0) |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
842 line = self.serv_file.readline() # second line |
|
24648
edf757213a92
Tighten the unbuffered readline test to distinguish between the two lines.
Guido van Rossum <guido@python.org>
parents:
24639
diff
changeset
|
843 self.assertEqual(line, "B. " + MSG) # second line |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
844 |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
845 def _testUnbufferedReadline(self): |
|
24648
edf757213a92
Tighten the unbuffered readline test to distinguish between the two lines.
Guido van Rossum <guido@python.org>
parents:
24639
diff
changeset
|
846 self.cli_file.write("A. " + MSG) |
|
edf757213a92
Tighten the unbuffered readline test to distinguish between the two lines.
Guido van Rossum <guido@python.org>
parents:
24639
diff
changeset
|
847 self.cli_file.write("B. " + MSG) |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
848 self.cli_file.flush() |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
849 |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
850 class LineBufferedFileObjectClassTestCase(FileObjectClassTestCase): |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
851 |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
852 bufsize = 1 # Default-buffered for reading; line-buffered for writing |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
853 |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
854 |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
855 class SmallBufferedFileObjectClassTestCase(FileObjectClassTestCase): |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
856 |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
857 bufsize = 2 # Exercise the buffering code |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
858 |
|
40684
2fa6e82b1f17
Patch #1627441: close sockets properly in urllib2.
Georg Brandl <georg@python.org>
parents:
40632
diff
changeset
|
859 |
|
41288
a73aa0b821ca
Added a 'create_connect()' function to socket.py, which creates a
Facundo Batista <facundobatista@gmail.com>
parents:
40684
diff
changeset
|
860 class NetworkConnectionTest(object): |
|
a73aa0b821ca
Added a 'create_connect()' function to socket.py, which creates a
Facundo Batista <facundobatista@gmail.com>
parents:
40684
diff
changeset
|
861 """Prove network connection.""" |
|
a73aa0b821ca
Added a 'create_connect()' function to socket.py, which creates a
Facundo Batista <facundobatista@gmail.com>
parents:
40684
diff
changeset
|
862 def clientSetUp(self): |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
863 # We're inherited below by BasicTCPTest2, which also inherits |
|
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
864 # BasicTCPTest, which defines self.port referenced below. |
|
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
865 self.cli = socket.create_connection((HOST, self.port)) |
|
41288
a73aa0b821ca
Added a 'create_connect()' function to socket.py, which creates a
Facundo Batista <facundobatista@gmail.com>
parents:
40684
diff
changeset
|
866 self.serv_conn = self.cli |
|
41532
4b9fa8092e82
Whitespace normalization. Ugh, we really need to do this more often.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41313
diff
changeset
|
867 |
|
41288
a73aa0b821ca
Added a 'create_connect()' function to socket.py, which creates a
Facundo Batista <facundobatista@gmail.com>
parents:
40684
diff
changeset
|
868 class BasicTCPTest2(NetworkConnectionTest, BasicTCPTest): |
|
a73aa0b821ca
Added a 'create_connect()' function to socket.py, which creates a
Facundo Batista <facundobatista@gmail.com>
parents:
40684
diff
changeset
|
869 """Tests that NetworkConnection does not break existing TCP functionality. |
|
a73aa0b821ca
Added a 'create_connect()' function to socket.py, which creates a
Facundo Batista <facundobatista@gmail.com>
parents:
40684
diff
changeset
|
870 """ |
|
a73aa0b821ca
Added a 'create_connect()' function to socket.py, which creates a
Facundo Batista <facundobatista@gmail.com>
parents:
40684
diff
changeset
|
871 |
|
41300
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
872 class NetworkConnectionNoServer(unittest.TestCase): |
|
41288
a73aa0b821ca
Added a 'create_connect()' function to socket.py, which creates a
Facundo Batista <facundobatista@gmail.com>
parents:
40684
diff
changeset
|
873 def testWithoutServer(self): |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
874 port = test_support.find_unused_port() |
|
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
875 self.failUnlessRaises( |
|
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
876 socket.error, |
|
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
877 lambda: socket.create_connection((HOST, port)) |
|
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
878 ) |
|
41288
a73aa0b821ca
Added a 'create_connect()' function to socket.py, which creates a
Facundo Batista <facundobatista@gmail.com>
parents:
40684
diff
changeset
|
879 |
|
41300
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
880 class NetworkConnectionAttributesTest(SocketTCPTest, ThreadableTest): |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
881 |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
882 def __init__(self, methodName='runTest'): |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
883 SocketTCPTest.__init__(self, methodName=methodName) |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
884 ThreadableTest.__init__(self) |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
885 |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
886 def clientSetUp(self): |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
887 pass |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
888 |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
889 def clientTearDown(self): |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
890 self.cli.close() |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
891 self.cli = None |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
892 ThreadableTest.clientTearDown(self) |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
893 |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
894 def _justAccept(self): |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
895 conn, addr = self.serv.accept() |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
896 |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
897 testFamily = _justAccept |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
898 def _testFamily(self): |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
899 self.cli = socket.create_connection((HOST, self.port), timeout=30) |
|
41300
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
900 self.assertEqual(self.cli.family, 2) |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
901 |
|
41532
4b9fa8092e82
Whitespace normalization. Ugh, we really need to do this more often.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41313
diff
changeset
|
902 testTimeoutDefault = _justAccept |
|
41300
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
903 def _testTimeoutDefault(self): |
|
47372
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
47248
diff
changeset
|
904 # passing no explicit timeout uses socket's global default |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
47248
diff
changeset
|
905 self.assert_(socket.getdefaulttimeout() is None) |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
47248
diff
changeset
|
906 socket.setdefaulttimeout(42) |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
47248
diff
changeset
|
907 try: |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
47248
diff
changeset
|
908 self.cli = socket.create_connection((HOST, self.port)) |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
47248
diff
changeset
|
909 finally: |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
47248
diff
changeset
|
910 socket.setdefaulttimeout(None) |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
47248
diff
changeset
|
911 self.assertEquals(self.cli.gettimeout(), 42) |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
47248
diff
changeset
|
912 |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
47248
diff
changeset
|
913 testTimeoutNone = _justAccept |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
47248
diff
changeset
|
914 def _testTimeoutNone(self): |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
47248
diff
changeset
|
915 # None timeout means the same as sock.settimeout(None) |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
47248
diff
changeset
|
916 self.assert_(socket.getdefaulttimeout() is None) |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
47248
diff
changeset
|
917 socket.setdefaulttimeout(30) |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
47248
diff
changeset
|
918 try: |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
47248
diff
changeset
|
919 self.cli = socket.create_connection((HOST, self.port), timeout=None) |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
47248
diff
changeset
|
920 finally: |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
47248
diff
changeset
|
921 socket.setdefaulttimeout(None) |
|
e2c5ae30cffe
Fixed the semantic of timeout for socket.create_connection and
Facundo Batista <facundobatista@gmail.com>
parents:
47248
diff
changeset
|
922 self.assertEqual(self.cli.gettimeout(), None) |
|
41532
4b9fa8092e82
Whitespace normalization. Ugh, we really need to do this more often.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41313
diff
changeset
|
923 |
|
4b9fa8092e82
Whitespace normalization. Ugh, we really need to do this more often.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41313
diff
changeset
|
924 testTimeoutValueNamed = _justAccept |
|
41300
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
925 def _testTimeoutValueNamed(self): |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
926 self.cli = socket.create_connection((HOST, self.port), timeout=30) |
|
41300
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
927 self.assertEqual(self.cli.gettimeout(), 30) |
|
41288
a73aa0b821ca
Added a 'create_connect()' function to socket.py, which creates a
Facundo Batista <facundobatista@gmail.com>
parents:
40684
diff
changeset
|
928 |
|
41532
4b9fa8092e82
Whitespace normalization. Ugh, we really need to do this more often.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41313
diff
changeset
|
929 testTimeoutValueNonamed = _justAccept |
|
41300
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
930 def _testTimeoutValueNonamed(self): |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
931 self.cli = socket.create_connection((HOST, self.port), 30) |
|
41300
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
932 self.assertEqual(self.cli.gettimeout(), 30) |
|
41288
a73aa0b821ca
Added a 'create_connect()' function to socket.py, which creates a
Facundo Batista <facundobatista@gmail.com>
parents:
40684
diff
changeset
|
933 |
|
41300
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
934 class NetworkConnectionBehaviourTest(SocketTCPTest, ThreadableTest): |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
935 |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
936 def __init__(self, methodName='runTest'): |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
937 SocketTCPTest.__init__(self, methodName=methodName) |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
938 ThreadableTest.__init__(self) |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
939 |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
940 def clientSetUp(self): |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
941 pass |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
942 |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
943 def clientTearDown(self): |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
944 self.cli.close() |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
945 self.cli = None |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
946 ThreadableTest.clientTearDown(self) |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
947 |
|
41288
a73aa0b821ca
Added a 'create_connect()' function to socket.py, which creates a
Facundo Batista <facundobatista@gmail.com>
parents:
40684
diff
changeset
|
948 def testInsideTimeout(self): |
|
41300
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
949 conn, addr = self.serv.accept() |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
950 time.sleep(3) |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
951 conn.send("done!") |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
952 testOutsideTimeout = testInsideTimeout |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
953 |
|
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
954 def _testInsideTimeout(self): |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
955 self.cli = sock = socket.create_connection((HOST, self.port)) |
|
41288
a73aa0b821ca
Added a 'create_connect()' function to socket.py, which creates a
Facundo Batista <facundobatista@gmail.com>
parents:
40684
diff
changeset
|
956 data = sock.recv(5) |
|
a73aa0b821ca
Added a 'create_connect()' function to socket.py, which creates a
Facundo Batista <facundobatista@gmail.com>
parents:
40684
diff
changeset
|
957 self.assertEqual(data, "done!") |
|
a73aa0b821ca
Added a 'create_connect()' function to socket.py, which creates a
Facundo Batista <facundobatista@gmail.com>
parents:
40684
diff
changeset
|
958 |
|
41300
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
959 def _testOutsideTimeout(self): |
|
46362
d917da2b1946
- Issue #2550: The approach used by client/server code for obtaining ports
Trent Nelson <trent.nelson@snakebite.org>
parents:
46298
diff
changeset
|
960 self.cli = sock = socket.create_connection((HOST, self.port), timeout=1) |
|
41288
a73aa0b821ca
Added a 'create_connect()' function to socket.py, which creates a
Facundo Batista <facundobatista@gmail.com>
parents:
40684
diff
changeset
|
961 self.failUnlessRaises(socket.timeout, lambda: sock.recv(5)) |
|
a73aa0b821ca
Added a 'create_connect()' function to socket.py, which creates a
Facundo Batista <facundobatista@gmail.com>
parents:
40684
diff
changeset
|
962 |
|
a73aa0b821ca
Added a 'create_connect()' function to socket.py, which creates a
Facundo Batista <facundobatista@gmail.com>
parents:
40684
diff
changeset
|
963 |
|
40684
2fa6e82b1f17
Patch #1627441: close sockets properly in urllib2.
Georg Brandl <georg@python.org>
parents:
40632
diff
changeset
|
964 class Urllib2FileobjectTest(unittest.TestCase): |
|
2fa6e82b1f17
Patch #1627441: close sockets properly in urllib2.
Georg Brandl <georg@python.org>
parents:
40632
diff
changeset
|
965 |
|
2fa6e82b1f17
Patch #1627441: close sockets properly in urllib2.
Georg Brandl <georg@python.org>
parents:
40632
diff
changeset
|
966 # urllib2.HTTPHandler has "borrowed" socket._fileobject, and requires that |
|
2fa6e82b1f17
Patch #1627441: close sockets properly in urllib2.
Georg Brandl <georg@python.org>
parents:
40632
diff
changeset
|
967 # it close the socket if the close c'tor argument is true |
|
2fa6e82b1f17
Patch #1627441: close sockets properly in urllib2.
Georg Brandl <georg@python.org>
parents:
40632
diff
changeset
|
968 |
|
2fa6e82b1f17
Patch #1627441: close sockets properly in urllib2.
Georg Brandl <georg@python.org>
parents:
40632
diff
changeset
|
969 def testClose(self): |
|
2fa6e82b1f17
Patch #1627441: close sockets properly in urllib2.
Georg Brandl <georg@python.org>
parents:
40632
diff
changeset
|
970 class MockSocket: |
|
2fa6e82b1f17
Patch #1627441: close sockets properly in urllib2.
Georg Brandl <georg@python.org>
parents:
40632
diff
changeset
|
971 closed = False |
|
2fa6e82b1f17
Patch #1627441: close sockets properly in urllib2.
Georg Brandl <georg@python.org>
parents:
40632
diff
changeset
|
972 def flush(self): pass |
|
2fa6e82b1f17
Patch #1627441: close sockets properly in urllib2.
Georg Brandl <georg@python.org>
parents:
40632
diff
changeset
|
973 def close(self): self.closed = True |
|
2fa6e82b1f17
Patch #1627441: close sockets properly in urllib2.
Georg Brandl <georg@python.org>
parents:
40632
diff
changeset
|
974 |
|
2fa6e82b1f17
Patch #1627441: close sockets properly in urllib2.
Georg Brandl <georg@python.org>
parents:
40632
diff
changeset
|
975 # must not close unless we request it: the original use of _fileobject |
|
2fa6e82b1f17
Patch #1627441: close sockets properly in urllib2.
Georg Brandl <georg@python.org>
parents:
40632
diff
changeset
|
976 # by module socket requires that the underlying socket not be closed until |
|
2fa6e82b1f17
Patch #1627441: close sockets properly in urllib2.
Georg Brandl <georg@python.org>
parents:
40632
diff
changeset
|
977 # the _socketobject that created the _fileobject is closed |
|
2fa6e82b1f17
Patch #1627441: close sockets properly in urllib2.
Georg Brandl <georg@python.org>
parents:
40632
diff
changeset
|
978 s = MockSocket() |
|
2fa6e82b1f17
Patch #1627441: close sockets properly in urllib2.
Georg Brandl <georg@python.org>
parents:
40632
diff
changeset
|
979 f = socket._fileobject(s) |
|
2fa6e82b1f17
Patch #1627441: close sockets properly in urllib2.
Georg Brandl <georg@python.org>
parents:
40632
diff
changeset
|
980 f.close() |
|
2fa6e82b1f17
Patch #1627441: close sockets properly in urllib2.
Georg Brandl <georg@python.org>
parents:
40632
diff
changeset
|
981 self.assert_(not s.closed) |
|
2fa6e82b1f17
Patch #1627441: close sockets properly in urllib2.
Georg Brandl <georg@python.org>
parents:
40632
diff
changeset
|
982 |
|
2fa6e82b1f17
Patch #1627441: close sockets properly in urllib2.
Georg Brandl <georg@python.org>
parents:
40632
diff
changeset
|
983 s = MockSocket() |
|
2fa6e82b1f17
Patch #1627441: close sockets properly in urllib2.
Georg Brandl <georg@python.org>
parents:
40632
diff
changeset
|
984 f = socket._fileobject(s, close=True) |
|
2fa6e82b1f17
Patch #1627441: close sockets properly in urllib2.
Georg Brandl <georg@python.org>
parents:
40632
diff
changeset
|
985 f.close() |
|
2fa6e82b1f17
Patch #1627441: close sockets properly in urllib2.
Georg Brandl <georg@python.org>
parents:
40632
diff
changeset
|
986 self.assert_(s.closed) |
|
2fa6e82b1f17
Patch #1627441: close sockets properly in urllib2.
Georg Brandl <georg@python.org>
parents:
40632
diff
changeset
|
987 |
|
29662
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
988 class TCPTimeoutTest(SocketTCPTest): |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
989 |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
990 def testTCPTimeout(self): |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
991 def raise_timeout(*args, **kwargs): |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
992 self.serv.settimeout(1.0) |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
993 self.serv.accept() |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
994 self.failUnlessRaises(socket.timeout, raise_timeout, |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
995 "Error generating a timeout exception (TCP)") |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
996 |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
997 def testTimeoutZero(self): |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
998 ok = False |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
999 try: |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1000 self.serv.settimeout(0.0) |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1001 foo = self.serv.accept() |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1002 except socket.timeout: |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1003 self.fail("caught timeout instead of error (TCP)") |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1004 except socket.error: |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1005 ok = True |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1006 except: |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1007 self.fail("caught unexpected exception (TCP)") |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1008 if not ok: |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1009 self.fail("accept() returned success when we did not expect it") |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1010 |
|
39354
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
1011 def testInterruptedTimeout(self): |
|
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
1012 # XXX I don't know how to do this test on MSWindows or any other |
|
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
1013 # plaform that doesn't support signal.alarm() or os.kill(), though |
|
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
1014 # the bug should have existed on all platforms. |
|
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
1015 if not hasattr(signal, "alarm"): |
|
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
1016 return # can only test on *nix |
|
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
1017 self.serv.settimeout(5.0) # must be longer than alarm |
|
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
1018 class Alarm(Exception): |
|
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
1019 pass |
|
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
1020 def alarm_handler(signal, frame): |
|
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
1021 raise Alarm |
|
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
1022 old_alarm = signal.signal(signal.SIGALRM, alarm_handler) |
|
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
1023 try: |
|
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
1024 signal.alarm(2) # POSIX allows alarm to be up to 1 second early |
|
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
1025 try: |
|
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
1026 foo = self.serv.accept() |
|
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
1027 except socket.timeout: |
|
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
1028 self.fail("caught timeout instead of Alarm") |
|
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
1029 except Alarm: |
|
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
1030 pass |
|
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
1031 except: |
|
46148
59d082591f56
Print more information the next time test_socket throws the wrong exception.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44770
diff
changeset
|
1032 self.fail("caught other exception instead of Alarm:" |
|
59d082591f56
Print more information the next time test_socket throws the wrong exception.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44770
diff
changeset
|
1033 " %s(%s):\n%s" % |
|
59d082591f56
Print more information the next time test_socket throws the wrong exception.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44770
diff
changeset
|
1034 (sys.exc_info()[:2] + (traceback.format_exc(),))) |
|
39354
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
1035 else: |
|
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
1036 self.fail("nothing caught") |
|
46148
59d082591f56
Print more information the next time test_socket throws the wrong exception.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44770
diff
changeset
|
1037 finally: |
|
59d082591f56
Print more information the next time test_socket throws the wrong exception.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44770
diff
changeset
|
1038 signal.alarm(0) # shut off alarm |
|
39354
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
1039 except Alarm: |
|
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
1040 self.fail("got Alarm in wrong place") |
|
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
1041 finally: |
|
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
1042 # no alarm can be pending. Safe to restore old handler. |
|
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
1043 signal.signal(signal.SIGALRM, old_alarm) |
|
85fdcdfca85c
Patch #1519025 and bug #926423: If a KeyboardInterrupt occurs during
Neal Norwitz <nnorwitz@gmail.com>
parents:
38976
diff
changeset
|
1044 |
|
29662
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1045 class UDPTimeoutTest(SocketTCPTest): |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1046 |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1047 def testUDPTimeout(self): |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1048 def raise_timeout(*args, **kwargs): |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1049 self.serv.settimeout(1.0) |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1050 self.serv.recv(1024) |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1051 self.failUnlessRaises(socket.timeout, raise_timeout, |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1052 "Error generating a timeout exception (UDP)") |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1053 |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1054 def testTimeoutZero(self): |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1055 ok = False |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1056 try: |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1057 self.serv.settimeout(0.0) |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1058 foo = self.serv.recv(1024) |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1059 except socket.timeout: |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1060 self.fail("caught timeout instead of error (UDP)") |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1061 except socket.error: |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1062 ok = True |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1063 except: |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1064 self.fail("caught unexpected exception (UDP)") |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1065 if not ok: |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1066 self.fail("recv() returned success when we did not expect it") |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1067 |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1068 class TestExceptions(unittest.TestCase): |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1069 |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1070 def testExceptionTree(self): |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1071 self.assert_(issubclass(socket.error, Exception)) |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1072 self.assert_(issubclass(socket.herror, socket.error)) |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1073 self.assert_(issubclass(socket.gaierror, socket.error)) |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1074 self.assert_(issubclass(socket.timeout, socket.error)) |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1075 |
|
37853
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37422
diff
changeset
|
1076 class TestLinuxAbstractNamespace(unittest.TestCase): |
|
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37422
diff
changeset
|
1077 |
|
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37422
diff
changeset
|
1078 UNIX_PATH_MAX = 108 |
|
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37422
diff
changeset
|
1079 |
|
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37422
diff
changeset
|
1080 def testLinuxAbstractNamespace(self): |
|
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37422
diff
changeset
|
1081 address = "\x00python-test-hello\x00\xff" |
|
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37422
diff
changeset
|
1082 s1 = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) |
|
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37422
diff
changeset
|
1083 s1.bind(address) |
|
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37422
diff
changeset
|
1084 s1.listen(1) |
|
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37422
diff
changeset
|
1085 s2 = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) |
|
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37422
diff
changeset
|
1086 s2.connect(s1.getsockname()) |
|
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37422
diff
changeset
|
1087 s1.accept() |
|
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37422
diff
changeset
|
1088 self.assertEqual(s1.getsockname(), address) |
|
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37422
diff
changeset
|
1089 self.assertEqual(s2.getpeername(), address) |
|
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37422
diff
changeset
|
1090 |
|
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37422
diff
changeset
|
1091 def testMaxName(self): |
|
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37422
diff
changeset
|
1092 address = "\x00" + "h" * (self.UNIX_PATH_MAX - 1) |
|
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37422
diff
changeset
|
1093 s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) |
|
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37422
diff
changeset
|
1094 s.bind(address) |
|
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37422
diff
changeset
|
1095 self.assertEqual(s.getsockname(), address) |
|
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37422
diff
changeset
|
1096 |
|
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37422
diff
changeset
|
1097 def testNameOverflow(self): |
|
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37422
diff
changeset
|
1098 address = "\x00" + "h" * self.UNIX_PATH_MAX |
|
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37422
diff
changeset
|
1099 s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) |
|
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37422
diff
changeset
|
1100 self.assertRaises(socket.error, s.bind, address) |
|
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37422
diff
changeset
|
1101 |
|
29662
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1102 |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37853
diff
changeset
|
1103 class BufferIOTest(SocketConnectedTest): |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37853
diff
changeset
|
1104 """ |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37853
diff
changeset
|
1105 Test the buffer versions of socket.recv() and socket.send(). |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37853
diff
changeset
|
1106 """ |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37853
diff
changeset
|
1107 def __init__(self, methodName='runTest'): |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37853
diff
changeset
|
1108 SocketConnectedTest.__init__(self, methodName=methodName) |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37853
diff
changeset
|
1109 |
|
38580
a114003aa3d3
Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents:
38353
diff
changeset
|
1110 def testRecvInto(self): |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37853
diff
changeset
|
1111 buf = array.array('c', ' '*1024) |
|
38580
a114003aa3d3
Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents:
38353
diff
changeset
|
1112 nbytes = self.cli_conn.recv_into(buf) |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37853
diff
changeset
|
1113 self.assertEqual(nbytes, len(MSG)) |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37853
diff
changeset
|
1114 msg = buf.tostring()[:len(MSG)] |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37853
diff
changeset
|
1115 self.assertEqual(msg, MSG) |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37853
diff
changeset
|
1116 |
|
38580
a114003aa3d3
Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents:
38353
diff
changeset
|
1117 def _testRecvInto(self): |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37853
diff
changeset
|
1118 buf = buffer(MSG) |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37853
diff
changeset
|
1119 self.serv_conn.send(buf) |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37853
diff
changeset
|
1120 |
|
38580
a114003aa3d3
Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents:
38353
diff
changeset
|
1121 def testRecvFromInto(self): |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37853
diff
changeset
|
1122 buf = array.array('c', ' '*1024) |
|
38580
a114003aa3d3
Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents:
38353
diff
changeset
|
1123 nbytes, addr = self.cli_conn.recvfrom_into(buf) |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37853
diff
changeset
|
1124 self.assertEqual(nbytes, len(MSG)) |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37853
diff
changeset
|
1125 msg = buf.tostring()[:len(MSG)] |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37853
diff
changeset
|
1126 self.assertEqual(msg, MSG) |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37853
diff
changeset
|
1127 |
|
38580
a114003aa3d3
Fixes in struct and socket from merge reviews.
Martin Blais <blais@furius.ca>
parents:
38353
diff
changeset
|
1128 def _testRecvFromInto(self): |
|
38353
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37853
diff
changeset
|
1129 buf = buffer(MSG) |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37853
diff
changeset
|
1130 self.serv_conn.send(buf) |
|
36cd4a4ab8f7
Support for buffer protocol for socket and struct.
Martin Blais <blais@furius.ca>
parents:
37853
diff
changeset
|
1131 |
|
44561
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1132 |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1133 TIPC_STYPE = 2000 |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1134 TIPC_LOWER = 200 |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1135 TIPC_UPPER = 210 |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1136 |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1137 def isTipcAvailable(): |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1138 """Check if the TIPC module is loaded |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1139 |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1140 The TIPC module is not loaded automatically on Ubuntu and probably |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1141 other Linux distros. |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1142 """ |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1143 if not hasattr(socket, "AF_TIPC"): |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1144 return False |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1145 if not os.path.isfile("/proc/modules"): |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1146 return False |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1147 with open("/proc/modules") as f: |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1148 for line in f: |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1149 if line.startswith("tipc "): |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1150 return True |
|
44592
cb22f8748da7
It's verbose, not debug
Christian Heimes <christian@cheimes.de>
parents:
44581
diff
changeset
|
1151 if test_support.verbose: |
|
44561
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1152 print "TIPC module is not loaded, please 'sudo modprobe tipc'" |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1153 return False |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1154 |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1155 class TIPCTest (unittest.TestCase): |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1156 def testRDM(self): |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1157 srv = socket.socket(socket.AF_TIPC, socket.SOCK_RDM) |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1158 cli = socket.socket(socket.AF_TIPC, socket.SOCK_RDM) |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1159 |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1160 srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1161 srvaddr = (socket.TIPC_ADDR_NAMESEQ, TIPC_STYPE, |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1162 TIPC_LOWER, TIPC_UPPER) |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1163 srv.bind(srvaddr) |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1164 |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1165 sendaddr = (socket.TIPC_ADDR_NAME, TIPC_STYPE, |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1166 TIPC_LOWER + (TIPC_UPPER - TIPC_LOWER) / 2, 0) |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1167 cli.sendto(MSG, sendaddr) |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1168 |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1169 msg, recvaddr = srv.recvfrom(1024) |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1170 |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1171 self.assertEqual(cli.getsockname(), recvaddr) |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1172 self.assertEqual(msg, MSG) |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1173 |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1174 |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1175 class TIPCThreadableTest (unittest.TestCase, ThreadableTest): |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1176 def __init__(self, methodName = 'runTest'): |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1177 unittest.TestCase.__init__(self, methodName = methodName) |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1178 ThreadableTest.__init__(self) |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1179 |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1180 def setUp(self): |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1181 self.srv = socket.socket(socket.AF_TIPC, socket.SOCK_STREAM) |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1182 self.srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1183 srvaddr = (socket.TIPC_ADDR_NAMESEQ, TIPC_STYPE, |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1184 TIPC_LOWER, TIPC_UPPER) |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1185 self.srv.bind(srvaddr) |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1186 self.srv.listen(5) |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1187 self.serverExplicitReady() |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1188 self.conn, self.connaddr = self.srv.accept() |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1189 |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1190 def clientSetUp(self): |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1191 # The is a hittable race between serverExplicitReady() and the |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1192 # accept() call; sleep a little while to avoid it, otherwise |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1193 # we could get an exception |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1194 time.sleep(0.1) |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1195 self.cli = socket.socket(socket.AF_TIPC, socket.SOCK_STREAM) |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1196 addr = (socket.TIPC_ADDR_NAME, TIPC_STYPE, |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1197 TIPC_LOWER + (TIPC_UPPER - TIPC_LOWER) / 2, 0) |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1198 self.cli.connect(addr) |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1199 self.cliaddr = self.cli.getsockname() |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1200 |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1201 def testStream(self): |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1202 msg = self.conn.recv(1024) |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1203 self.assertEqual(msg, MSG) |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1204 self.assertEqual(self.cliaddr, self.connaddr) |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1205 |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1206 def _testStream(self): |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1207 self.cli.send(MSG) |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1208 self.cli.close() |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1209 |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1210 |
|
24451
22570e76cca1
Enable test_socket again, if only to prevent mistakes like Jeremy
Guido van Rossum <guido@python.org>
parents:
24450
diff
changeset
|
1211 def test_main(): |
|
38976
c547f6e91c58
Release all forwarded functions in .close. Fixes #1513223.
Martin v. Löwis <martin@v.loewis.de>
parents:
38867
diff
changeset
|
1212 tests = [GeneralModuleTests, BasicTCPTest, TCPCloserTest, TCPTimeoutTest, |
|
41288
a73aa0b821ca
Added a 'create_connect()' function to socket.py, which creates a
Facundo Batista <facundobatista@gmail.com>
parents:
40684
diff
changeset
|
1213 TestExceptions, BufferIOTest, BasicTCPTest2] |
|
25152
0c9dfd5a06d4
Skip UDP testing for MacPython (for now), it hangs. This may be due to
Jack Jansen <jack.jansen@cwi.nl>
parents:
24772
diff
changeset
|
1214 if sys.platform != 'mac': |
|
29662
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
1215 tests.extend([ BasicUDPTest, UDPTimeoutTest ]) |
|
28917
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28833
diff
changeset
|
1216 |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28833
diff
changeset
|
1217 tests.extend([ |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28833
diff
changeset
|
1218 NonBlockingTCPTests, |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28833
diff
changeset
|
1219 FileObjectClassTestCase, |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28833
diff
changeset
|
1220 UnbufferedFileObjectClassTestCase, |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28833
diff
changeset
|
1221 LineBufferedFileObjectClassTestCase, |
|
40684
2fa6e82b1f17
Patch #1627441: close sockets properly in urllib2.
Georg Brandl <georg@python.org>
parents:
40632
diff
changeset
|
1222 SmallBufferedFileObjectClassTestCase, |
|
2fa6e82b1f17
Patch #1627441: close sockets properly in urllib2.
Georg Brandl <georg@python.org>
parents:
40632
diff
changeset
|
1223 Urllib2FileobjectTest, |
|
41300
8258f25d43d7
Redone the tests, using the infrastructure already present
Facundo Batista <facundobatista@gmail.com>
parents:
41292
diff
changeset
|
1224 NetworkConnectionNoServer, |
|
41288
a73aa0b821ca
Added a 'create_connect()' function to socket.py, which creates a
Facundo Batista <facundobatista@gmail.com>
parents:
40684
diff
changeset
|
1225 NetworkConnectionAttributesTest, |
|
a73aa0b821ca
Added a 'create_connect()' function to socket.py, which creates a
Facundo Batista <facundobatista@gmail.com>
parents:
40684
diff
changeset
|
1226 NetworkConnectionBehaviourTest, |
|
28917
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28833
diff
changeset
|
1227 ]) |
|
33063
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
1228 if hasattr(socket, "socketpair"): |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
1229 tests.append(BasicSocketPairTest) |
|
37853
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37422
diff
changeset
|
1230 if sys.platform == 'linux2': |
|
29257ef6abeb
SF Patch #1062014: AF_UNIX sockets under Linux have a special
Armin Rigo <arigo@tunes.org>
parents:
37422
diff
changeset
|
1231 tests.append(TestLinuxAbstractNamespace) |
|
44561
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1232 if isTipcAvailable(): |
|
ac51cfe5c5c6
Issue #1646: Make socket support TIPC. The socket module now has support
Christian Heimes <christian@cheimes.de>
parents:
44478
diff
changeset
|
1233 tests.append(TIPCTest) |
|
44581
6d521603e07d
Fixed indention problem that caused the second TIPC test to run on systems without TIPC
Christian Heimes <christian@cheimes.de>
parents:
44561
diff
changeset
|
1234 tests.append(TIPCThreadableTest) |
|
38867
30d2333852d5
Prevent spurious leaks when running regrtest.py -R. There may be more
Neal Norwitz <nnorwitz@gmail.com>
parents:
38767
diff
changeset
|
1235 |
|
30d2333852d5
Prevent spurious leaks when running regrtest.py -R. There may be more
Neal Norwitz <nnorwitz@gmail.com>
parents:
38767
diff
changeset
|
1236 thread_info = test_support.threading_setup() |
|
28917
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28833
diff
changeset
|
1237 test_support.run_unittest(*tests) |
|
38867
30d2333852d5
Prevent spurious leaks when running regrtest.py -R. There may be more
Neal Norwitz <nnorwitz@gmail.com>
parents:
38767
diff
changeset
|
1238 test_support.threading_cleanup(*thread_info) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1239 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1240 if __name__ == "__main__": |
|
24451
22570e76cca1
Enable test_socket again, if only to prevent mistakes like Jeremy
Guido van Rossum <guido@python.org>
parents:
24450
diff
changeset
|
1241 test_main() |
