2008-05-26 08:14:17 -03:00
|
|
|
from xmlrpc.server import DocXMLRPCServer
|
2008-05-26 13:32:26 -03:00
|
|
|
import http.client
|
2010-02-23 21:46:21 -04:00
|
|
|
import sys
|
2008-05-20 18:35:26 -03:00
|
|
|
from test import support
|
2007-12-10 12:18:49 -04:00
|
|
|
import threading
|
|
|
|
import time
|
Merged revisions 78018,78035-78040,78042-78043,78046,78048-78052,78054,78059,78075-78080 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78018 | georg.brandl | 2010-02-06 11:08:21 +0100 (Sa, 06 Feb 2010) | 1 line
#7864: make deprecation notices a bit clearer.
........
r78035 | georg.brandl | 2010-02-06 23:44:17 +0100 (Sa, 06 Feb 2010) | 1 line
Fix duplicate import.
........
r78036 | georg.brandl | 2010-02-06 23:49:47 +0100 (Sa, 06 Feb 2010) | 1 line
Remove unused import.
........
r78037 | georg.brandl | 2010-02-06 23:59:15 +0100 (Sa, 06 Feb 2010) | 1 line
No need to assign the results of expressions used only for side effects.
........
r78038 | georg.brandl | 2010-02-07 00:02:29 +0100 (So, 07 Feb 2010) | 1 line
Add a missing import.
........
r78039 | georg.brandl | 2010-02-07 00:06:24 +0100 (So, 07 Feb 2010) | 1 line
Add missing imports.
........
r78040 | georg.brandl | 2010-02-07 00:08:00 +0100 (So, 07 Feb 2010) | 1 line
Fix a few UnboundLocalErrors in test_long.
........
r78042 | georg.brandl | 2010-02-07 00:12:12 +0100 (So, 07 Feb 2010) | 1 line
Add missing import.
........
r78043 | georg.brandl | 2010-02-07 00:12:19 +0100 (So, 07 Feb 2010) | 1 line
Remove duplicate test method.
........
r78046 | georg.brandl | 2010-02-07 00:18:00 +0100 (So, 07 Feb 2010) | 1 line
Fix various missing import/unbound name errors.
........
r78048 | georg.brandl | 2010-02-07 00:23:45 +0100 (So, 07 Feb 2010) | 1 line
We heard you like test failures so we put unbound locals in your test so that you can fail while you fail.
........
r78049 | georg.brandl | 2010-02-07 00:33:33 +0100 (So, 07 Feb 2010) | 1 line
Fix import/access for some identifiers. _TestSharedCTypes does not seem to be executed?
........
r78050 | georg.brandl | 2010-02-07 00:34:10 +0100 (So, 07 Feb 2010) | 1 line
Fix more unbound locals in code paths that do not seem to be used.
........
r78051 | georg.brandl | 2010-02-07 00:53:52 +0100 (So, 07 Feb 2010) | 1 line
Add missing import when running these tests standalone.
........
r78052 | georg.brandl | 2010-02-07 00:54:04 +0100 (So, 07 Feb 2010) | 1 line
Add missing import when running these tests standalone.
........
r78054 | georg.brandl | 2010-02-07 00:58:25 +0100 (So, 07 Feb 2010) | 1 line
Add missing import.
........
r78059 | georg.brandl | 2010-02-07 12:34:15 +0100 (So, 07 Feb 2010) | 1 line
Use "regexp" consistently.
........
r78075 | georg.brandl | 2010-02-07 13:16:12 +0100 (So, 07 Feb 2010) | 1 line
Fix another duplicated test method.
........
r78076 | georg.brandl | 2010-02-07 13:19:43 +0100 (So, 07 Feb 2010) | 1 line
Fix wrong usage of "except X, Y:".
........
r78077 | georg.brandl | 2010-02-07 13:25:50 +0100 (So, 07 Feb 2010) | 1 line
Fix two redefined test methods.
........
r78078 | georg.brandl | 2010-02-07 13:27:06 +0100 (So, 07 Feb 2010) | 1 line
Fix a redefined test method.
........
r78079 | georg.brandl | 2010-02-07 13:34:26 +0100 (So, 07 Feb 2010) | 1 line
Add a minimal test for fnmatchcase().
........
r78080 | georg.brandl | 2010-02-07 13:55:12 +0100 (So, 07 Feb 2010) | 1 line
Remove duplicate test method.
........
2010-03-14 07:23:39 -03:00
|
|
|
import socket
|
2007-12-10 12:18:49 -04:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
PORT = None
|
|
|
|
|
2010-02-23 21:46:21 -04:00
|
|
|
def make_request_and_skipIf(condition, reason):
|
|
|
|
# If we skip the test, we have to make a request because the
|
|
|
|
# the server created in setUp blocks expecting one to come in.
|
|
|
|
if not condition:
|
|
|
|
return lambda func: func
|
|
|
|
def decorator(func):
|
|
|
|
def make_request_and_skip(self):
|
|
|
|
self.client.request("GET", "/")
|
|
|
|
self.client.getresponse()
|
|
|
|
raise unittest.SkipTest(reason)
|
|
|
|
return make_request_and_skip
|
|
|
|
return decorator
|
|
|
|
|
|
|
|
|
2007-12-10 12:18:49 -04:00
|
|
|
def server(evt, numrequests):
|
2008-10-10 21:49:57 -03:00
|
|
|
serv = DocXMLRPCServer(("localhost", 0), logRequests=False)
|
2007-12-10 12:18:49 -04:00
|
|
|
|
2008-10-10 21:49:57 -03:00
|
|
|
try:
|
2007-12-10 12:18:49 -04:00
|
|
|
global PORT
|
|
|
|
PORT = serv.socket.getsockname()[1]
|
|
|
|
|
|
|
|
# Add some documentation
|
|
|
|
serv.set_server_title("DocXMLRPCServer Test Documentation")
|
|
|
|
serv.set_server_name("DocXMLRPCServer Test Docs")
|
|
|
|
serv.set_server_documentation(
|
2010-01-23 11:40:09 -04:00
|
|
|
"This is an XML-RPC server's documentation, but the server "
|
|
|
|
"can be used by POSTing to /RPC2. Try self.add, too.")
|
2007-12-10 12:18:49 -04:00
|
|
|
|
|
|
|
# Create and register classes and functions
|
|
|
|
class TestClass(object):
|
|
|
|
def test_method(self, arg):
|
|
|
|
"""Test method's docs. This method truly does very little."""
|
|
|
|
self.arg = arg
|
|
|
|
|
|
|
|
serv.register_introspection_functions()
|
|
|
|
serv.register_instance(TestClass())
|
|
|
|
|
|
|
|
def add(x, y):
|
|
|
|
"""Add two instances together. This follows PEP008, but has nothing
|
|
|
|
to do with RFC1952. Case should matter: pEp008 and rFC1952. Things
|
|
|
|
that start with http and ftp should be auto-linked, too:
|
|
|
|
http://google.com.
|
|
|
|
"""
|
|
|
|
return x + y
|
|
|
|
|
|
|
|
serv.register_function(add)
|
|
|
|
serv.register_function(lambda x, y: x-y)
|
|
|
|
|
|
|
|
while numrequests > 0:
|
|
|
|
serv.handle_request()
|
|
|
|
numrequests -= 1
|
|
|
|
except socket.timeout:
|
|
|
|
pass
|
|
|
|
finally:
|
|
|
|
serv.server_close()
|
|
|
|
PORT = None
|
|
|
|
evt.set()
|
|
|
|
|
|
|
|
class DocXMLRPCHTTPGETServer(unittest.TestCase):
|
|
|
|
def setUp(self):
|
2009-10-30 14:34:49 -03:00
|
|
|
self._threads = support.threading_setup()
|
2007-12-10 12:18:49 -04:00
|
|
|
# Enable server feedback
|
|
|
|
DocXMLRPCServer._send_traceback_header = True
|
|
|
|
|
|
|
|
self.evt = threading.Event()
|
|
|
|
threading.Thread(target=server, args=(self.evt, 1)).start()
|
|
|
|
|
|
|
|
# wait for port to be assigned
|
|
|
|
n = 1000
|
|
|
|
while n > 0 and PORT is None:
|
|
|
|
time.sleep(0.001)
|
|
|
|
n -= 1
|
|
|
|
|
2008-05-26 13:32:26 -03:00
|
|
|
self.client = http.client.HTTPConnection("localhost:%d" % PORT)
|
2007-12-10 12:18:49 -04:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.client.close()
|
|
|
|
|
|
|
|
self.evt.wait()
|
|
|
|
|
|
|
|
# Disable server feedback
|
|
|
|
DocXMLRPCServer._send_traceback_header = False
|
2009-10-30 14:34:49 -03:00
|
|
|
support.threading_cleanup(*self._threads)
|
2007-12-10 12:18:49 -04:00
|
|
|
|
|
|
|
def test_valid_get_response(self):
|
|
|
|
self.client.request("GET", "/")
|
|
|
|
response = self.client.getresponse()
|
|
|
|
|
|
|
|
self.assertEqual(response.status, 200)
|
|
|
|
self.assertEqual(response.getheader("Content-type"), "text/html")
|
|
|
|
|
|
|
|
# Server throws an exception if we don't start to read the data
|
|
|
|
response.read()
|
|
|
|
|
|
|
|
def test_invalid_get_response(self):
|
|
|
|
self.client.request("GET", "/spam")
|
|
|
|
response = self.client.getresponse()
|
|
|
|
|
|
|
|
self.assertEqual(response.status, 404)
|
|
|
|
self.assertEqual(response.getheader("Content-type"), "text/plain")
|
|
|
|
|
|
|
|
response.read()
|
|
|
|
|
|
|
|
def test_lambda(self):
|
|
|
|
"""Test that lambda functionality stays the same. The output produced
|
|
|
|
currently is, I suspect invalid because of the unencoded brackets in the
|
|
|
|
HTML, "<lambda>".
|
|
|
|
|
|
|
|
The subtraction lambda method is tested.
|
|
|
|
"""
|
|
|
|
self.client.request("GET", "/")
|
|
|
|
response = self.client.getresponse()
|
|
|
|
|
2010-01-23 11:40:09 -04:00
|
|
|
self.assertIn((b'<dl><dt><a name="-<lambda>"><strong>'
|
|
|
|
b'<lambda></strong></a>(x, y)</dt></dl>'),
|
|
|
|
response.read())
|
2007-12-10 12:18:49 -04:00
|
|
|
|
2010-02-23 21:46:21 -04:00
|
|
|
@make_request_and_skipIf(sys.flags.optimize >= 2,
|
|
|
|
"Docstrings are omitted with -O2 and above")
|
2007-12-10 12:18:49 -04:00
|
|
|
def test_autolinking(self):
|
2010-02-23 21:46:21 -04:00
|
|
|
"""Test that the server correctly automatically wraps references to
|
|
|
|
PEPS and RFCs with links, and that it linkifies text starting with
|
|
|
|
http or ftp protocol prefixes.
|
2007-12-10 12:18:49 -04:00
|
|
|
|
|
|
|
The documentation for the "add" method contains the test material.
|
|
|
|
"""
|
|
|
|
self.client.request("GET", "/")
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60568-60598,60600-60616 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60568 | christian.heimes | 2008-02-04 19:48:38 +0100 (Mon, 04 Feb 2008) | 1 line
Increase debugging to investige failing tests on some build bots
........
r60570 | christian.heimes | 2008-02-04 20:30:05 +0100 (Mon, 04 Feb 2008) | 1 line
Small adjustments for test compact freelist test. It's no passing on Windows as well.
........
r60573 | amaury.forgeotdarc | 2008-02-04 21:53:14 +0100 (Mon, 04 Feb 2008) | 2 lines
Correct quotes in NEWS file
........
r60575 | amaury.forgeotdarc | 2008-02-04 22:45:05 +0100 (Mon, 04 Feb 2008) | 13 lines
#1750076: Debugger did not step on every iteration of a while statement.
The mapping between bytecode offsets and source lines (lnotab) did not contain
an entry for the beginning of the loop.
Now it does, and the lnotab can be a bit larger:
in particular, several statements on the same line generate several entries.
However, this does not bother the settrace function, which will trigger only
one 'line' event.
The lnotab seems to be exactly the same as with python2.4.
........
r60584 | amaury.forgeotdarc | 2008-02-05 01:26:21 +0100 (Tue, 05 Feb 2008) | 3 lines
Change r60575 broke test_compile:
there is no need to emit co_lnotab item when both offsets are zeros.
........
r60587 | skip.montanaro | 2008-02-05 03:32:16 +0100 (Tue, 05 Feb 2008) | 1 line
sync with most recent version from python-mode sf project
........
r60588 | lars.gustaebel | 2008-02-05 12:51:40 +0100 (Tue, 05 Feb 2008) | 5 lines
Issue #2004: Use mode 0700 for temporary directories and default
permissions for missing directories.
(will backport to 2.5)
........
r60590 | georg.brandl | 2008-02-05 13:01:24 +0100 (Tue, 05 Feb 2008) | 2 lines
Convert external links to internal links. Fixes #2010.
........
r60592 | marc-andre.lemburg | 2008-02-05 15:50:40 +0100 (Tue, 05 Feb 2008) | 3 lines
Keep distutils Python 2.1 compatible (or even Python 2.4 in this case).
........
r60593 | andrew.kuchling | 2008-02-05 17:06:57 +0100 (Tue, 05 Feb 2008) | 5 lines
Update PEP URL.
(This code is duplicated between pydoc and DocXMLRPCServer; maybe it
should be refactored as a GHOP project.)
2.5.2 backport candidate.
........
r60596 | guido.van.rossum | 2008-02-05 18:32:15 +0100 (Tue, 05 Feb 2008) | 2 lines
In the experimental 'Scanner' feature, the group count was set wrong.
........
r60602 | facundo.batista | 2008-02-05 20:03:32 +0100 (Tue, 05 Feb 2008) | 3 lines
Issue 1951. Converts wave test cases to unittest.
........
r60603 | georg.brandl | 2008-02-05 20:07:10 +0100 (Tue, 05 Feb 2008) | 2 lines
Actually run the test.
........
r60604 | skip.montanaro | 2008-02-05 20:24:30 +0100 (Tue, 05 Feb 2008) | 2 lines
correct object name
........
r60605 | georg.brandl | 2008-02-05 20:58:17 +0100 (Tue, 05 Feb 2008) | 7 lines
* Use the same code to profile for test_profile and test_cprofile.
* Convert both to unittest.
* Use the same unit testing code.
* Include the expected output in both test files.
* Make it possible to regenerate the expected output by running
the file as a script with an '-r' argument.
........
r60613 | raymond.hettinger | 2008-02-06 02:49:00 +0100 (Wed, 06 Feb 2008) | 1 line
Sync-up with Py3k work.
........
r60614 | christian.heimes | 2008-02-06 13:44:34 +0100 (Wed, 06 Feb 2008) | 1 line
Limit free list of method and builtin function objects to 256 entries each.
........
r60616 | christian.heimes | 2008-02-06 14:33:44 +0100 (Wed, 06 Feb 2008) | 7 lines
Unified naming convention for free lists and their limits. All free lists
in Object/ are named ``free_list``, the counter ``numfree`` and the upper
limit is a macro ``PyName_MAXFREELIST`` inside an #ifndef block.
The chances should make it easier to adjust Python for platforms with
less memory, e.g. mobile phones.
........
2008-02-06 10:31:34 -04:00
|
|
|
response = self.client.getresponse().read()
|
2007-12-10 12:18:49 -04:00
|
|
|
|
2010-01-23 11:40:09 -04:00
|
|
|
self.assertIn(
|
|
|
|
(b'<dl><dt><a name="-add"><strong>add</strong></a>(x, y)</dt><dd>'
|
|
|
|
b'<tt>Add two instances together. This '
|
|
|
|
b'follows <a href="http://www.python.org/dev/peps/pep-0008/">'
|
|
|
|
b'PEP008</a>, but has nothing<br>\nto do '
|
|
|
|
b'with <a href="http://www.rfc-editor.org/rfc/rfc1952.txt">'
|
|
|
|
b'RFC1952</a>. Case should matter: pEp008 '
|
|
|
|
b'and rFC1952. Things<br>\nthat start '
|
|
|
|
b'with http and ftp should be '
|
|
|
|
b'auto-linked, too:<br>\n<a href="http://google.com">'
|
|
|
|
b'http://google.com</a>.</tt></dd></dl>'), response)
|
2007-12-10 12:18:49 -04:00
|
|
|
|
2010-02-23 21:46:21 -04:00
|
|
|
@make_request_and_skipIf(sys.flags.optimize >= 2,
|
|
|
|
"Docstrings are omitted with -O2 and above")
|
2007-12-10 12:18:49 -04:00
|
|
|
def test_system_methods(self):
|
|
|
|
"""Test the precense of three consecutive system.* methods.
|
|
|
|
|
2010-02-23 21:46:21 -04:00
|
|
|
This also tests their use of parameter type recognition and the
|
|
|
|
systems related to that process.
|
2007-12-10 12:18:49 -04:00
|
|
|
"""
|
|
|
|
self.client.request("GET", "/")
|
2007-12-10 16:18:07 -04:00
|
|
|
response = self.client.getresponse().read()
|
2007-12-10 12:18:49 -04:00
|
|
|
|
2010-01-23 11:40:09 -04:00
|
|
|
self.assertIn(
|
|
|
|
(b'<dl><dt><a name="-system.methodHelp"><strong>system.methodHelp'
|
|
|
|
b'</strong></a>(method_name)</dt><dd><tt><a href="#-system.method'
|
|
|
|
b'Help">system.methodHelp</a>(\'add\') => "Adds '
|
|
|
|
b'two integers together"<br>\n <br>\nReturns a'
|
|
|
|
b' string containing documentation for '
|
|
|
|
b'the specified method.</tt></dd></dl>\n<dl><dt><a name'
|
|
|
|
b'="-system.methodSignature"><strong>system.methodSignature</strong>'
|
|
|
|
b'</a>(method_name)</dt><dd><tt><a href="#-system.methodSignature">'
|
|
|
|
b'system.methodSignature</a>(\'add\') => [double, '
|
|
|
|
b'int, int]<br>\n <br>\nReturns a list '
|
|
|
|
b'describing the signature of the method.'
|
|
|
|
b' In the<br>\nabove example, the add '
|
|
|
|
b'method takes two integers as arguments'
|
|
|
|
b'<br>\nand returns a double result.<br>\n '
|
|
|
|
b'<br>\nThis server does NOT support system'
|
|
|
|
b'.methodSignature.</tt></dd></dl>\n<dl><dt><a name="-test_method">'
|
|
|
|
b'<strong>test_method</strong></a>(arg)</dt><dd><tt>Test '
|
|
|
|
b'method\'s docs. This method truly does'
|
|
|
|
b' very little.</tt></dd></dl>'), response)
|
2007-12-10 12:18:49 -04:00
|
|
|
|
|
|
|
def test_autolink_dotted_methods(self):
|
|
|
|
"""Test that selfdot values are made strong automatically in the
|
|
|
|
documentation."""
|
|
|
|
self.client.request("GET", "/")
|
|
|
|
response = self.client.getresponse()
|
|
|
|
|
2010-01-23 11:40:09 -04:00
|
|
|
self.assertIn(b"""Try self.<strong>add</strong>, too.""",
|
|
|
|
response.read())
|
2007-12-10 12:18:49 -04:00
|
|
|
|
|
|
|
def test_main():
|
2008-05-20 18:35:26 -03:00
|
|
|
support.run_unittest(DocXMLRPCHTTPGETServer)
|
2007-12-10 12:18:49 -04:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
test_main()
|