Changeset 391 for python/trunk/Lib/test/test_docxmlrpc.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/test/test_docxmlrpc.py
r2 r391 1 1 from DocXMLRPCServer import DocXMLRPCServer 2 2 import httplib 3 import sys 3 4 from test import test_support 4 import threading 5 threading = test_support.import_module('threading') 5 6 import time 6 7 import socket 7 8 import unittest 8 import xmlrpclib9 9 10 10 PORT = None 11 12 def make_request_and_skipIf(condition, reason): 13 # If we skip the test, we have to make a request because the 14 # the server created in setUp blocks expecting one to come in. 15 if not condition: 16 return lambda func: func 17 def decorator(func): 18 def make_request_and_skip(self): 19 self.client.request("GET", "/") 20 self.client.getresponse() 21 raise unittest.SkipTest(reason) 22 return make_request_and_skip 23 return decorator 24 11 25 12 26 def server(evt, numrequests): … … 21 35 serv.set_server_name("DocXMLRPCServer Test Docs") 22 36 serv.set_server_documentation( 23 """This is an XML-RPC server's documentation, but the server can be used by 24 POSTing to /RPC2. Try self.add, too.""")37 "This is an XML-RPC server's documentation, but the server " 38 "can be used by POSTing to /RPC2. Try self.add, too.") 25 39 26 40 # Create and register classes and functions … … 56 70 class DocXMLRPCHTTPGETServer(unittest.TestCase): 57 71 def setUp(self): 72 self._threads = test_support.threading_setup() 58 73 # Enable server feedback 59 74 DocXMLRPCServer._send_traceback_header = True … … 77 92 # Disable server feedback 78 93 DocXMLRPCServer._send_traceback_header = False 94 test_support.threading_cleanup(*self._threads) 79 95 80 96 def test_valid_get_response(self): … … 85 101 self.assertEqual(response.getheader("Content-type"), "text/html") 86 102 87 # Server throws an exception if we don't start to read the data103 # Server raises an exception if we don't start to read the data 88 104 response.read() 89 105 … … 107 123 response = self.client.getresponse() 108 124 109 self.assert_( 110 """<dl><dt><a name="-<lambda>"><strong><lambda></strong></a>(x, y)</dt></dl>""" 111 in response.read()) 112 125 self.assertIn('<dl><dt><a name="-<lambda>"><strong>' 126 '<lambda></strong></a>(x, y)</dt></dl>', 127 response.read()) 128 129 @make_request_and_skipIf(sys.flags.optimize >= 2, 130 "Docstrings are omitted with -O2 and above") 113 131 def test_autolinking(self): 114 """Test that the server correctly automatically wraps references to PEPS115 and RFCs with links, and that it linkifies text starting with http or116 ftp protocol prefixes.132 """Test that the server correctly automatically wraps references to 133 PEPS and RFCs with links, and that it linkifies text starting with 134 http or ftp protocol prefixes. 117 135 118 136 The documentation for the "add" method contains the test material. … … 121 139 response = self.client.getresponse() 122 140 123 self.assert_( # This is ugly ... how can it be made better? 124 """<dl><dt><a name="-add"><strong>add</strong></a>(x, y)</dt><dd><tt>Add two instances together. This follows <a href="http://www.python.org/dev/peps/pep-0008/">PEP008</a>, but has nothing<br>\nto do with <a href="http://www.rfc-editor.org/rfc/rfc1952.txt">RFC1952</a>. Case should matter: pEp008 and rFC1952. Things<br>\nthat start with http and ftp should be auto-linked, too:<br>\n<a href="http://google.com">http://google.com</a>.</tt></dd></dl>""" 125 in response.read()) 126 141 self.assertIn( 142 ('<dl><dt><a name="-add"><strong>add</strong></a>(x, y)</dt><dd>' 143 '<tt>Add two instances together. This ' 144 'follows <a href="http://www.python.org/dev/peps/pep-0008/">' 145 'PEP008</a>, but has nothing<br>\nto do ' 146 'with <a href="http://www.rfc-editor.org/rfc/rfc1952.txt">' 147 'RFC1952</a>. Case should matter: pEp008 ' 148 'and rFC1952. Things<br>\nthat start ' 149 'with http and ftp should be ' 150 'auto-linked, too:<br>\n<a href="http://google.com">' 151 'http://google.com</a>.</tt></dd></dl>'), response.read()) 152 153 @make_request_and_skipIf(sys.flags.optimize >= 2, 154 "Docstrings are omitted with -O2 and above") 127 155 def test_system_methods(self): 128 156 """Test the precense of three consecutive system.* methods. 129 157 130 This also tests their use of parameter type recognition and the systems131 related to that process.158 This also tests their use of parameter type recognition and the 159 systems related to that process. 132 160 """ 133 161 self.client.request("GET", "/") 134 162 response = self.client.getresponse() 135 163 136 self.assert_( 137 """<dl><dt><a name="-system.listMethods"><strong>system.listMethods</strong></a>()</dt><dd><tt><a href="#-system.listMethods">system.listMethods</a>() => [\'add\', \'subtract\', \'multiple\']<br>\n <br>\nReturns a list of the methods supported by the server.</tt></dd></dl>\n <dl><dt><a name="-system.methodHelp"><strong>system.methodHelp</strong></a>(method_name)</dt><dd><tt><a href="#-system.methodHelp">system.methodHelp</a>(\'add\') => "Adds two integers together"<br>\n <br>\nReturns a string containing documentation for the specified method.</tt></dd></dl>\n <dl><dt><a name="-system.methodSignature"><strong>system.methodSignature</strong></a>(method_name)</dt><dd><tt><a href="#-system.methodSignature">system.methodSignature</a>(\'add\') => [double, int, int]<br>\n <br>\nReturns a list describing the signature of the method. In the<br>\nabove example, the add method takes two integers as arguments<br>\nand returns a double result.<br>\n <br>\nThis server does NOT support system.methodSignature.</tt></dd></dl>""" 138 in response.read()) 164 self.assertIn( 165 ('<dl><dt><a name="-system.listMethods"><strong>system.listMethods' 166 '</strong></a>()</dt><dd><tt><a href="#-system.listMethods">system' 167 '.listMethods</a>() => [\'add\', \'subtract\',' 168 ' \'multiple\']<br>\n <br>\nReturns a list' 169 ' of the methods supported by the' 170 ' server.</tt></dd></dl>\n <dl><dt><a name="-system.methodHelp">' 171 '<strong>system.methodHelp</strong></a>(method_name)</dt><dd><tt>' 172 '<a href="#-system.methodHelp">system.methodHelp</a>(\'add\') ' 173 '=> "Adds two integers together"<br>\n ' 174 '<br>\nReturns a string containing documentation' 175 ' for the specified method.</tt></dd></dl>\n ' 176 '<dl><dt><a name="-system.methodSignature"><strong>system.' 177 'methodSignature</strong></a>(method_name)</dt><dd><tt><a href="#-' 178 'system.methodSignature">system.methodSignature</a>(\'add\') ' 179 '=> [double, int, int]<br>\n <br>\nReturns' 180 ' a list describing the signature of' 181 ' the method. In the<br>\nabove example,' 182 ' the add method takes two integers' 183 ' as arguments<br>\nand returns a double' 184 ' result.<br>\n <br>\nThis server does ' 185 'NOT support system.methodSignature.</tt></dd></dl>'), 186 response.read()) 139 187 140 188 def test_autolink_dotted_methods(self): … … 144 192 response = self.client.getresponse() 145 193 146 self.assert _("""Try self.<strong>add</strong>, too.""" in147 response.read())194 self.assertIn("""Try self.<strong>add</strong>, too.""", 195 response.read()) 148 196 149 197 def test_main():
Note:
See TracChangeset
for help on using the changeset viewer.