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
|
Merged revisions 80552-80556,80564-80566,80568-80571 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r80552 | victor.stinner | 2010-04-27 23:46:03 +0200 (mar., 27 avril 2010) | 3 lines
Issue #7449, part 1: fix test_support.py for Python compiled without thread
........
r80553 | victor.stinner | 2010-04-27 23:47:01 +0200 (mar., 27 avril 2010) | 1 line
Issue #7449, part 2: regrtest.py -j option requires thread support
........
r80554 | victor.stinner | 2010-04-27 23:51:26 +0200 (mar., 27 avril 2010) | 9 lines
Issue #7449 part 3, test_doctest: import trace module in test_coverage()
Import trace module fail if the threading module is missing. test_coverage() is
only used if test_doctest.py is used with the -c option. This commit allows to
execute the test suite without thread support.
Move "import trace" in test_coverage() and use
test_support.import_module('trace').
........
r80555 | victor.stinner | 2010-04-27 23:56:26 +0200 (mar., 27 avril 2010) | 6 lines
Issue #7449, part 4: skip test_multiprocessing if thread support is disabled
import threading after _multiprocessing to raise a more revelant error message:
"No module named _multiprocessing". _multiprocessing is not compiled without
thread support.
........
r80556 | victor.stinner | 2010-04-28 00:01:24 +0200 (mer., 28 avril 2010) | 8 lines
Issue #7449, part 5: split Test.test_open() of ctypes/test/test_errno.py
* Split Test.test_open() in 2 functions: test_open() and test_thread_open()
* Skip test_open() and test_thread_open() if we are unable to find the C
library
* Skip test_thread_open() if thread support is disabled
* Use unittest.skipUnless(os.name == "nt", ...) on test_GetLastError()
........
r80564 | victor.stinner | 2010-04-28 00:59:35 +0200 (mer., 28 avril 2010) | 4 lines
Issue #7449, part 6: fix test_hashlib for missing threading module
Move @test_support.reap_thread decorator from test_main() to test_threaded_hashing().
........
r80565 | victor.stinner | 2010-04-28 01:01:29 +0200 (mer., 28 avril 2010) | 6 lines
Issue #7449, part 7: simplify threading detection in test_capi
* Skip TestPendingCalls if threading module is missing
* Test if threading module is present or not, instead of test the presence of
_testcapi._test_thread_state
........
r80566 | victor.stinner | 2010-04-28 01:03:16 +0200 (mer., 28 avril 2010) | 4 lines
Issue #7449, part 8: don't skip the whole test_asynchat if threading is missing
TestFifo can be executed without the threading module
........
r80568 | victor.stinner | 2010-04-28 01:14:58 +0200 (mer., 28 avril 2010) | 6 lines
Issue #7449, part 9: fix test_xmlrpclib for missing threading module
* Skip testcases using threads if threading module is missing
* Use "http://" instead of URL in ServerProxyTestCase if threading is missing
because URL is not set in this case
........
r80569 | victor.stinner | 2010-04-28 01:33:58 +0200 (mer., 28 avril 2010) | 6 lines
Partial revert of r80556 (Issue #7449, part 5, fix ctypes test)
Rewrite r80556: the thread test have to be executed just after the test on
libc_open() and so the test cannot be splitted in two functions (without
duplicating code, and I don't want to duplicate code).
........
r80570 | victor.stinner | 2010-04-28 01:51:16 +0200 (mer., 28 avril 2010) | 8 lines
Issue #7449, part 10: test_cmd imports trace module using test_support.import_module()
Use test_support.import_module() instead of import to raise a SkipTest
exception if the import fail. Import trace fails if the threading module is
missing.
See also part 3: test_doctest: import trace module in test_coverage().
........
r80571 | victor.stinner | 2010-04-28 01:55:59 +0200 (mer., 28 avril 2010) | 6 lines
Issue #7449, last part (11): fix many tests if thread support is disabled
* Use try/except ImportError or test_support.import_module() to import thread
and threading modules
* Add @unittest.skipUnless(threading, ...) to testcases using threads
........
2010-04-28 19:31:17 -03:00
|
|
|
threading = support.import_module('threading')
|
2007-12-10 12:18:49 -04:00
|
|
|
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()
|