annotate Lib/test/test_socket.py @ 51749:1408feec0084 3.0

Merged revisions 69798 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r69798 | benjamin.peterson | 2009-02-19 22:02:38 -0600 (Thu, 19 Feb 2009) | 13 lines Merged revisions 69769,69776 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r69769 | georg.brandl | 2009-02-19 02:30:06 -0600 (Thu, 19 Feb 2009) | 1 line #5310, #3558: fix operator precedence table. ........ r69776 | georg.brandl | 2009-02-19 10:34:51 -0600 (Thu, 19 Feb 2009) | 2 lines #5317: update IronPython URL. ........ ................
author Benjamin Peterson <benjamin@python.org>
date Fri, 20 Feb 2009 04:05:32 +0000
parents 7a0525613644
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 46899
diff changeset
4 from test import support
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
5
46370
2e917b0c8f6e Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46262
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
47266
7fe3a8648ce2 Rename thread to _thread and dummy_thread to _dummy_thread. Issue #2875.
Georg Brandl <georg@python.org>
parents: 47201
diff changeset
9 import _thread as thread
7fe3a8648ce2 Rename thread to _thread and dummy_thread to _dummy_thread. Issue #2875.
Georg Brandl <georg@python.org>
parents: 47201
diff changeset
10 import threading
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
11 import time
46161
848160d10780 Merged revisions 61981,61984-61987,61992-61993,61997-62000 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44782
diff changeset
12 import traceback
46899
bd2c95c165ea Rename Queue module to queue.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 46370
diff changeset
13 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
14 import sys
44535
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43954
diff changeset
15 import os
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43954
diff changeset
16 import array
32160
aec9c98a47d2 Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents: 31833
diff changeset
17 from weakref import proxy
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
18 import signal
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
19
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 46899
diff changeset
20 HOST = support.HOST
41809
8e062e572ea4 Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents: 41770
diff changeset
21 MSG = b'Michael Gilfix was here\n'
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
22
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
23 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
24
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
25 def setUp(self):
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
26 self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 46899
diff changeset
27 self.port = 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
28 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
29
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
30 def tearDown(self):
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
31 self.serv.close()
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
32 self.serv = None
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
33
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
34 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
35
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
36 def setUp(self):
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
37 self.serv = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 46899
diff changeset
38 self.port = 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
39
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
40 def tearDown(self):
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
41 self.serv.close()
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
42 self.serv = None
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
43
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
44 class ThreadableTest:
23909
b16d4be6a232 Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents: 23831
diff changeset
45 """Threadable Test class
b16d4be6a232 Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents: 23831
diff changeset
46
b16d4be6a232 Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents: 23831
diff changeset
47 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
48 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
49 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
50 inheritance:
b16d4be6a232 Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents: 23831
diff changeset
51
b16d4be6a232 Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents: 23831
diff changeset
52 class NewClass (OldClass, ThreadableTest):
b16d4be6a232 Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents: 23831
diff changeset
53 pass
b16d4be6a232 Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents: 23831
diff changeset
54
b16d4be6a232 Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents: 23831
diff changeset
55 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
56 purposes for overriding:
b16d4be6a232 Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents: 23831
diff changeset
57
b16d4be6a232 Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents: 23831
diff changeset
58 clientSetUp ()
b16d4be6a232 Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents: 23831
diff changeset
59 clientTearDown ()
b16d4be6a232 Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents: 23831
diff changeset
60
b16d4be6a232 Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents: 23831
diff changeset
61 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
62 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
63 '_' 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
64
b16d4be6a232 Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents: 23831
diff changeset
65 def testFoo(self):
b16d4be6a232 Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents: 23831
diff changeset
66 # Server portion
b16d4be6a232 Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents: 23831
diff changeset
67
b16d4be6a232 Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents: 23831
diff changeset
68 def _testFoo(self):
b16d4be6a232 Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents: 23831
diff changeset
69 # Client portion
b16d4be6a232 Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents: 23831
diff changeset
70
b16d4be6a232 Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents: 23831
diff changeset
71 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
72 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
73 the testing framework.
b16d4be6a232 Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents: 23831
diff changeset
74
b16d4be6a232 Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents: 23831
diff changeset
75 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
76 functions that rely on the client thread during setup,
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
77 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
78 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
79 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
80 """
4880
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
81
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
82 def __init__(self):
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
83 # 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
84 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
85 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
86 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
87 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
88
23909
b16d4be6a232 Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents: 23831
diff changeset
89 def serverExplicitReady(self):
b16d4be6a232 Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents: 23831
diff changeset
90 """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
91 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
92 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
93 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
94 self.server_ready.set()
b16d4be6a232 Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents: 23831
diff changeset
95
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
96 def _setUp(self):
23909
b16d4be6a232 Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents: 23831
diff changeset
97 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
98 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
99 self.done = threading.Event()
46899
bd2c95c165ea Rename Queue module to queue.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 46370
diff changeset
100 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
101
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
102 # 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
103 methodname = self.id()
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23814
diff changeset
104 i = methodname.rfind('.')
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23814
diff changeset
105 methodname = methodname[i+1:]
203d1412a7e8 Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents: 23814
diff changeset
106 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
107 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
108 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
109
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
110 self.__setUp()
47615
045f83a1b864 Merged revisions 64125 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 47559
diff changeset
111 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
112 self.server_ready.set()
b16d4be6a232 Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents: 23831
diff changeset
113 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
114
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
115 def _tearDown(self):
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
116 self.__tearDown()
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
117 self.done.wait()
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
118
44675
627f2e2273b9 Remove Queue.empty() and Queue.full() in favor of using qsize() or trapping the Empty and Full exceptions.
Raymond Hettinger <python@rcn.com>
parents: 44604
diff changeset
119 if self.queue.qsize():
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
120 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
121 self.fail(msg)
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
122
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
123 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
124 self.server_ready.wait()
b16d4be6a232 Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents: 23831
diff changeset
125 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
126 self.clientSetUp()
41824
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41809
diff changeset
127 if not hasattr(test_func, '__call__'):
43014
9834301a2fd3 Raise statement normalization in Lib/test/.
Collin Winter <collinw@gmail.com>
parents: 42637
diff changeset
128 raise TypeError("test_func must be a callable function")
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
129 try:
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
130 test_func()
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 39648
diff changeset
131 except Exception as strerror:
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
132 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
133 self.clientTearDown()
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
134
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
135 def clientSetUp(self):
43014
9834301a2fd3 Raise statement normalization in Lib/test/.
Collin Winter <collinw@gmail.com>
parents: 42637
diff changeset
136 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
137
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
138 def clientTearDown(self):
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
139 self.done.set()
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
140 thread.exit()
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
141
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
142 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
143
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
144 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
145 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
146 ThreadableTest.__init__(self)
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
147
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
148 def clientSetUp(self):
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
149 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
150
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
151 def clientTearDown(self):
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
152 self.cli.close()
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
153 self.cli = None
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
154 ThreadableTest.clientTearDown(self)
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
155
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
156 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
157
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
158 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
159 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
160 ThreadableTest.__init__(self)
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
161
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
162 def clientSetUp(self):
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
163 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
164
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
165 class SocketConnectedTest(ThreadedTCPSocketTest):
42434
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
166 """Socket tests for client-server connection.
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
167
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
168 self.cli_conn is a client socket connected to the server. The
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
169 setUp() method guarantees that it is connected to the server.
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
170 """
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
171
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
172 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
173 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
174
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
175 def setUp(self):
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
176 ThreadedTCPSocketTest.setUp(self)
23909
b16d4be6a232 Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents: 23831
diff changeset
177 # 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
178 # 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
179 self.serverExplicitReady()
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
180 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
181 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
182
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
183 def tearDown(self):
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
184 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
185 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
186 ThreadedTCPSocketTest.tearDown(self)
4880
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
187
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
188 def clientSetUp(self):
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
189 ThreadedTCPSocketTest.clientSetUp(self)
46370
2e917b0c8f6e Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46262
diff changeset
190 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
191 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
192
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
193 def clientTearDown(self):
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
194 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
195 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
196 ThreadedTCPSocketTest.clientTearDown(self)
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
197
33063
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
198 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
199
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
200 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
201 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
202 ThreadableTest.__init__(self)
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
203
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
204 def setUp(self):
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
205 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
206
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
207 def tearDown(self):
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
208 self.serv.close()
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
209 self.serv = None
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
210
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
211 def clientSetUp(self):
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
212 pass
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
213
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
214 def clientTearDown(self):
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
215 self.cli.close()
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
216 self.cli = None
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
217 ThreadableTest.clientTearDown(self)
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
218
33076
836e77266f97 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 33063
diff changeset
219
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
220 #######################################################################
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
221 ## Begin Tests
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
222
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
223 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
224
41941
e4ab08039c75 Simplify socket_repr() by using PyUnicode_FromFormat()
Walter Dörwald <walter@livinglogic.de>
parents: 41824
diff changeset
225 def test_repr(self):
e4ab08039c75 Simplify socket_repr() by using PyUnicode_FromFormat()
Walter Dörwald <walter@livinglogic.de>
parents: 41824
diff changeset
226 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
e4ab08039c75 Simplify socket_repr() by using PyUnicode_FromFormat()
Walter Dörwald <walter@livinglogic.de>
parents: 41824
diff changeset
227 self.assert_(repr(s).startswith("<socket.socket object"))
e4ab08039c75 Simplify socket_repr() by using PyUnicode_FromFormat()
Walter Dörwald <walter@livinglogic.de>
parents: 41824
diff changeset
228
32160
aec9c98a47d2 Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents: 31833
diff changeset
229 def test_weakref(self):
aec9c98a47d2 Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents: 31833
diff changeset
230 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
231 p = proxy(s)
aec9c98a47d2 Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents: 31833
diff changeset
232 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
233 s.close()
aec9c98a47d2 Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents: 31833
diff changeset
234 s = None
aec9c98a47d2 Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents: 31833
diff changeset
235 try:
aec9c98a47d2 Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents: 31833
diff changeset
236 p.fileno()
aec9c98a47d2 Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents: 31833
diff changeset
237 except ReferenceError:
aec9c98a47d2 Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents: 31833
diff changeset
238 pass
aec9c98a47d2 Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents: 31833
diff changeset
239 else:
aec9c98a47d2 Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents: 31833
diff changeset
240 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
241
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
242 def testSocketError(self):
24655
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
243 # 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
244 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
245 raise socket.error
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
246 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
247 raise socket.herror
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
248 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
249 raise socket.gaierror
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
250 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
251 "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
252 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
253 "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
254 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
255 "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
256
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
257 def testCrucialConstants(self):
24655
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
258 # 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
259 socket.AF_INET
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
260 socket.SOCK_STREAM
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
261 socket.SOCK_DGRAM
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
262 socket.SOCK_RAW
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
263 socket.SOCK_RDM
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
264 socket.SOCK_SEQPACKET
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
265 socket.SOL_SOCKET
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
266 socket.SO_REUSEADDR
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
267
23831
f7306ae8662d Temporarily disable the timeout and socket tests.
Guido van Rossum <guido@python.org>
parents: 23819
diff changeset
268 def testHostnameRes(self):
24655
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
269 # Testing hostname resolution mechanisms
23831
f7306ae8662d Temporarily disable the timeout and socket tests.
Guido van Rossum <guido@python.org>
parents: 23819
diff changeset
270 hostname = socket.gethostname()
26799
507aa96a128f Skip testHostnameRes() if gethostbyname() raises an exception.
Guido van Rossum <guido@python.org>
parents: 25285
diff changeset
271 try:
507aa96a128f Skip testHostnameRes() if gethostbyname() raises an exception.
Guido van Rossum <guido@python.org>
parents: 25285
diff changeset
272 ip = socket.gethostbyname(hostname)
507aa96a128f Skip testHostnameRes() if gethostbyname() raises an exception.
Guido van Rossum <guido@python.org>
parents: 25285
diff changeset
273 except socket.error:
507aa96a128f Skip testHostnameRes() if gethostbyname() raises an exception.
Guido van Rossum <guido@python.org>
parents: 25285
diff changeset
274 # 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
275 return
23831
f7306ae8662d Temporarily disable the timeout and socket tests.
Guido van Rossum <guido@python.org>
parents: 23819
diff changeset
276 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
277 try:
b2b4797052c6 Also skip testHostnameRes() if gethostbyaddr() raises an exception.
Guido van Rossum <guido@python.org>
parents: 26799
diff changeset
278 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
279 except socket.error:
b2b4797052c6 Also skip testHostnameRes() if gethostbyaddr() raises an exception.
Guido van Rossum <guido@python.org>
parents: 26799
diff changeset
280 # 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
281 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
282 all_host_names = [hostname, hname] + aliases
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
283 fqhn = socket.getfqdn(ip)
23831
f7306ae8662d Temporarily disable the timeout and socket tests.
Guido van Rossum <guido@python.org>
parents: 23819
diff changeset
284 if not fqhn in all_host_names:
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
285 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
286
23799
2ad13ee6d850 Don't test for Java, test for sys.getrefcount.
Guido van Rossum <guido@python.org>
parents: 23798
diff changeset
287 def testRefCountGetNameInfo(self):
24655
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
288 # 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
289 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
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 loses a reference
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
292 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
293 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
294 except SystemError:
39648
efe3f2c0da5e Killed the <> operator. You must now use !=.
Guido van Rossum <guido@python.org>
parents: 39442
diff changeset
295 if sys.getrefcount(__name__) != orig:
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
296 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
297
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
298 def testInterpreterCrash(self):
24655
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
299 # 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
300 try:
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
301 # 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
302 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
303 except socket.error:
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
304 pass
4880
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
305
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
306 def testNtoH(self):
25256
04a541e68964 Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents: 25152
diff changeset
307 # 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
308 # 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
309 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
310 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
311 for func, size in sizes.items():
40644
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 40638
diff changeset
312 mask = (1<<size) - 1
25256
04a541e68964 Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents: 25152
diff changeset
313 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
314 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
315
25256
04a541e68964 Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents: 25152
diff changeset
316 swapped = func(mask)
04a541e68964 Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents: 25152
diff changeset
317 self.assertEqual(swapped & mask, mask)
40644
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 40638
diff changeset
318 self.assertRaises(OverflowError, func, 1<<34)
24375
89ce62126664 Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24374
diff changeset
319
40638
86ce1df6a88e Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40587
diff changeset
320 def testNtoHErrors(self):
40644
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 40638
diff changeset
321 good_values = [ 1, 2, 3, 1, 2, 3 ]
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 40638
diff changeset
322 bad_values = [ -1, -2, -3, -1, -2, -3 ]
40638
86ce1df6a88e Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40587
diff changeset
323 for k in good_values:
86ce1df6a88e Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40587
diff changeset
324 socket.ntohl(k)
86ce1df6a88e Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40587
diff changeset
325 socket.ntohs(k)
86ce1df6a88e Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40587
diff changeset
326 socket.htonl(k)
86ce1df6a88e Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40587
diff changeset
327 socket.htons(k)
86ce1df6a88e Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40587
diff changeset
328 for k in bad_values:
86ce1df6a88e Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40587
diff changeset
329 self.assertRaises(OverflowError, socket.ntohl, k)
86ce1df6a88e Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40587
diff changeset
330 self.assertRaises(OverflowError, socket.ntohs, k)
86ce1df6a88e Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40587
diff changeset
331 self.assertRaises(OverflowError, socket.htonl, k)
86ce1df6a88e Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40587
diff changeset
332 self.assertRaises(OverflowError, socket.htons, k)
86ce1df6a88e Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40587
diff changeset
333
32429
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32160
diff changeset
334 def testGetServBy(self):
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32160
diff changeset
335 eq = self.assertEqual
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32160
diff changeset
336 # 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
337 # 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
338 # 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
339 if sys.platform in ('linux2', 'freebsd4', 'freebsd5', 'freebsd6',
43734
3e5edf19d5f0 Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 43014
diff changeset
340 '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
341 # 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
342 # 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
343 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
344 else:
059dae06585b FreeBSD's services file contains an additional echo service entry, with
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 32508
diff changeset
345 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
346 for service in services:
24485
f05a311d7988 testGetServByName shouldn't check for getservbyname - the socket module
Skip Montanaro <skip@pobox.com>
parents: 24470
diff changeset
347 try:
32429
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32160
diff changeset
348 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
349 break
f05a311d7988 testGetServByName shouldn't check for getservbyname - the socket module
Skip Montanaro <skip@pobox.com>
parents: 24470
diff changeset
350 except socket.error:
f05a311d7988 testGetServByName shouldn't check for getservbyname - the socket module
Skip Montanaro <skip@pobox.com>
parents: 24470
diff changeset
351 pass
31503
eb48b2503f20 Fix indentation error in testGetServByName and rewrite loop to avoid clumsy
Skip Montanaro <skip@pobox.com>
parents: 29662
diff changeset
352 else:
eb48b2503f20 Fix indentation error in testGetServByName and rewrite loop to avoid clumsy
Skip Montanaro <skip@pobox.com>
parents: 29662
diff changeset
353 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
354 # 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
355 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
356 eq(port, port2)
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32160
diff changeset
357 # 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
358 try:
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32160
diff changeset
359 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
360 except socket.error:
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32160
diff changeset
361 udpport = None
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32160
diff changeset
362 else:
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32160
diff changeset
363 eq(udpport, port)
d8abf582f893 Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents: 32160
diff changeset
364 # 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
365 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
366 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
367 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
368 eq(socket.getservbyport(udpport, 'udp'), service)
51384
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
369 # Make sure getservbyport does not accept out of range ports.
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
370 self.assertRaises(OverflowError, socket.getservbyport, -1)
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
371 self.assertRaises(OverflowError, socket.getservbyport, 65536)
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
372
24293
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 23931
diff changeset
373 def testDefaultTimeout(self):
24655
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
374 # Testing default timeout
24293
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 23931
diff changeset
375 # 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
376 self.assertEqual(socket.getdefaulttimeout(), None)
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 23931
diff changeset
377 s = socket.socket()
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 23931
diff changeset
378 self.assertEqual(s.gettimeout(), None)
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 23931
diff changeset
379 s.close()
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 23931
diff changeset
380
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 23931
diff changeset
381 # 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
382 socket.setdefaulttimeout(10)
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 23931
diff changeset
383 self.assertEqual(socket.getdefaulttimeout(), 10)
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 23931
diff changeset
384 s = socket.socket()
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 23931
diff changeset
385 self.assertEqual(s.gettimeout(), 10)
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 23931
diff changeset
386 s.close()
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 23931
diff changeset
387
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 23931
diff changeset
388 # 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
389 socket.setdefaulttimeout(None)
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 23931
diff changeset
390 self.assertEqual(socket.getdefaulttimeout(), None)
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 23931
diff changeset
391 s = socket.socket()
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 23931
diff changeset
392 self.assertEqual(s.gettimeout(), None)
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 23931
diff changeset
393 s.close()
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 23931
diff changeset
394
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 23931
diff changeset
395 # 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
396 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
397
640370f08e2a Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents: 23931
diff changeset
398 # 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
399 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
400
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
401 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
402 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
403 return # No inet_pton() on this platform
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
404 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
405 g = lambda a: inet_pton(AF_INET, a)
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
406
41770
651fa2c9c2ab Make test_socket pass. There was an unchecked error when a Unicode
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
407 self.assertEquals(b'\x00\x00\x00\x00', f('0.0.0.0'))
651fa2c9c2ab Make test_socket pass. There was an unchecked error when a Unicode
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
408 self.assertEquals(b'\xff\x00\xff\x00', f('255.0.255.0'))
651fa2c9c2ab Make test_socket pass. There was an unchecked error when a Unicode
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
409 self.assertEquals(b'\xaa\xaa\xaa\xaa', f('170.170.170.170'))
651fa2c9c2ab Make test_socket pass. There was an unchecked error when a Unicode
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
410 self.assertEquals(b'\x01\x02\x03\x04', f('1.2.3.4'))
651fa2c9c2ab Make test_socket pass. There was an unchecked error when a Unicode
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
411 self.assertEquals(b'\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
412
41770
651fa2c9c2ab Make test_socket pass. There was an unchecked error when a Unicode
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
413 self.assertEquals(b'\x00\x00\x00\x00', g('0.0.0.0'))
651fa2c9c2ab Make test_socket pass. There was an unchecked error when a Unicode
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
414 self.assertEquals(b'\xff\x00\xff\x00', g('255.0.255.0'))
651fa2c9c2ab Make test_socket pass. There was an unchecked error when a Unicode
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
415 self.assertEquals(b'\xaa\xaa\xaa\xaa', g('170.170.170.170'))
651fa2c9c2ab Make test_socket pass. There was an unchecked error when a Unicode
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
416 self.assertEquals(b'\xff\xff\xff\xff', g('255.255.255.255'))
29087
526f37fb380d Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 28917
diff changeset
417
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
418 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
419 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
420 return # No inet_pton() on this platform
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
421 try:
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
422 from socket import inet_pton, AF_INET6, has_ipv6
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
423 if not has_ipv6:
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
424 return
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
425 except ImportError:
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
426 return
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
427 f = lambda a: inet_pton(AF_INET6, a)
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
428
42637
ff5adb3374ad Fix the IPv6 pton/ntop tests. Why weren't these failing on Linux? No IPv6?
Guido van Rossum <guido@python.org>
parents: 42596
diff changeset
429 self.assertEquals(b'\x00' * 16, f('::'))
ff5adb3374ad Fix the IPv6 pton/ntop tests. Why weren't these failing on Linux? No IPv6?
Guido van Rossum <guido@python.org>
parents: 42596
diff changeset
430 self.assertEquals(b'\x00' * 16, f('0::0'))
ff5adb3374ad Fix the IPv6 pton/ntop tests. Why weren't these failing on Linux? No IPv6?
Guido van Rossum <guido@python.org>
parents: 42596
diff changeset
431 self.assertEquals(b'\x00\x01' + b'\x00' * 14, f('1::'))
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
432 self.assertEquals(
42169
e38047550383 Fix test_socket.py. Simple str/bytes issue with IPV6 addresse.
Guido van Rossum <guido@python.org>
parents: 41941
diff changeset
433 b'\x45\xef\x76\xcb\x00\x1a\x56\xef\xaf\xeb\x0b\xac\x19\x24\xae\xae',
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
434 f('45ef:76cb:1a:56ef:afeb:bac:1924:aeae')
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
435 )
29087
526f37fb380d Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 28917
diff changeset
436
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
437 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
438 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
439 return # No inet_ntop() on this platform
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
440 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
441 g = lambda a: inet_ntop(AF_INET, a)
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
442
41770
651fa2c9c2ab Make test_socket pass. There was an unchecked error when a Unicode
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
443 self.assertEquals('1.0.1.0', f(b'\x01\x00\x01\x00'))
651fa2c9c2ab Make test_socket pass. There was an unchecked error when a Unicode
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
444 self.assertEquals('170.85.170.85', f(b'\xaa\x55\xaa\x55'))
651fa2c9c2ab Make test_socket pass. There was an unchecked error when a Unicode
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
445 self.assertEquals('255.255.255.255', f(b'\xff\xff\xff\xff'))
651fa2c9c2ab Make test_socket pass. There was an unchecked error when a Unicode
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
446 self.assertEquals('1.2.3.4', f(b'\x01\x02\x03\x04'))
29087
526f37fb380d Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 28917
diff changeset
447
41770
651fa2c9c2ab Make test_socket pass. There was an unchecked error when a Unicode
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
448 self.assertEquals('1.0.1.0', g(b'\x01\x00\x01\x00'))
651fa2c9c2ab Make test_socket pass. There was an unchecked error when a Unicode
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
449 self.assertEquals('170.85.170.85', g(b'\xaa\x55\xaa\x55'))
651fa2c9c2ab Make test_socket pass. There was an unchecked error when a Unicode
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
450 self.assertEquals('255.255.255.255', g(b'\xff\xff\xff\xff'))
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
451
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
452 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
453 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
454 return # No inet_ntop() on this platform
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
455 try:
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
456 from socket import inet_ntop, AF_INET6, has_ipv6
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
457 if not has_ipv6:
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
458 return
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
459 except ImportError:
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
460 return
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
461 f = lambda a: inet_ntop(AF_INET6, a)
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
462
42637
ff5adb3374ad Fix the IPv6 pton/ntop tests. Why weren't these failing on Linux? No IPv6?
Guido van Rossum <guido@python.org>
parents: 42596
diff changeset
463 self.assertEquals('::', f(b'\x00' * 16))
ff5adb3374ad Fix the IPv6 pton/ntop tests. Why weren't these failing on Linux? No IPv6?
Guido van Rossum <guido@python.org>
parents: 42596
diff changeset
464 self.assertEquals('::1', f(b'\x00' * 15 + b'\x01'))
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
465 self.assertEquals(
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
466 'aef:b01:506:1001:ffff:9997:55:170',
42169
e38047550383 Fix test_socket.py. Simple str/bytes issue with IPV6 addresse.
Guido van Rossum <guido@python.org>
parents: 41941
diff changeset
467 f(b'\x0a\xef\x0b\x01\x05\x06\x10\x01\xff\xff\x99\x97\x00\x55\x01\x70')
28818
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
468 )
57e61588571b Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents: 26800
diff changeset
469
24318
12815d05080c Add test for previous core dump when sending on closed socket with
Guido van Rossum <guido@python.org>
parents: 24293
diff changeset
470 # 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
471
51384
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
472 def _get_unused_port(self, bind_address='0.0.0.0'):
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
473 """Use a temporary socket to elicit an unused ephemeral port.
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
474
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
475 Args:
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
476 bind_address: Hostname or IP address to search for a port on.
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
477
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
478 Returns: A most likely to be unused port.
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
479 """
46370
2e917b0c8f6e Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46262
diff changeset
480 tempsock = socket.socket()
51384
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
481 tempsock.bind((bind_address, 0))
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
482 host, port = tempsock.getsockname()
46370
2e917b0c8f6e Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46262
diff changeset
483 tempsock.close()
51384
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
484 return port
46370
2e917b0c8f6e Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46262
diff changeset
485
51384
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
486 def testSockName(self):
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
487 # Testing getsockname()
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
488 port = self._get_unused_port()
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
489 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
46370
2e917b0c8f6e Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46262
diff changeset
490 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
491 name = sock.getsockname()
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
492 # XXX(nnorwitz): http://tinyurl.com/os5jz seems to indicate
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
493 # it reasonable to get the host's addr in addition to 0.0.0.0.
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
494 # At least for eCos. This is required for the S/390 to pass.
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
495 my_ip_addr = socket.gethostbyname(socket.gethostname())
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
496 self.assert_(name[0] in ("0.0.0.0", my_ip_addr), '%s invalid' % name[0])
46370
2e917b0c8f6e Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46262
diff changeset
497 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
498
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
499 def testGetSockOpt(self):
24655
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
500 # Testing getsockopt()
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
501 # 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
502 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
503 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
504 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
505
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
506 def testSetSockOpt(self):
24655
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
507 # Testing setsockopt()
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
508 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
509 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
510 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
511 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
512
24318
12815d05080c Add test for previous core dump when sending on closed socket with
Guido van Rossum <guido@python.org>
parents: 24293
diff changeset
513 def testSendAfterClose(self):
24655
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
514 # 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
515 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
516 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
517 sock.close()
43954
092b5306983f Convert the socket module to insist on bytes for input, and to return bytes
Guido van Rossum <guido@python.org>
parents: 43881
diff changeset
518 self.assertRaises(socket.error, sock.send, b"spam")
24318
12815d05080c Add test for previous core dump when sending on closed socket with
Guido van Rossum <guido@python.org>
parents: 24293
diff changeset
519
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
520 def testNewAttributes(self):
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
521 # testing .family, .type and .protocol
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
522 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
523 self.assertEqual(sock.family, socket.AF_INET)
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
524 self.assertEqual(sock.type, socket.SOCK_STREAM)
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
525 self.assertEqual(sock.proto, 0)
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
526 sock.close()
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
527
51384
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
528 def test_getsockaddrarg(self):
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
529 host = '0.0.0.0'
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
530 port = self._get_unused_port(bind_address=host)
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
531 big_port = port + 65536
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
532 neg_port = port - 65536
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
533 sock = socket.socket()
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
534 try:
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
535 self.assertRaises(OverflowError, sock.bind, (host, big_port))
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
536 self.assertRaises(OverflowError, sock.bind, (host, neg_port))
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
537 sock.bind((host, port))
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
538 finally:
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
539 sock.close()
7a0525613644 Merged revisions 69350 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50927
diff changeset
540
44535
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43954
diff changeset
541 def test_sock_ioctl(self):
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43954
diff changeset
542 if os.name != "nt":
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43954
diff changeset
543 return
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43954
diff changeset
544 self.assert_(hasattr(socket.socket, 'ioctl'))
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43954
diff changeset
545 self.assert_(hasattr(socket, 'SIO_RCVALL'))
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43954
diff changeset
546 self.assert_(hasattr(socket, 'RCVALL_ON'))
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43954
diff changeset
547 self.assert_(hasattr(socket, 'RCVALL_OFF'))
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43954
diff changeset
548
420fe6d7d5f4 Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43954
diff changeset
549
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
550 class BasicTCPTest(SocketConnectedTest):
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
551
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
552 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
553 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
554
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
555 def testRecv(self):
24655
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
556 # 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
557 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
558 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
559
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
560 def _testRecv(self):
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
561 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
562
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
563 def testOverFlowRecv(self):
24655
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
564 # 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
565 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
566 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
567 msg = seg1 + seg2
23794
1f1a6f7dd600 Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents: 23790
diff changeset
568 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
569
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
570 def _testOverFlowRecv(self):
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
571 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
572
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
573 def testRecvFrom(self):
24655
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
574 # 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
575 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
576 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
577
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
578 def _testRecvFrom(self):
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
579 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
580
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
581 def testOverFlowRecvFrom(self):
24655
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
582 # 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
583 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
584 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
585 msg = seg1 + seg2
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 _testOverFlowRecvFrom(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
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
591 def testSendAll(self):
24655
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
592 # Testing sendall() with a 2048 byte string over TCP
41809
8e062e572ea4 Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents: 41770
diff changeset
593 msg = b''
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
594 while 1:
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
595 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
596 if not read:
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
597 break
24675
fec0b0aef14b testSendAll(): loop until all data is read; this was necessary at
Guido van Rossum <guido@python.org>
parents: 24674
diff changeset
598 msg += read
41809
8e062e572ea4 Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents: 41770
diff changeset
599 self.assertEqual(msg, b'f' * 2048)
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
600
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
601 def _testSendAll(self):
41809
8e062e572ea4 Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents: 41770
diff changeset
602 big_chunk = b'f' * 2048
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
603 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
604
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
605 def testFromFd(self):
24655
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
606 # Testing fromfd()
23797
ba29485d0720 Argh. Typo. :-(
Guido van Rossum <guido@python.org>
parents: 23796
diff changeset
607 if not hasattr(socket, "fromfd"):
23796
fcc36ee1924b Allow absent fromfd(), for Windows.
Guido van Rossum <guido@python.org>
parents: 23795
diff changeset
608 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
609 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
610 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
611 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
612 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
613
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
614 def _testFromFd(self):
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
615 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
616
43881
70cfc7b504c2 This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents: 43734
diff changeset
617 def testDup(self):
70cfc7b504c2 This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents: 43734
diff changeset
618 # Testing dup()
70cfc7b504c2 This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents: 43734
diff changeset
619 sock = self.cli_conn.dup()
70cfc7b504c2 This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents: 43734
diff changeset
620 msg = sock.recv(1024)
70cfc7b504c2 This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents: 43734
diff changeset
621 self.assertEqual(msg, MSG)
70cfc7b504c2 This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents: 43734
diff changeset
622
70cfc7b504c2 This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents: 43734
diff changeset
623 def _testDup(self):
70cfc7b504c2 This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents: 43734
diff changeset
624 self.serv_conn.send(MSG)
70cfc7b504c2 This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents: 43734
diff changeset
625
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
626 def testShutdown(self):
24655
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
627 # Testing shutdown()
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
628 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
629 self.assertEqual(msg, MSG)
50801
bb86f2ed18aa Merged revisions 68615 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 49800
diff changeset
630 # wait for _testShutdown to finish: on OS X, when the server
bb86f2ed18aa Merged revisions 68615 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 49800
diff changeset
631 # closes the connection the client also becomes disconnected,
bb86f2ed18aa Merged revisions 68615 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 49800
diff changeset
632 # and the client's shutdown call will fail. (Issue #4397.)
bb86f2ed18aa Merged revisions 68615 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 49800
diff changeset
633 self.done.wait()
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
634
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
635 def _testShutdown(self):
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
636 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
637 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
638
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
639 class BasicUDPTest(ThreadedUDPSocketTest):
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
640
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
641 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
642 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
643
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
644 def testSendtoAndRecv(self):
24655
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
645 # 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
646 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
647 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
648
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
649 def _testSendtoAndRecv(self):
46370
2e917b0c8f6e Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46262
diff changeset
650 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
651
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
652 def testRecvFrom(self):
24655
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
653 # 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
654 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
655 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
656
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
657 def _testRecvFrom(self):
46370
2e917b0c8f6e Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46262
diff changeset
658 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
659
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
660 def testRecvFromNegative(self):
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
661 # Negative lengths passed to recvfrom should give ValueError.
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
662 self.assertRaises(ValueError, self.serv.recvfrom, -1)
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
663
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
664 def _testRecvFromNegative(self):
46370
2e917b0c8f6e Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46262
diff changeset
665 self.cli.sendto(MSG, 0, (HOST, self.port))
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
666
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
667 class TCPCloserTest(ThreadedTCPSocketTest):
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
668
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
669 def testClose(self):
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
670 conn, addr = self.serv.accept()
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
671 conn.close()
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
672
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
673 sd = self.cli
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
674 read, write, err = select.select([sd], [], [], 1.0)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
675 self.assertEqual(read, [sd])
41809
8e062e572ea4 Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents: 41770
diff changeset
676 self.assertEqual(sd.recv(1), b'')
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
677
42434
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
678 # Calling close() many times should be safe.
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
679 conn.close()
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
680 conn.close()
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
681
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
682 def _testClose(self):
46370
2e917b0c8f6e Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46262
diff changeset
683 self.cli.connect((HOST, self.port))
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
684 time.sleep(1.0)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
685
33063
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
686 class BasicSocketPairTest(SocketPairTest):
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
687
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
688 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
689 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
690
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
691 def testRecv(self):
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
692 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
693 self.assertEqual(msg, MSG)
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
694
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
695 def _testRecv(self):
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
696 self.cli.send(MSG)
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
697
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
698 def testSend(self):
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
699 self.serv.send(MSG)
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
700
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
701 def _testSend(self):
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
702 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
703 self.assertEqual(msg, MSG)
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
704
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
705 class NonBlockingTCPTests(ThreadedTCPSocketTest):
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
706
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
707 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
708 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
709
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
710 def testSetBlocking(self):
24655
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
711 # 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
712 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
713 start = time.time()
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
714 try:
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
715 self.serv.accept()
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
716 except socket.error:
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
717 pass
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
718 end = time.time()
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
719 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
720
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
721 def _testSetBlocking(self):
17208
c8817a9bbbdd Make socket.getservbyname test optional on socket module having that
Barry Warsaw <barry@python.org>
parents: 16519
diff changeset
722 pass
4880
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
723
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
724 def testAccept(self):
24655
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
725 # 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
726 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
727 try:
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
728 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
729 except socket.error:
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
730 pass
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
731 else:
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
732 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
733 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
734 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
735 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
736 else:
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
737 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
738
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
739 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
740 time.sleep(0.1)
46370
2e917b0c8f6e Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46262
diff changeset
741 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
742
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
743 def testConnect(self):
24655
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
744 # 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
745 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
746
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
747 def _testConnect(self):
23818
8a0a14e3725e Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents: 23815
diff changeset
748 self.cli.settimeout(10)
46370
2e917b0c8f6e Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46262
diff changeset
749 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
750
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
751 def testRecv(self):
24655
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
752 # 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
753 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
754 conn.setblocking(0)
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
755 try:
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
756 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
757 except socket.error:
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
758 pass
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
759 else:
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
760 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
761 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
762 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
763 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
764 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
765 else:
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
766 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
767
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
768 def _testRecv(self):
46370
2e917b0c8f6e Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46262
diff changeset
769 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
770 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
771 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
772
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
773 class FileObjectClassTestCase(SocketConnectedTest):
42434
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
774 """Unit tests for the object returned by socket.makefile()
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
775
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
776 self.serv_file is the io object returned by makefile() on
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
777 the client connection. You can read from this file to
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
778 get output from the server.
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
779
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
780 self.cli_file is the io object returned by makefile() on the
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
781 server connection. You can write to this file to send output
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
782 to the client.
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
783 """
23715
c2733e8f6612 SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 21315
diff changeset
784
24634
778093533a46 "Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents: 24485
diff changeset
785 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
786
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
787 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
788 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
789
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
790 def setUp(self):
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
791 SocketConnectedTest.setUp(self)
24634
778093533a46 "Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents: 24485
diff changeset
792 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
793
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
794 def tearDown(self):
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
795 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
796 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
797 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
798 SocketConnectedTest.tearDown(self)
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
799
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
800 def clientSetUp(self):
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
801 SocketConnectedTest.clientSetUp(self)
24634
778093533a46 "Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents: 24485
diff changeset
802 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
803
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
804 def clientTearDown(self):
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
805 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
806 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
807 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
808 SocketConnectedTest.clientTearDown(self)
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
809
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
810 def testSmallRead(self):
24655
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
811 # 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
812 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
813 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
814 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
815 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
816
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
817 def _testSmallRead(self):
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
818 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
819 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
820
24655
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
821 def testFullRead(self):
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
822 # read until EOF
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
823 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
824 self.assertEqual(msg, MSG)
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
825
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
826 def _testFullRead(self):
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
827 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
828 self.cli_file.close()
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
829
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
830 def testUnbufferedRead(self):
24655
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
831 # Performing unbuffered file read test
41809
8e062e572ea4 Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents: 41770
diff changeset
832 buf = b''
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
833 while 1:
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
834 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
835 if not char:
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
836 break
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
837 buf += char
24655
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
838 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
839
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
840 def _testUnbufferedRead(self):
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
841 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
842 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
843
23790
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
844 def testReadline(self):
24655
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
845 # 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
846 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
847 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
848
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
849 def _testReadline(self):
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
850 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
851 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
852
42434
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
853 def testCloseAfterMakefile(self):
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
854 # The file returned by makefile should keep the socket open.
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
855 self.cli_conn.close()
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
856 # read until EOF
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
857 msg = self.serv_file.read()
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
858 self.assertEqual(msg, MSG)
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
859
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
860 def _testCloseAfterMakefile(self):
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
861 self.cli_file.write(MSG)
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
862 self.cli_file.flush()
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
863
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
864 def testMakefileAfterMakefileClose(self):
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
865 self.serv_file.close()
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
866 msg = self.cli_conn.recv(len(MSG))
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
867 self.assertEqual(msg, MSG)
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
868
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
869 def _testMakefileAfterMakefileClose(self):
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
870 self.cli_file.write(MSG)
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
871 self.cli_file.flush()
c35140559f87 Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42169
diff changeset
872
31833
a910b822b12c SF bug 924242: socket._fileobject._getclosed() returns wrong value
Tim Peters <tim.peters@gmail.com>
parents: 31503
diff changeset
873 def testClosedAttr(self):
a910b822b12c SF bug 924242: socket._fileobject._getclosed() returns wrong value
Tim Peters <tim.peters@gmail.com>
parents: 31503
diff changeset
874 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
875
a910b822b12c SF bug 924242: socket._fileobject._getclosed() returns wrong value
Tim Peters <tim.peters@gmail.com>
parents: 31503
diff changeset
876 def _testClosedAttr(self):
a910b822b12c SF bug 924242: socket._fileobject._getclosed() returns wrong value
Tim Peters <tim.peters@gmail.com>
parents: 31503
diff changeset
877 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
878
49782
5ffd67df8c9f Follow-up of r67300: correct a failure in socket.makefile().
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48623
diff changeset
879 def testAttributes(self):
49800
6aef28ebbd6c make FileIO.mode always include 'b'
Benjamin Peterson <benjamin@python.org>
parents: 49782
diff changeset
880 self.assertEqual(self.serv_file.mode, 'rb')
49782
5ffd67df8c9f Follow-up of r67300: correct a failure in socket.makefile().
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48623
diff changeset
881 self.assertEqual(self.serv_file.name, self.cli_conn.fileno())
5ffd67df8c9f Follow-up of r67300: correct a failure in socket.makefile().
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48623
diff changeset
882
5ffd67df8c9f Follow-up of r67300: correct a failure in socket.makefile().
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48623
diff changeset
883 def _testAttributes(self):
49800
6aef28ebbd6c make FileIO.mode always include 'b'
Benjamin Peterson <benjamin@python.org>
parents: 49782
diff changeset
884 self.assertEqual(self.cli_file.mode, 'wb')
49782
5ffd67df8c9f Follow-up of r67300: correct a failure in socket.makefile().
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48623
diff changeset
885 self.assertEqual(self.cli_file.name, self.serv_conn.fileno())
5ffd67df8c9f Follow-up of r67300: correct a failure in socket.makefile().
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48623
diff changeset
886
50927
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
887 def testRealClose(self):
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
888 self.serv_file.close()
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
889 self.assertRaises(ValueError, self.serv_file.fileno)
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
890 self.cli_conn.close()
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
891 self.assertRaises(socket.error, self.cli_conn.getsockname)
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
892
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
893 def _testRealClose(self):
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
894 pass
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
895
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
896
24634
778093533a46 "Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents: 24485
diff changeset
897 class UnbufferedFileObjectClassTestCase(FileObjectClassTestCase):
778093533a46 "Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents: 24485
diff changeset
898
778093533a46 "Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents: 24485
diff changeset
899 """Repeat the tests from FileObjectClassTestCase with bufsize==0.
24674
3269bdd65988 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 24655
diff changeset
900
24634
778093533a46 "Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents: 24485
diff changeset
901 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
902 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
903 object, read another line from it, without loss of data in the
47318
e1fcc3881cb6 Create http package. #2883.
Georg Brandl <georg@python.org>
parents: 47266
diff changeset
904 first file object's buffer. Note that http.client relies on this
24634
778093533a46 "Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents: 24485
diff changeset
905 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
906
778093533a46 "Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents: 24485
diff changeset
907 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
908
778093533a46 "Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents: 24485
diff changeset
909 def testUnbufferedReadline(self):
24655
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
910 # 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
911 line = self.serv_file.readline() # first line
41809
8e062e572ea4 Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents: 41770
diff changeset
912 self.assertEqual(line, b"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
913 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
914 line = self.serv_file.readline() # second line
41809
8e062e572ea4 Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents: 41770
diff changeset
915 self.assertEqual(line, b"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
916
778093533a46 "Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents: 24485
diff changeset
917 def _testUnbufferedReadline(self):
41809
8e062e572ea4 Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents: 41770
diff changeset
918 self.cli_file.write(b"A. " + MSG)
8e062e572ea4 Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents: 41770
diff changeset
919 self.cli_file.write(b"B. " + MSG)
24634
778093533a46 "Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents: 24485
diff changeset
920 self.cli_file.flush()
778093533a46 "Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents: 24485
diff changeset
921
50927
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
922 def testMakefileClose(self):
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
923 # The file returned by makefile should keep the socket open...
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
924 self.cli_conn.close()
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
925 msg = self.cli_conn.recv(1024)
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
926 self.assertEqual(msg, MSG)
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
927 # ...until the file is itself closed
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
928 self.serv_file.close()
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
929 self.assertRaises(socket.error, self.cli_conn.recv, 1024)
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
930
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
931 def _testMakefileClose(self):
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
932 self.cli_file.write(MSG)
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
933 self.cli_file.flush()
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
934
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
935 def testMakefileCloseSocketDestroy(self):
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
936 refcount_before = sys.getrefcount(self.cli_conn)
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
937 self.serv_file.close()
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
938 refcount_after = sys.getrefcount(self.cli_conn)
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
939 self.assertEqual(refcount_before - 1, refcount_after)
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
940
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
941 def _testMakefileCloseSocketDestroy(self):
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
942 pass
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
943
5c3bf31d04fd Backport r68539, Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents: 50801
diff changeset
944
24655
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
945 class LineBufferedFileObjectClassTestCase(FileObjectClassTestCase):
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
946
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
947 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
948
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
949
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
950 class SmallBufferedFileObjectClassTestCase(FileObjectClassTestCase):
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
951
18ca4e783f98 Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents: 24648
diff changeset
952 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
953
40737
6ebad2a6b990 Merged revisions 53451-53537 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40644
diff changeset
954
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
955 class NetworkConnectionTest(object):
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
956 """Prove network connection."""
41809
8e062e572ea4 Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents: 41770
diff changeset
957
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
958 def clientSetUp(self):
46370
2e917b0c8f6e Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46262
diff changeset
959 # We're inherited below by BasicTCPTest2, which also inherits
2e917b0c8f6e Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46262
diff changeset
960 # BasicTCPTest, which defines self.port referenced below.
2e917b0c8f6e Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46262
diff changeset
961 self.cli = socket.create_connection((HOST, self.port))
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
962 self.serv_conn = self.cli
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
963
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
964 class BasicTCPTest2(NetworkConnectionTest, BasicTCPTest):
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
965 """Tests that NetworkConnection does not break existing TCP functionality.
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
966 """
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
967
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
968 class NetworkConnectionNoServer(unittest.TestCase):
41809
8e062e572ea4 Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents: 41770
diff changeset
969
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
970 def testWithoutServer(self):
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 46899
diff changeset
971 port = support.find_unused_port()
46370
2e917b0c8f6e Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46262
diff changeset
972 self.failUnlessRaises(
2e917b0c8f6e Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46262
diff changeset
973 socket.error,
2e917b0c8f6e Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46262
diff changeset
974 lambda: socket.create_connection((HOST, port))
2e917b0c8f6e Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46262
diff changeset
975 )
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
976
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
977 class NetworkConnectionAttributesTest(SocketTCPTest, ThreadableTest):
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
978
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
979 def __init__(self, methodName='runTest'):
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
980 SocketTCPTest.__init__(self, methodName=methodName)
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
981 ThreadableTest.__init__(self)
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
982
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
983 def clientSetUp(self):
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
984 pass
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
985
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
986 def clientTearDown(self):
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
987 self.cli.close()
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
988 self.cli = None
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
989 ThreadableTest.clientTearDown(self)
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
990
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
991 def _justAccept(self):
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
992 conn, addr = self.serv.accept()
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
993
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
994 testFamily = _justAccept
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
995 def _testFamily(self):
46370
2e917b0c8f6e Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46262
diff changeset
996 self.cli = socket.create_connection((HOST, self.port), timeout=30)
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
997 self.assertEqual(self.cli.family, 2)
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
998
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
999 testTimeoutDefault = _justAccept
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1000 def _testTimeoutDefault(self):
47559
2925b568aacc Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47318
diff changeset
1001 # passing no explicit timeout uses socket's global default
2925b568aacc Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47318
diff changeset
1002 self.assert_(socket.getdefaulttimeout() is None)
2925b568aacc Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47318
diff changeset
1003 socket.setdefaulttimeout(42)
2925b568aacc Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47318
diff changeset
1004 try:
2925b568aacc Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47318
diff changeset
1005 self.cli = socket.create_connection((HOST, self.port))
2925b568aacc Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47318
diff changeset
1006 finally:
2925b568aacc Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47318
diff changeset
1007 socket.setdefaulttimeout(None)
2925b568aacc Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47318
diff changeset
1008 self.assertEquals(self.cli.gettimeout(), 42)
2925b568aacc Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47318
diff changeset
1009
2925b568aacc Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47318
diff changeset
1010 testTimeoutNone = _justAccept
2925b568aacc Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47318
diff changeset
1011 def _testTimeoutNone(self):
2925b568aacc Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47318
diff changeset
1012 # None timeout means the same as sock.settimeout(None)
2925b568aacc Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47318
diff changeset
1013 self.assert_(socket.getdefaulttimeout() is None)
2925b568aacc Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47318
diff changeset
1014 socket.setdefaulttimeout(30)
2925b568aacc Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47318
diff changeset
1015 try:
2925b568aacc Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47318
diff changeset
1016 self.cli = socket.create_connection((HOST, self.port), timeout=None)
2925b568aacc Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47318
diff changeset
1017 finally:
2925b568aacc Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47318
diff changeset
1018 socket.setdefaulttimeout(None)
2925b568aacc Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47318
diff changeset
1019 self.assertEqual(self.cli.gettimeout(), None)
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1020
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1021 testTimeoutValueNamed = _justAccept
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1022 def _testTimeoutValueNamed(self):
46370
2e917b0c8f6e Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46262
diff changeset
1023 self.cli = socket.create_connection((HOST, self.port), timeout=30)
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1024 self.assertEqual(self.cli.gettimeout(), 30)
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1025
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1026 testTimeoutValueNonamed = _justAccept
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1027 def _testTimeoutValueNonamed(self):
46370
2e917b0c8f6e Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46262
diff changeset
1028 self.cli = socket.create_connection((HOST, self.port), 30)
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1029 self.assertEqual(self.cli.gettimeout(), 30)
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1030
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1031 class NetworkConnectionBehaviourTest(SocketTCPTest, ThreadableTest):
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1032
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1033 def __init__(self, methodName='runTest'):
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1034 SocketTCPTest.__init__(self, methodName=methodName)
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1035 ThreadableTest.__init__(self)
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1036
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1037 def clientSetUp(self):
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1038 pass
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1039
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1040 def clientTearDown(self):
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1041 self.cli.close()
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1042 self.cli = None
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1043 ThreadableTest.clientTearDown(self)
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1044
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1045 def testInsideTimeout(self):
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1046 conn, addr = self.serv.accept()
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1047 time.sleep(3)
41809
8e062e572ea4 Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents: 41770
diff changeset
1048 conn.send(b"done!")
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1049 testOutsideTimeout = testInsideTimeout
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1050
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1051 def _testInsideTimeout(self):
46370
2e917b0c8f6e Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46262
diff changeset
1052 self.cli = sock = socket.create_connection((HOST, self.port))
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1053 data = sock.recv(5)
41809
8e062e572ea4 Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents: 41770
diff changeset
1054 self.assertEqual(data, b"done!")
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1055
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1056 def _testOutsideTimeout(self):
46370
2e917b0c8f6e Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 46262
diff changeset
1057 self.cli = sock = socket.create_connection((HOST, self.port), timeout=1)
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1058 self.failUnlessRaises(socket.timeout, lambda: sock.recv(5))
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1059
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1060
29662
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1061 class TCPTimeoutTest(SocketTCPTest):
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1062
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1063 def testTCPTimeout(self):
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1064 def raise_timeout(*args, **kwargs):
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1065 self.serv.settimeout(1.0)
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1066 self.serv.accept()
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1067 self.failUnlessRaises(socket.timeout, raise_timeout,
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1068 "Error generating a timeout exception (TCP)")
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 testTimeoutZero(self):
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1071 ok = False
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1072 try:
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1073 self.serv.settimeout(0.0)
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1074 foo = self.serv.accept()
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1075 except socket.timeout:
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1076 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
1077 except socket.error:
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1078 ok = True
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1079 except:
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1080 self.fail("caught unexpected exception (TCP)")
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1081 if not ok:
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1082 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
1083
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1084 def testInterruptedTimeout(self):
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1085 # XXX I don't know how to do this test on MSWindows or any other
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1086 # plaform that doesn't support signal.alarm() or os.kill(), though
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1087 # the bug should have existed on all platforms.
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1088 if not hasattr(signal, "alarm"):
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1089 return # can only test on *nix
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1090 self.serv.settimeout(5.0) # must be longer than alarm
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1091 class Alarm(Exception):
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1092 pass
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1093 def alarm_handler(signal, frame):
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1094 raise Alarm
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1095 old_alarm = signal.signal(signal.SIGALRM, alarm_handler)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1096 try:
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1097 signal.alarm(2) # POSIX allows alarm to be up to 1 second early
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1098 try:
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1099 foo = self.serv.accept()
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1100 except socket.timeout:
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1101 self.fail("caught timeout instead of Alarm")
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1102 except Alarm:
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1103 pass
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1104 except:
46161
848160d10780 Merged revisions 61981,61984-61987,61992-61993,61997-62000 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44782
diff changeset
1105 self.fail("caught other exception instead of Alarm:"
848160d10780 Merged revisions 61981,61984-61987,61992-61993,61997-62000 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44782
diff changeset
1106 " %s(%s):\n%s" %
848160d10780 Merged revisions 61981,61984-61987,61992-61993,61997-62000 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44782
diff changeset
1107 (sys.exc_info()[:2] + (traceback.format_exc(),)))
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1108 else:
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1109 self.fail("nothing caught")
46161
848160d10780 Merged revisions 61981,61984-61987,61992-61993,61997-62000 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44782
diff changeset
1110 finally:
848160d10780 Merged revisions 61981,61984-61987,61992-61993,61997-62000 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44782
diff changeset
1111 signal.alarm(0) # shut off alarm
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1112 except Alarm:
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1113 self.fail("got Alarm in wrong place")
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1114 finally:
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1115 # no alarm can be pending. Safe to restore old handler.
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1116 signal.signal(signal.SIGALRM, old_alarm)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1117
29662
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1118 class UDPTimeoutTest(SocketTCPTest):
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1119
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1120 def testUDPTimeout(self):
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1121 def raise_timeout(*args, **kwargs):
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1122 self.serv.settimeout(1.0)
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1123 self.serv.recv(1024)
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1124 self.failUnlessRaises(socket.timeout, raise_timeout,
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1125 "Error generating a timeout exception (UDP)")
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1126
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1127 def testTimeoutZero(self):
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1128 ok = False
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1129 try:
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1130 self.serv.settimeout(0.0)
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1131 foo = self.serv.recv(1024)
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1132 except socket.timeout:
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1133 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
1134 except socket.error:
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1135 ok = True
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1136 except:
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1137 self.fail("caught unexpected exception (UDP)")
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1138 if not ok:
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1139 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
1140
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1141 class TestExceptions(unittest.TestCase):
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1142
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1143 def testExceptionTree(self):
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1144 self.assert_(issubclass(socket.error, Exception))
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1145 self.assert_(issubclass(socket.herror, socket.error))
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1146 self.assert_(issubclass(socket.gaierror, socket.error))
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1147 self.assert_(issubclass(socket.timeout, socket.error))
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1148
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
1149 class TestLinuxAbstractNamespace(unittest.TestCase):
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
1150
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
1151 UNIX_PATH_MAX = 108
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
1152
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
1153 def testLinuxAbstractNamespace(self):
42596
980308fbda29 Down with str8!
Guido van Rossum <guido@python.org>
parents: 42434
diff changeset
1154 address = b"\x00python-test-hello\x00\xff"
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
1155 s1 = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
1156 s1.bind(address)
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
1157 s1.listen(1)
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
1158 s2 = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
1159 s2.connect(s1.getsockname())
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
1160 s1.accept()
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
1161 self.assertEqual(s1.getsockname(), address)
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
1162 self.assertEqual(s2.getpeername(), address)
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
1163
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
1164 def testMaxName(self):
42596
980308fbda29 Down with str8!
Guido van Rossum <guido@python.org>
parents: 42434
diff changeset
1165 address = b"\x00" + b"h" * (self.UNIX_PATH_MAX - 1)
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
1166 s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
1167 s.bind(address)
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
1168 self.assertEqual(s.getsockname(), address)
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
1169
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
1170 def testNameOverflow(self):
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
1171 address = "\x00" + "h" * self.UNIX_PATH_MAX
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
1172 s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
1173 self.assertRaises(socket.error, s.bind, address)
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
1174
29662
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1175
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1176 class BufferIOTest(SocketConnectedTest):
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1177 """
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1178 Test the buffer versions of socket.recv() and socket.send().
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1179 """
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1180 def __init__(self, methodName='runTest'):
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1181 SocketConnectedTest.__init__(self, methodName=methodName)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1182
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1183 def testRecvInto(self):
48623
bf50085fbcd3 #2538: bytes objects can only provide read-only buffers
Antoine Pitrou <solipsis@pitrou.net>
parents: 47615
diff changeset
1184 buf = bytearray(1024)
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1185 nbytes = self.cli_conn.recv_into(buf)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1186 self.assertEqual(nbytes, len(MSG))
41809
8e062e572ea4 Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents: 41770
diff changeset
1187 msg = buf[:len(MSG)]
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1188 self.assertEqual(msg, MSG)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1189
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1190 def _testRecvInto(self):
41770
651fa2c9c2ab Make test_socket pass. There was an unchecked error when a Unicode
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
1191 buf = bytes(MSG)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1192 self.serv_conn.send(buf)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1193
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1194 def testRecvFromInto(self):
48623
bf50085fbcd3 #2538: bytes objects can only provide read-only buffers
Antoine Pitrou <solipsis@pitrou.net>
parents: 47615
diff changeset
1195 buf = bytearray(1024)
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1196 nbytes, addr = self.cli_conn.recvfrom_into(buf)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1197 self.assertEqual(nbytes, len(MSG))
41809
8e062e572ea4 Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents: 41770
diff changeset
1198 msg = buf[:len(MSG)]
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1199 self.assertEqual(msg, MSG)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1200
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1201 def _testRecvFromInto(self):
41770
651fa2c9c2ab Make test_socket pass. There was an unchecked error when a Unicode
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
1202 buf = bytes(MSG)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1203 self.serv_conn.send(buf)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1204
44568
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1205
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1206 TIPC_STYPE = 2000
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1207 TIPC_LOWER = 200
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1208 TIPC_UPPER = 210
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1209
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1210 def isTipcAvailable():
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1211 """Check if the TIPC module is loaded
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1212
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1213 The TIPC module is not loaded automatically on Ubuntu and probably
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1214 other Linux distros.
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1215 """
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1216 if not hasattr(socket, "AF_TIPC"):
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1217 return False
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1218 if not os.path.isfile("/proc/modules"):
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1219 return False
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1220 with open("/proc/modules") as f:
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1221 for line in f:
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1222 if line.startswith("tipc "):
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1223 return True
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 46899
diff changeset
1224 if support.verbose:
44568
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1225 print("TIPC module is not loaded, please 'sudo modprobe tipc'")
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1226 return False
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1227
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1228 class TIPCTest (unittest.TestCase):
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1229 def testRDM(self):
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1230 srv = socket.socket(socket.AF_TIPC, socket.SOCK_RDM)
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1231 cli = socket.socket(socket.AF_TIPC, socket.SOCK_RDM)
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1232
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1233 srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1234 srvaddr = (socket.TIPC_ADDR_NAMESEQ, TIPC_STYPE,
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1235 TIPC_LOWER, TIPC_UPPER)
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1236 srv.bind(srvaddr)
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1237
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1238 sendaddr = (socket.TIPC_ADDR_NAME, TIPC_STYPE,
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1239 TIPC_LOWER + int((TIPC_UPPER - TIPC_LOWER) / 2), 0)
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1240 cli.sendto(MSG, sendaddr)
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1241
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1242 msg, recvaddr = srv.recvfrom(1024)
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1243
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1244 self.assertEqual(cli.getsockname(), recvaddr)
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1245 self.assertEqual(msg, MSG)
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1246
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1247
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1248 class TIPCThreadableTest (unittest.TestCase, ThreadableTest):
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1249 def __init__(self, methodName = 'runTest'):
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1250 unittest.TestCase.__init__(self, methodName = methodName)
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1251 ThreadableTest.__init__(self)
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1252
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1253 def setUp(self):
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1254 self.srv = socket.socket(socket.AF_TIPC, socket.SOCK_STREAM)
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1255 self.srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1256 srvaddr = (socket.TIPC_ADDR_NAMESEQ, TIPC_STYPE,
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1257 TIPC_LOWER, TIPC_UPPER)
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1258 self.srv.bind(srvaddr)
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1259 self.srv.listen(5)
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1260 self.serverExplicitReady()
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1261 self.conn, self.connaddr = self.srv.accept()
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1262
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1263 def clientSetUp(self):
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1264 # The is a hittable race between serverExplicitReady() and the
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1265 # accept() call; sleep a little while to avoid it, otherwise
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1266 # we could get an exception
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1267 time.sleep(0.1)
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1268 self.cli = socket.socket(socket.AF_TIPC, socket.SOCK_STREAM)
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1269 addr = (socket.TIPC_ADDR_NAME, TIPC_STYPE,
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1270 TIPC_LOWER + int((TIPC_UPPER - TIPC_LOWER) / 2), 0)
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1271 self.cli.connect(addr)
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1272 self.cliaddr = self.cli.getsockname()
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1273
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1274 def testStream(self):
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1275 msg = self.conn.recv(1024)
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1276 self.assertEqual(msg, MSG)
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1277 self.assertEqual(self.cliaddr, self.connaddr)
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1278
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1279 def _testStream(self):
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1280 self.cli.send(MSG)
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1281 self.cli.close()
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1282
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1283
24451
22570e76cca1 Enable test_socket again, if only to prevent mistakes like Jeremy
Guido van Rossum <guido@python.org>
parents: 24450
diff changeset
1284 def test_main():
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1285 tests = [GeneralModuleTests, BasicTCPTest, TCPCloserTest, TCPTimeoutTest,
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1286 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
1287 if sys.platform != 'mac':
29662
1308d7ec9953 SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents: 29087
diff changeset
1288 tests.extend([ BasicUDPTest, UDPTimeoutTest ])
28917
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28833
diff changeset
1289
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28833
diff changeset
1290 tests.extend([
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28833
diff changeset
1291 NonBlockingTCPTests,
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28833
diff changeset
1292 FileObjectClassTestCase,
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28833
diff changeset
1293 UnbufferedFileObjectClassTestCase,
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28833
diff changeset
1294 LineBufferedFileObjectClassTestCase,
40737
6ebad2a6b990 Merged revisions 53451-53537 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40644
diff changeset
1295 SmallBufferedFileObjectClassTestCase,
41554
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1296 NetworkConnectionNoServer,
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1297 NetworkConnectionAttributesTest,
06145fbc7ab9 Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40737
diff changeset
1298 NetworkConnectionBehaviourTest,
28917
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 28833
diff changeset
1299 ])
33063
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
1300 if hasattr(socket, "socketpair"):
90da70986407 Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents: 32630
diff changeset
1301 tests.append(BasicSocketPairTest)
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
1302 if sys.platform == 'linux2':
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35453
diff changeset
1303 tests.append(TestLinuxAbstractNamespace)
44568
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1304 if isTipcAvailable():
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
1305 tests.append(TIPCTest)
44587
fb5a6330f71b Merged revisions 59822-59841 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44568
diff changeset
1306 tests.append(TIPCThreadableTest)
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
1307
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 46899
diff changeset
1308 thread_info = support.threading_setup()
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 46899
diff changeset
1309 support.run_unittest(*tests)
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 46899
diff changeset
1310 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
1311
486f4045d13d New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents: 23715
diff changeset
1312 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
1313 test_main()