Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
test.test_socket.UnbufferedFileObjectClassTestCase Class Reference
Inheritance diagram for test.test_socket.UnbufferedFileObjectClassTestCase:
Inheritance graph
[legend]
Collaboration diagram for test.test_socket.UnbufferedFileObjectClassTestCase:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def testUnbufferedReadline
def testMakefileClose
def testMakefileCloseSocketDestroy
def testSmallReadNonBlocking
def testWriteNonBlocking
def setUp
def tearDown
def clientSetUp
def clientTearDown
def testReadAfterTimeout
def testSmallRead
def testFullRead
def testUnbufferedRead
def testReadline
def testCloseAfterMakefile
def testMakefileAfterMakefileClose
def testClosedAttr
def testAttributes
def testRealClose
def serverExplicitReady
def clientRun

Public Attributes

 read_file
 serv_skipped
 cli_finished
 write_file
 setUp
 tearDown
 cli_conn
 serv_conn
 cli
 serv
 port
 server_ready
 client_ready
 done
 queue
 client_thread

Static Public Attributes

int bufsize = 0
string encoding = 'utf8'
string errors = 'strict'
 newline = None
string read_mode = 'rb'
 read_msg = MSG
string write_mode = 'wb'
 write_msg = MSG

Private Member Functions

def _testUnbufferedReadline
def _testMakefileClose
def _testMakefileCloseSocketDestroy
def _testSmallReadNonBlocking
def _testWriteNonBlocking

Detailed Description

Repeat the tests from FileObjectClassTestCase with bufsize==0.

In this case (and in this case only), it should be possible to
create a file object, read a line from it, create another file
object, read another line from it, without loss of data in the
first file object's buffer.  Note that http.client relies on this
when reading multiple requests from the same socket.

Definition at line 1366 of file test_socket.py.


Member Function Documentation

Definition at line 1400 of file test_socket.py.

01400 
01401     def _testMakefileClose(self):
01402         self.write_file.write(self.write_msg)
01403         self.write_file.flush()

Definition at line 1410 of file test_socket.py.

01410 
01411     def _testMakefileCloseSocketDestroy(self):
01412         pass

Definition at line 1436 of file test_socket.py.

01436 
01437     def _testSmallReadNonBlocking(self):
01438         self.evt1.wait(1.0)
01439         self.write_file.write(self.write_msg)
01440         self.write_file.flush()
01441         self.evt2.set()
01442         # Avoid cloding the socket before the server test has finished,
01443         # otherwise system recv() will return 0 instead of EWOULDBLOCK.
01444         self.serv_finished.wait(5.0)

Definition at line 1386 of file test_socket.py.

01386 
01387     def _testUnbufferedReadline(self):
01388         self.write_file.write(b"A. " + self.write_msg)
01389         self.write_file.write(b"B. " + self.write_msg)
01390         self.write_file.flush()

Definition at line 1452 of file test_socket.py.

01452 
01453     def _testWriteNonBlocking(self):
01454         self.serv_skipped = None
01455         self.serv_conn.setblocking(False)
01456         # Try to saturate the socket buffer pipe with repeated large writes.
01457         BIG = b"x" * (1024 ** 2)
01458         LIMIT = 10
01459         # The first write() succeeds since a chunk of data can be buffered
01460         n = self.write_file.write(BIG)
01461         self.assertGreater(n, 0)
01462         for i in range(LIMIT):
01463             n = self.write_file.write(BIG)
01464             if n is None:
01465                 # Succeeded
01466                 break
01467             self.assertGreater(n, 0)
01468         else:
01469             # Let us know that this test didn't manage to establish
01470             # the expected conditions. This is not a failure in itself but,
01471             # if it happens repeatedly, the test should be fixed.
01472             self.serv_skipped = "failed to saturate the socket buffer"
01473 

def test.test_socket.ThreadableTest.clientRun (   self,
  test_func 
) [inherited]

Definition at line 157 of file test_socket.py.

00157 
00158     def clientRun(self, test_func):
00159         self.server_ready.wait()
00160         self.client_ready.set()
00161         self.clientSetUp()
00162         if not hasattr(test_func, '__call__'):
00163             raise TypeError("test_func must be a callable function")
00164         try:
00165             test_func()
00166         except BaseException as e:
00167             self.queue.put(e)
00168         finally:
00169             self.clientTearDown()

Here is the call graph for this function:

Reimplemented from test.test_socket.SocketConnectedTest.

Definition at line 1134 of file test_socket.py.

01134 
01135     def clientSetUp(self):
01136         SocketConnectedTest.clientSetUp(self)
01137         self.write_file = self.serv_conn.makefile(
01138             self.write_mode, self.bufsize,
01139             encoding = self.encoding,
01140             errors = self.errors,
01141             newline = self.newline)

