Back to index

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

List of all members.

Public Member Functions

def tearDown
def loop_waiting_for_flag
def test_handle_connect
def test_handle_accept
def test_handle_accepted
def test_handle_read
def test_handle_write
def test_handle_close
def test_handle_expt
def test_handle_error
def test_connection_attributes
def test_create_socket
def test_bind
def test_set_reuse_addr

Public Attributes

 flag
 address

Static Public Attributes

 use_poll = False

Detailed Description

Definition at line 734 of file test_asyncore.py.


Member Function Documentation

def test.test_asyncore.BaseTestAPI.loop_waiting_for_flag (   self,
  instance,
  timeout = 5 
) [inherited]

Definition at line 510 of file test_asyncore.py.

00510 
00511     def loop_waiting_for_flag(self, instance, timeout=5):
00512         timeout = float(timeout) / 100
00513         count = 100
00514         while asyncore.socket_map and count > 0:
00515             asyncore.loop(timeout=0.01, count=1, use_poll=self.use_poll)
00516             if instance.flag:
00517                 return
00518             count -= 1
00519             time.sleep(timeout)
00520         self.fail("flag not set")

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_asyncore.BaseTestAPI.tearDown (   self) [inherited]

Definition at line 507 of file test_asyncore.py.

00507 
00508     def tearDown(self):
00509         asyncore.close_all()

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_asyncore.BaseTestAPI.test_bind (   self) [inherited]

Definition at line 701 of file test_asyncore.py.

00701 
00702     def test_bind(self):
00703         s1 = asyncore.dispatcher()
00704         s1.create_socket(socket.AF_INET, socket.SOCK_STREAM)
00705         s1.bind((HOST, 0))
00706         s1.listen(5)
00707         port = s1.socket.getsockname()[1]
00708 
00709         s2 = asyncore.dispatcher()
00710         s2.create_socket(socket.AF_INET, socket.SOCK_STREAM)
00711         # EADDRINUSE indicates the socket was correctly bound
00712         self.assertRaises(socket.error, s2.bind, (HOST, port))

Here is the call graph for this function:

Definition at line 664 of file test_asyncore.py.

00664 
00665     def test_connection_attributes(self):
00666         server = TCPServer()
00667         client = BaseClient(server.address)
00668 
00669         # we start disconnected
00670         self.assertFalse(server.connected)
00671         self.assertTrue(server.accepting)
00672         # this can't be taken for granted across all platforms
00673         #self.assertFalse(client.connected)
00674         self.assertFalse(client.accepting)
00675 
00676         # execute some loops so that client connects to server
00677         asyncore.loop(timeout=0.01, use_poll=self.use_poll, count=100)
00678         self.assertFalse(server.connected)
00679         self.assertTrue(server.accepting)
00680         self.assertTrue(client.connected)
00681         self.assertFalse(client.accepting)
00682 
00683         # disconnect the client
00684         client.close()
00685         self.assertFalse(server.connected)
00686         self.assertTrue(server.accepting)
00687         self.assertFalse(client.connected)
00688         self.assertFalse(client.accepting)
00689 
00690         # stop serving
00691         server.close()
00692         self.assertFalse(server.connected)
00693         self.assertFalse(server.accepting)

Here is the call graph for this function:

Definition at line 694 of file test_asyncore.py.

00694 
00695     def test_create_socket(self):
00696         s = asyncore.dispatcher()
00697         s.create_socket(socket.AF_INET, socket.SOCK_STREAM)
00698         self.assertEqual(s.socket.family, socket.AF_INET)
00699         SOCK_NONBLOCK = getattr(socket, 'SOCK_NONBLOCK', 0)
00700         self.assertEqual(s.socket.type, socket.SOCK_STREAM | SOCK_NONBLOCK)

Here is the call graph for this function:

Definition at line 532 of file test_asyncore.py.

00532 
00533     def test_handle_accept(self):
00534         # make sure handle_accept() is called when a client connects
00535 
00536         class TestListener(BaseTestHandler):
00537 
00538             def __init__(self):
00539                 BaseTestHandler.__init__(self)
00540                 self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
00541                 self.bind((HOST, 0))
00542                 self.listen(5)
00543                 self.address = self.socket.getsockname()[:2]
00544 
00545             def handle_accept(self):
00546                 self.flag = True
00547 
00548         server = TestListener()
00549         client = BaseClient(server.address)
00550         self.loop_waiting_for_flag(server)

Here is the call graph for this function:

Definition at line 551 of file test_asyncore.py.

00551 
00552     def test_handle_accepted(self):
00553         # make sure handle_accepted() is called when a client connects
00554 
00555         class TestListener(BaseTestHandler):
00556 
00557             def __init__(self):
00558                 BaseTestHandler.__init__(self)
00559                 self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
00560                 self.bind((HOST, 0))
00561                 self.listen(5)
00562                 self.address = self.socket.getsockname()[:2]
00563 
00564             def handle_accept(self):
00565                 asyncore.dispatcher.handle_accept(self)
00566 
00567             def handle_accepted(self, sock, addr):
00568                 sock.close()
00569                 self.flag = True
00570 
00571         server = TestListener()
00572         client = BaseClient(server.address)
00573         self.loop_waiting_for_flag(server)
00574 

