1818from test .support import os_helper
1919from test .support import socket_helper
2020from test .support import threading_helper
21+ from test .support import ALWAYS_EQ , LARGEST , SMALLEST
2122
2223try :
2324 import gzip
@@ -559,14 +560,10 @@ def test_comparison(self):
559560 # some other types
560561 dbytes = dstr .encode ('ascii' )
561562 dtuple = now .timetuple ()
562- with self .assertRaises (TypeError ):
563- dtime == 1970
564- with self .assertRaises (TypeError ):
565- dtime != dbytes
566- with self .assertRaises (TypeError ):
567- dtime == bytearray (dbytes )
568- with self .assertRaises (TypeError ):
569- dtime != dtuple
563+ self .assertFalse (dtime == 1970 )
564+ self .assertTrue (dtime != dbytes )
565+ self .assertFalse (dtime == bytearray (dbytes ))
566+ self .assertTrue (dtime != dtuple )
570567 with self .assertRaises (TypeError ):
571568 dtime < float (1970 )
572569 with self .assertRaises (TypeError ):
@@ -576,9 +573,21 @@ def test_comparison(self):
576573 with self .assertRaises (TypeError ):
577574 dtime >= dtuple
578575
576+ self .assertTrue (dtime == ALWAYS_EQ )
577+ self .assertFalse (dtime != ALWAYS_EQ )
578+ self .assertTrue (dtime < LARGEST )
579+ self .assertFalse (dtime > LARGEST )
580+ self .assertTrue (dtime <= LARGEST )
581+ self .assertFalse (dtime >= LARGEST )
582+ self .assertFalse (dtime < SMALLEST )
583+ self .assertTrue (dtime > SMALLEST )
584+ self .assertFalse (dtime <= SMALLEST )
585+ self .assertTrue (dtime >= SMALLEST )
586+
587+
579588class BinaryTestCase (unittest .TestCase ):
580589
581- # XXX What should str(Binary(b"\xff")) return? I'm chosing "\xff"
590+ # XXX What should str(Binary(b"\xff")) return? I'm choosing "\xff"
582591 # for now (i.e. interpreting the binary data as Latin-1-encoded
583592 # text). But this feels very unsatisfactory. Perhaps we should
584593 # only define repr(), and return r"Binary(b'\xff')" instead?
@@ -665,7 +674,7 @@ def _(x, y):
665674 serv .handle_request ()
666675 numrequests -= 1
667676
668- except socket . timeout :
677+ except TimeoutError :
669678 pass
670679 finally :
671680 serv .socket .close ()
@@ -715,11 +724,16 @@ def _marshaled_dispatch(self, data, dispatch_method=None, path=None):
715724 #on AF_INET only.
716725 URL = "http://%s:%d" % (ADDR , PORT )
717726 serv .server_activate ()
718- paths = ["/foo" , "/foo/bar" ]
727+ paths = [
728+ "/foo" , "/foo/bar" ,
729+ "/foo?k=v" , "/foo#frag" , "/foo?k=v#frag" ,
730+ "" , "/" , "/RPC2" , "?k=v" , "#frag" ,
731+ ]
719732 for path in paths :
720733 d = serv .add_dispatcher (path , xmlrpc .server .SimpleXMLRPCDispatcher ())
721734 d .register_introspection_functions ()
722735 d .register_multicall_functions ()
736+ d .register_function (lambda p = path : p , 'test' )
723737 serv .get_dispatcher (paths [0 ]).register_function (pow )
724738 serv .get_dispatcher (paths [1 ]).register_function (lambda x ,y : x + y , 'add' )
725739 serv .add_dispatcher ("/is/broken" , BrokenDispatcher ())
@@ -730,7 +744,7 @@ def _marshaled_dispatch(self, data, dispatch_method=None, path=None):
730744 serv .handle_request ()
731745 numrequests -= 1
732746
733- except socket . timeout :
747+ except TimeoutError :
734748 pass
735749 finally :
736750 serv .socket .close ()
@@ -1073,6 +1087,39 @@ def test_path3(self):
10731087 p = xmlrpclib .ServerProxy (URL + "/is/broken" )
10741088 self .assertRaises (xmlrpclib .Fault , p .add , 6 , 8 )
10751089
1090+ def test_invalid_path (self ):
1091+ p = xmlrpclib .ServerProxy (URL + "/invalid" )
1092+ self .assertRaises (xmlrpclib .Fault , p .add , 6 , 8 )
1093+
1094+ def test_path_query_fragment (self ):
1095+ p = xmlrpclib .ServerProxy (URL + "/foo?k=v#frag" )
1096+ self .assertEqual (p .test (), "/foo?k=v#frag" )
1097+
1098+ def test_path_fragment (self ):
1099+ p = xmlrpclib .ServerProxy (URL + "/foo#frag" )
1100+ self .assertEqual (p .test (), "/foo#frag" )
1101+
1102+ def test_path_query (self ):
1103+ p = xmlrpclib .ServerProxy (URL + "/foo?k=v" )
1104+ self .assertEqual (p .test (), "/foo?k=v" )
1105+
1106+ def test_empty_path (self ):
1107+ p = xmlrpclib .ServerProxy (URL )
1108+ self .assertEqual (p .test (), "/RPC2" )
1109+
1110+ def test_root_path (self ):
1111+ p = xmlrpclib .ServerProxy (URL + "/" )
1112+ self .assertEqual (p .test (), "/" )
1113+
1114+ def test_empty_path_query (self ):
1115+ p = xmlrpclib .ServerProxy (URL + "?k=v" )
1116+ self .assertEqual (p .test (), "?k=v" )
1117+
1118+ def test_empty_path_fragment (self ):
1119+ p = xmlrpclib .ServerProxy (URL + "#frag" )
1120+ self .assertEqual (p .test (), "#frag" )
1121+
1122+
10761123#A test case that verifies that a server using the HTTP/1.1 keep-alive mechanism
10771124#does indeed serve subsequent requests on the same connection
10781125class BaseKeepaliveServerTestCase (BaseServerTestCase ):
@@ -1544,16 +1591,10 @@ def test_xmlrpcserver_has_use_builtin_types_flag(self):
15441591 self .assertTrue (server .use_builtin_types )
15451592
15461593
1547- @threading_helper .reap_threads
1548- def test_main ():
1549- support .run_unittest (XMLRPCTestCase , HelperTestCase , DateTimeTestCase ,
1550- BinaryTestCase , FaultTestCase , UseBuiltinTypesTestCase ,
1551- SimpleServerTestCase , SimpleServerEncodingTestCase ,
1552- KeepaliveServerTestCase1 , KeepaliveServerTestCase2 ,
1553- GzipServerTestCase , GzipUtilTestCase , HeadersServerTestCase ,
1554- MultiPathServerTestCase , ServerProxyTestCase , FailingServerTestCase ,
1555- CGIHandlerTestCase , SimpleXMLRPCDispatcherTestCase )
1594+ def setUpModule ():
1595+ thread_info = threading_helper .threading_setup ()
1596+ unittest .addModuleCleanup (threading_helper .threading_cleanup , * thread_info )
15561597
15571598
15581599if __name__ == "__main__" :
1559- test_main ()
1600+ unittest . main ()
0 commit comments