Reimplemented from test.test_socket.SocketConnectedTest.

Definition at line 1142 of file test_socket.py.

01142 
01143     def clientTearDown(self):
01144         self.cli_finished.set()
01145         self.write_file.close()
01146         self.assertTrue(self.write_file.closed)
01147         self.write_file = None
01148         SocketConnectedTest.clientTearDown(self)

Here is the call graph for this function:

This method allows the server to explicitly indicate that
it wants the client thread to proceed. This is useful if the
server is about to execute a blocking routine that is
dependent upon the client thread during its setup routine.

Definition at line 123 of file test_socket.py.

00123 
00124     def serverExplicitReady(self):
00125         """This method allows the server to explicitly indicate that
00126         it wants the client thread to proceed. This is useful if the
00127         server is about to execute a blocking routine that is
00128         dependent upon the client thread during its setup routine."""
00129         self.server_ready.set()

Here is the caller graph for this function:

Reimplemented from test.test_socket.SocketConnectedTest.

Definition at line 1117 of file test_socket.py.

01117 
01118     def setUp(self):
01119         self.evt1, self.evt2, self.serv_finished, self.cli_finished = [
01120             threading.Event() for i in range(4)]
01121         SocketConnectedTest.setUp(self)
01122         self.read_file = self.cli_conn.makefile(
01123             self.read_mode, self.bufsize,
01124             encoding = self.encoding,
01125             errors = self.errors,
01126             newline = self.newline)

Here is the caller graph for this function:

Reimplemented from test.test_socket.SocketConnectedTest.

Definition at line 1127 of file test_socket.py.

01127 
01128     def tearDown(self):
01129         self.serv_finished.set()
01130         self.read_file.close()
01131         self.assertTrue(self.read_file.closed)
01132         self.read_file = None
01133         SocketConnectedTest.tearDown(self)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1237 of file test_socket.py.

01237 
01238     def testAttributes(self):
01239         self.assertEqual(self.read_file.mode, self.read_mode)
01240         self.assertEqual(self.read_file.name, self.cli_conn.fileno())

Here is the call graph for this function:

Definition at line 1209 of file test_socket.py.

01209 
01210     def testCloseAfterMakefile(self):
01211         # The file returned by makefile should keep the socket open.
01212         self.cli_conn.close()
01213         # read until EOF
01214         msg = self.read_file.read()
01215         self.assertEqual(msg, self.read_msg)

Here is the call graph for this function:

Definition at line 1231 of file test_socket.py.

01231 
01232     def testClosedAttr(self):
01233         self.assertTrue(not self.read_file.closed)

Here is the call graph for this function:

Definition at line 1177 of file test_socket.py.

01177 
01178     def testFullRead(self):
01179         # read until EOF
01180         msg = self.read_file.read()
01181         self.assertEqual(msg, self.read_msg)

Here is the call graph for this function:

Definition at line 1220 of file test_socket.py.

01220 
01221     def testMakefileAfterMakefileClose(self):
01222         self.read_file.close()
01223         msg = self.cli_conn.recv(len(MSG))
01224         if isinstance(self.read_msg, str):
01225             msg = msg.decode()
01226         self.assertEqual(msg, self.read_msg)

Here is the call graph for this function:

Definition at line 1391 of file test_socket.py.

01391 
01392     def testMakefileClose(self):
01393         # The file returned by makefile should keep the socket open...
01394         self.cli_conn.close()
01395         msg = self.cli_conn.recv(1024)
01396         self.assertEqual(msg, self.read_msg)
01397         # ...until the file is itself closed
01398         self.read_file.close()
01399         self.assertRaises(socket.error, self.cli_conn.recv, 1024)

Here is the call graph for this function:

Definition at line 1404 of file test_socket.py.

01404 
01405     def testMakefileCloseSocketDestroy(self):
01406         refcount_before = sys.getrefcount(self.cli_conn)
01407         self.read_file.close()
01408         refcount_after = sys.getrefcount(self.cli_conn)
01409         self.assertEqual(refcount_before - 1, refcount_after)

Here is the call graph for this function:

Definition at line 1149 of file test_socket.py.

01149 
01150     def testReadAfterTimeout(self):
01151         # Issue #7322: A file object must disallow further reads
01152         # after a timeout has occurred.
01153         self.cli_conn.settimeout(1)
01154         self.read_file.read(3)
01155         # First read raises a timeout
01156         self.assertRaises(socket.timeout, self.read_file.read, 1)
01157         # Second read is disallowed
01158         with self.assertRaises(IOError) as ctx:
01159             self.read_file.read(1)
01160         self.assertIn("cannot read from timed out object", str(ctx.exception))