Here is the call graph for this function:

Definition at line 602 of file test_asyncore.py.

00602 
00603     def test_handle_close(self):
00604         # make sure handle_close is called when the other end closes
00605         # the connection
00606 
00607         class TestClient(BaseClient):
00608 
00609             def handle_read(self):
00610                 # in order to make handle_close be called we are supposed
00611                 # to make at least one recv() call
00612                 self.recv(1024)
00613 
00614             def handle_close(self):
00615                 self.flag = True
00616                 self.close()
00617 
00618         class TestHandler(BaseTestHandler):
00619             def __init__(self, conn):
00620                 BaseTestHandler.__init__(self, conn)
00621                 self.close()
00622 
00623         server = TCPServer(TestHandler)
00624         client = TestClient(server.address)
00625         self.loop_waiting_for_flag(client)

Definition at line 521 of file test_asyncore.py.

00521 
00522     def test_handle_connect(self):
00523         # make sure handle_connect is called on connect()
00524 
00525         class TestClient(BaseClient):
00526             def handle_connect(self):
00527                 self.flag = True
00528 
00529         server = TCPServer()
00530         client = TestClient(server.address)
00531         self.loop_waiting_for_flag(client)

Here is the call graph for this function:

Definition at line 646 of file test_asyncore.py.

00646 
00647     def test_handle_error(self):
00648 
00649         class TestClient(BaseClient):
00650             def handle_write(self):
00651                 1.0 / 0
00652             def handle_error(self):
00653                 self.flag = True
00654                 try:
00655                     raise
00656                 except ZeroDivisionError:
00657                     pass
00658                 else:
00659                     raise Exception("exception not raised")
00660 
00661         server = TCPServer()
00662         client = TestClient(server.address)
00663         self.loop_waiting_for_flag(client)

Here is the call graph for this function:

Definition at line 628 of file test_asyncore.py.

00628 
00629     def test_handle_expt(self):
00630         # Make sure handle_expt is called on OOB data received.
00631         # Note: this might fail on some platforms as OOB data is
00632         # tenuously supported and rarely used.
00633 
00634         class TestClient(BaseClient):
00635             def handle_expt(self):
00636                 self.flag = True
00637 
00638         class TestHandler(BaseTestHandler):
00639             def __init__(self, conn):
00640                 BaseTestHandler.__init__(self, conn)
00641                 self.socket.send(bytes(chr(244), 'latin-1'), socket.MSG_OOB)
00642 
00643         server = TCPServer(TestHandler)
00644         client = TestClient(server.address)
00645         self.loop_waiting_for_flag(client)

Here is the call graph for this function:

Definition at line 575 of file test_asyncore.py.

00575 
00576     def test_handle_read(self):
00577         # make sure handle_read is called on data received
00578 
00579         class TestClient(BaseClient):
00580             def handle_read(self):
00581                 self.flag = True
00582 
00583         class TestHandler(BaseTestHandler):
00584             def __init__(self, conn):
00585                 BaseTestHandler.__init__(self, conn)
00586                 self.send(b'x' * 1024)
00587 
00588         server = TCPServer(TestHandler)
00589         client = TestClient(server.address)
00590         self.loop_waiting_for_flag(client)

Here is the call graph for this function:

Definition at line 591 of file test_asyncore.py.

00591 
00592     def test_handle_write(self):
00593         # make sure handle_write is called
00594 
00595         class TestClient(BaseClient):
00596             def handle_write(self):
00597                 self.flag = True
00598 
00599         server = TCPServer()
00600         client = TestClient(server.address)
00601         self.loop_waiting_for_flag(client)

Here is the call graph for this function:

Definition at line 713 of file test_asyncore.py.

00713 
00714     def test_set_reuse_addr(self):
00715         sock = socket.socket()
00716         try:
00717             sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
00718         except socket.error:
00719             unittest.skip("SO_REUSEADDR not supported on this platform")
00720         else:
00721             # if SO_REUSEADDR succeeded for sock we expect asyncore
00722             # to do the same
00723             s = asyncore.dispatcher(socket.socket())
00724             self.assertFalse(s.socket.getsockopt(socket.SOL_SOCKET,
00725                                                  socket.SO_REUSEADDR))
00726             s.socket.close()
00727             s.create_socket(socket.AF_INET, socket.SOCK_STREAM)
00728             s.set_reuse_addr()
00729             self.assertTrue(s.socket.getsockopt(socket.SOL_SOCKET,
00730                                                  socket.SO_REUSEADDR))
00731         finally:
00732             sock.close()
00733 

Here is the call graph for this function:


Member Data Documentation

Definition at line 542 of file test_asyncore.py.

Definition at line 526 of file test_asyncore.py.

Definition at line 735 of file test_asyncore.py.


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