Back to index

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

List of all members.

Public Member Functions

def testTCPTimeout
def testTimeoutZero
def testInterruptedTimeout
def setUp
def tearDown

Public Attributes

 serv
 port

Detailed Description

Definition at line 1668 of file test_socket.py.


Member Function Documentation

def test.test_socket.SocketTCPTest.setUp (   self) [inherited]

Reimplemented in test.test_socket.FileObjectClassTestCase, and test.test_socket.SocketConnectedTest.

Definition at line 59 of file test_socket.py.

00059 
00060     def setUp(self):
00061         self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
00062         self.port = support.bind_port(self.serv)
00063         self.serv.listen(1)

Here is the caller graph for this function:

def test.test_socket.SocketTCPTest.tearDown (   self) [inherited]

Reimplemented in test.test_socket.FileObjectClassTestCase, and test.test_socket.SocketConnectedTest.

Definition at line 64 of file test_socket.py.

00064 
00065     def tearDown(self):
00066         self.serv.close()
00067         self.serv = None

Here is the caller graph for this function:

Definition at line 1691 of file test_socket.py.

01691 
01692     def testInterruptedTimeout(self):
01693         # XXX I don't know how to do this test on MSWindows or any other
01694         # plaform that doesn't support signal.alarm() or os.kill(), though
01695         # the bug should have existed on all platforms.
01696         if not hasattr(signal, "alarm"):
01697             return                  # can only test on *nix
01698         self.serv.settimeout(5.0)   # must be longer than alarm
01699         class Alarm(Exception):
01700             pass
01701         def alarm_handler(signal, frame):
01702             raise Alarm
01703         old_alarm = signal.signal(signal.SIGALRM, alarm_handler)
01704         try:
01705             signal.alarm(2)    # POSIX allows alarm to be up to 1 second early
01706             try:
01707                 foo = self.serv.accept()
01708             except socket.timeout:
01709                 self.fail("caught timeout instead of Alarm")
01710             except Alarm:
01711                 pass
01712             except:
01713                 self.fail("caught other exception instead of Alarm:"
01714                           " %s(%s):\n%s" %
01715                           (sys.exc_info()[:2] + (traceback.format_exc(),)))
01716             else:
01717                 self.fail("nothing caught")
01718             finally:
01719                 signal.alarm(0)         # shut off alarm
01720         except Alarm:
01721             self.fail("got Alarm in wrong place")
01722         finally:
01723             # no alarm can be pending.  Safe to restore old handler.
01724             signal.signal(signal.SIGALRM, old_alarm)

Definition at line 1670 of file test_socket.py.

01670 
01671     def testTCPTimeout(self):
01672         def raise_timeout(*args, **kwargs):
01673             self.serv.settimeout(1.0)
01674             self.serv.accept()
01675         self.assertRaises(socket.timeout, raise_timeout,
01676                               "Error generating a timeout exception (TCP)")

Here is the call graph for this function:

Definition at line 1677 of file test_socket.py.

01677 
01678     def testTimeoutZero(self):
01679         ok = False
01680         try:
01681             self.serv.settimeout(0.0)
01682             foo = self.serv.accept()
01683         except socket.timeout:
01684             self.fail("caught timeout instead of error (TCP)")
01685         except socket.error:
01686             ok = True
01687         except:
01688             self.fail("caught unexpected exception (TCP)")
01689         if not ok:
01690             self.fail("accept() returned success when we did not expect it")

Here is the call graph for this function:


Member Data Documentation

Reimplemented in test.test_socket.NonBlockingTCPTests.

Definition at line 61 of file test_socket.py.

Reimplemented in test.test_socket.NonBlockingTCPTests.

Definition at line 60 of file test_socket.py.


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