Python/CloseTestPong.py
author morrowa
Thu Jul 02 19:58:11 2009 -0700 (2009-07-02)
changeset 56 6c3b5372a307
parent 51 de59ce19f42e
permissions -rw-r--r--
Removed unnecessary files. Toned down logging. Added null logging handler to BLIP so client code doesn't have to use logging. Modified test drivers to work against Cocoa versions.
     1 # CloseTestPong.py
     2 # Tests the closing negotiation facilities of the BLIP 1.1 protocol
     3 
     4 from BLIP import Listener
     5 
     6 import logging
     7 import asyncore
     8 import unittest
     9 
    10 class CloseTestPong(unittest.TestCase):
    11     
    12     def shouldClose(self):
    13         logging.info("Allowed to close.")
    14         return True
    15     
    16     def handleConnection(self, conn):
    17         logging.info("Accepted connection.")
    18         conn.onCloseRequest = self.shouldClose
    19     
    20     def handleRequest(self, req):
    21         resp = req.response
    22         resp.body = "Pong"
    23         resp.send()
    24     
    25     def testClose(self):
    26         listen = Listener(1337)
    27         listen.onConnected = self.handleConnection
    28         listen.onRequest = self.handleRequest
    29         
    30         try:
    31             asyncore.loop()
    32         except KeyboardInterrupt:
    33             pass
    34 
    35 
    36 if __name__ == '__main__':
    37     logging.basicConfig(level=logging.INFO)
    38     unittest.main()