Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/test/test_docxmlrpc.py

    r2 r391  
    11from DocXMLRPCServer import DocXMLRPCServer
    22import httplib
     3import sys
    34from test import test_support
    4 import threading
     5threading = test_support.import_module('threading')
    56import time
    67import socket
    78import unittest
    8 import xmlrpclib
    99
    1010PORT = None
     11
     12def 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
    1125
    1226def server(evt, numrequests):
     
    2135        serv.set_server_name("DocXMLRPCServer Test Docs")
    2236        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.")
    2539
    2640        # Create and register classes and functions
     
    5670class DocXMLRPCHTTPGETServer(unittest.TestCase):
    5771    def setUp(self):
     72        self._threads = test_support.threading_setup()
    5873        # Enable server feedback
    5974        DocXMLRPCServer._send_traceback_header = True
     
    7792        # Disable server feedback
    7893        DocXMLRPCServer._send_traceback_header = False
     94        test_support.threading_cleanup(*self._threads)
    7995
    8096    def test_valid_get_response(self):
     
    85101        self.assertEqual(response.getheader("Content-type"), "text/html")
    86102
    87         # Server throws an exception if we don't start to read the data
     103        # Server raises an exception if we don't start to read the data
    88104        response.read()
    89105
     
    107123        response = self.client.getresponse()
    108124
    109         self.assert_(
    110 """<dl><dt><a name="-&lt;lambda&gt;"><strong>&lt;lambda&gt;</strong></a>(x, y)</dt></dl>"""
    111             in response.read())
    112 
     125        self.assertIn('<dl><dt><a name="-&lt;lambda&gt;"><strong>'
     126                      '&lt;lambda&gt;</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")
    113131    def test_autolinking(self):
    114         """Test that the server correctly automatically wraps references to PEPS
    115         and RFCs with links, and that it linkifies text starting with http or
    116         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.
    117135
    118136        The documentation for the "add" method contains the test material.
     
    121139        response = self.client.getresponse()
    122140
    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&nbsp;two&nbsp;instances&nbsp;together.&nbsp;This&nbsp;follows&nbsp;<a href="http://www.python.org/dev/peps/pep-0008/">PEP008</a>,&nbsp;but&nbsp;has&nbsp;nothing<br>\nto&nbsp;do&nbsp;with&nbsp;<a href="http://www.rfc-editor.org/rfc/rfc1952.txt">RFC1952</a>.&nbsp;Case&nbsp;should&nbsp;matter:&nbsp;pEp008&nbsp;and&nbsp;rFC1952.&nbsp;&nbsp;Things<br>\nthat&nbsp;start&nbsp;with&nbsp;http&nbsp;and&nbsp;ftp&nbsp;should&nbsp;be&nbsp;auto-linked,&nbsp;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&nbsp;two&nbsp;instances&nbsp;together.&nbsp;This&nbsp;'
     144             'follows&nbsp;<a href="http://www.python.org/dev/peps/pep-0008/">'
     145             'PEP008</a>,&nbsp;but&nbsp;has&nbsp;nothing<br>\nto&nbsp;do&nbsp;'
     146             'with&nbsp;<a href="http://www.rfc-editor.org/rfc/rfc1952.txt">'
     147             'RFC1952</a>.&nbsp;Case&nbsp;should&nbsp;matter:&nbsp;pEp008&nbsp;'
     148             'and&nbsp;rFC1952.&nbsp;&nbsp;Things<br>\nthat&nbsp;start&nbsp;'
     149             'with&nbsp;http&nbsp;and&nbsp;ftp&nbsp;should&nbsp;be&nbsp;'
     150             'auto-linked,&nbsp;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")
    127155    def test_system_methods(self):
    128156        """Test the precense of three consecutive system.* methods.
    129157
    130         This also tests their use of parameter type recognition and the systems
    131         related to that process.
     158        This also tests their use of parameter type recognition and the
     159        systems related to that process.
    132160        """
    133161        self.client.request("GET", "/")
    134162        response = self.client.getresponse()
    135163
    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>()&nbsp;=&gt;&nbsp;[\'add\',&nbsp;\'subtract\',&nbsp;\'multiple\']<br>\n&nbsp;<br>\nReturns&nbsp;a&nbsp;list&nbsp;of&nbsp;the&nbsp;methods&nbsp;supported&nbsp;by&nbsp;the&nbsp;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\')&nbsp;=&gt;&nbsp;"Adds&nbsp;two&nbsp;integers&nbsp;together"<br>\n&nbsp;<br>\nReturns&nbsp;a&nbsp;string&nbsp;containing&nbsp;documentation&nbsp;for&nbsp;the&nbsp;specified&nbsp;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\')&nbsp;=&gt;&nbsp;[double,&nbsp;int,&nbsp;int]<br>\n&nbsp;<br>\nReturns&nbsp;a&nbsp;list&nbsp;describing&nbsp;the&nbsp;signature&nbsp;of&nbsp;the&nbsp;method.&nbsp;In&nbsp;the<br>\nabove&nbsp;example,&nbsp;the&nbsp;add&nbsp;method&nbsp;takes&nbsp;two&nbsp;integers&nbsp;as&nbsp;arguments<br>\nand&nbsp;returns&nbsp;a&nbsp;double&nbsp;result.<br>\n&nbsp;<br>\nThis&nbsp;server&nbsp;does&nbsp;NOT&nbsp;support&nbsp;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>()&nbsp;=&gt;&nbsp;[\'add\',&nbsp;\'subtract\','
     168             '&nbsp;\'multiple\']<br>\n&nbsp;<br>\nReturns&nbsp;a&nbsp;list'
     169             '&nbsp;of&nbsp;the&nbsp;methods&nbsp;supported&nbsp;by&nbsp;the'
     170             '&nbsp;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\')&nbsp;'
     173             '=&gt;&nbsp;"Adds&nbsp;two&nbsp;integers&nbsp;together"<br>\n&nbsp;'
     174             '<br>\nReturns&nbsp;a&nbsp;string&nbsp;containing&nbsp;documentation'
     175             '&nbsp;for&nbsp;the&nbsp;specified&nbsp;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\')&nbsp;'
     179             '=&gt;&nbsp;[double,&nbsp;int,&nbsp;int]<br>\n&nbsp;<br>\nReturns'
     180             '&nbsp;a&nbsp;list&nbsp;describing&nbsp;the&nbsp;signature&nbsp;of'
     181             '&nbsp;the&nbsp;method.&nbsp;In&nbsp;the<br>\nabove&nbsp;example,'
     182             '&nbsp;the&nbsp;add&nbsp;method&nbsp;takes&nbsp;two&nbsp;integers'
     183             '&nbsp;as&nbsp;arguments<br>\nand&nbsp;returns&nbsp;a&nbsp;double'
     184             '&nbsp;result.<br>\n&nbsp;<br>\nThis&nbsp;server&nbsp;does&nbsp;'
     185             'NOT&nbsp;support&nbsp;system.methodSignature.</tt></dd></dl>'),
     186            response.read())
    139187
    140188    def test_autolink_dotted_methods(self):
     
    144192        response = self.client.getresponse()
    145193
    146         self.assert_("""Try&nbsp;self.<strong>add</strong>,&nbsp;too.""" in
    147             response.read())
     194        self.assertIn("""Try&nbsp;self.<strong>add</strong>,&nbsp;too.""",
     195                      response.read())
    148196
    149197def test_main():
Note: See TracChangeset for help on using the changeset viewer.