Here is the call graph for this function:

Definition at line 1200 of file test_socket.py.

01200 
01201     def testReadline(self):
01202         # Performing file readline test
01203         line = self.read_file.readline()
01204         self.assertEqual(line, self.read_msg)

Here is the call graph for this function:

Definition at line 1245 of file test_socket.py.

01245 
01246     def testRealClose(self):
01247         self.read_file.close()
01248         self.assertRaises(ValueError, self.read_file.fileno)
01249         self.cli_conn.close()
01250         self.assertRaises(socket.error, self.cli_conn.getsockname)

Here is the call graph for this function:

Definition at line 1166 of file test_socket.py.

01166 
01167     def testSmallRead(self):
01168         # Performing small file read test
01169         first_seg = self.read_file.read(len(self.read_msg)-3)
01170         second_seg = self.read_file.read(3)
01171         msg = first_seg + second_seg
01172         self.assertEqual(msg, self.read_msg)

Here is the call graph for this function:

Definition at line 1417 of file test_socket.py.

01417 
01418     def testSmallReadNonBlocking(self):
01419         self.cli_conn.setblocking(False)
01420         self.assertEqual(self.read_file.readinto(bytearray(10)), None)
01421         self.assertEqual(self.read_file.read(len(self.read_msg) - 3), None)
01422         self.evt1.set()
01423         self.evt2.wait(1.0)
01424         first_seg = self.read_file.read(len(self.read_msg) - 3)
01425         if first_seg is None:
01426             # Data not arrived (can happen under Windows), wait a bit
01427             time.sleep(0.5)
01428             first_seg = self.read_file.read(len(self.read_msg) - 3)
01429         buf = bytearray(10)
01430         n = self.read_file.readinto(buf)
01431         self.assertEqual(n, 3)
01432         msg = first_seg + buf[:n]
01433         self.assertEqual(msg, self.read_msg)
01434         self.assertEqual(self.read_file.readinto(bytearray(16)), None)
01435         self.assertEqual(self.read_file.read(1), None)

Here is the call graph for this function:

Definition at line 1186 of file test_socket.py.

01186 
01187     def testUnbufferedRead(self):
01188         # Performing unbuffered file read test
01189         buf = type(self.read_msg)()
01190         while 1:
01191             char = self.read_file.read(1)
01192             if not char:
01193                 break
01194             buf += char
01195         self.assertEqual(buf, self.read_msg)

Here is the call graph for this function:

Definition at line 1378 of file test_socket.py.

01378 
01379     def testUnbufferedReadline(self):
01380         # Read a line, create a new file object, read another line with it
01381         line = self.read_file.readline() # first line
01382         self.assertEqual(line, b"A. " + self.write_msg) # first line
01383         self.read_file = self.cli_conn.makefile('rb', 0)
01384         line = self.read_file.readline() # second line
01385         self.assertEqual(line, b"B. " + self.write_msg) # second line

Here is the call graph for this function:

Definition at line 1445 of file test_socket.py.

01445 
01446     def testWriteNonBlocking(self):
01447         self.cli_finished.wait(5.0)
01448         # The client thread can't skip directly - the SkipTest exception
01449         # would appear as a failure.
01450         if self.serv_skipped:
01451             self.skipTest(self.serv_skipped)

Here is the call graph for this function:


Member Data Documentation

Reimplemented from test.test_socket.FileObjectClassTestCase.

Definition at line 1376 of file test_socket.py.

Definition at line 184 of file test_socket.py.

Definition at line 221 of file test_socket.py.

Definition at line 1118 of file test_socket.py.

Definition at line 132 of file test_socket.py.

Definition at line 141 of file test_socket.py.

Definition at line 133 of file test_socket.py.

Definition at line 1105 of file test_socket.py.

Definition at line 1106 of file test_socket.py.

Reimplemented in test.test_socket.NonBlockingTCPTests.

Definition at line 61 of file test_socket.py.

Definition at line 134 of file test_socket.py.

Reimplemented from test.test_socket.FileObjectClassTestCase.

Definition at line 1382 of file test_socket.py.

Reimplemented in test.test_socket.NonBlockingTCPTests.

Definition at line 60 of file test_socket.py.

Definition at line 231 of file test_socket.py.

Definition at line 1453 of file test_socket.py.

Definition at line 131 of file test_socket.py.

Definition at line 120 of file test_socket.py.

Definition at line 121 of file test_socket.py.

Definition at line 1136 of file test_socket.py.


The documentation for this class was generated from the following file: