From a3ed23d8924e1232c8f219a70da98238644326fd Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Sun, 29 Nov 2009 21:45:24 -0500 Subject: [PATCH] Added all.py convenience module for running stdlib tests. Patcherized test_timeout. --- doc/testing.rst | 8 ++++---- tests/stdlib/all.py | 38 ++++++++++++++++++++++++++++++++++++ tests/stdlib/test_timeout.py | 14 ++++++------- 3 files changed, 49 insertions(+), 11 deletions(-) create mode 100644 tests/stdlib/all.py diff --git a/doc/testing.rst b/doc/testing.rst index 43adbcb..d1c908f 100644 --- a/doc/testing.rst +++ b/doc/testing.rst @@ -39,14 +39,14 @@ Standard Library Tests Eventlet provides for the ability to test itself with the standard Python networking tests. This verifies that the libraries it wraps work at least as well as the standard ones do. The directory tests/stdlib contains a bunch of stubs that import the standard lib tests from your system and run them. If you do not have any tests in your python distribution, they'll simply fail to import. -Run the standard library tests with nose; simply do: +There's a convenience module called all.py designed to handle the impedance mismatch between Nose and the standard tests: .. code-block:: sh - $ cd tests/ - $ nosetests stdlib + $ nosetests tests/stdlib/all.py -That should get you started. At this time this generates a bunch of spurious failures, due to `Nose issue 162 `_, which incorrectly identifies helper methods as test cases. Therefore, ignore any failure for the reason ``TypeError: foo() takes exactly N arguments (2 given)``, and sit tight until a version of Nose is released that fixes the issue. +That will run all the tests, though the output will be a little weird because it will look like Nose is running about 20 tests, each of which consists of a bunch of sub-tests. Not all test modules are present in all versions of Python, so there will be an occasional printout of "Not importing %s, it doesn't exist in this installation/version of Python". + Testing Eventlet Hubs --------------------- diff --git a/tests/stdlib/all.py b/tests/stdlib/all.py new file mode 100644 index 0000000..1734c5f --- /dev/null +++ b/tests/stdlib/all.py @@ -0,0 +1,38 @@ +""" Convenience module for running standard library tests with nose. The standard tests are not especially homogeneous, but they mostly expose a test_main method that does the work of selecting which tests to run based on what is supported by the platform. On its own, Nose would run all possible tests and many would fail; therefore we collect all of the test_main methods here in one module and Nose can run it. Hopefully in the future the standard tests get rewritten to be more self-contained. + +Many of these tests make connections to external servers, causing failures when run while disconnected from the internet. +""" + + +def import_main(g, name): + try: + modobj = __import__(name, g, fromlist=['test_main']) + except ImportError: + print "Not importing %s, it doesn't exist in this installation/version of Python" % name + return + else: + method_name = name + "_test_main" + try: + g[method_name] = modobj.test_main + modobj.test_main.__name__ = name + '.test_main' + except AttributeError: + print "No test_main for %s, assuming it tests on import" % name + +import_main(globals(), 'test_SimpleHTTPServer') +import_main(globals(), 'test_asynchat') +import_main(globals(), 'test_asyncore') +import_main(globals(), 'test_ftplib') +import_main(globals(), 'test_httplib') +#import_main(globals(), 'test_httpservers') +import_main(globals(), 'test_select') +import_main(globals(), 'test_socket') +#import_main(globals(), 'test_socket_ssl') +import_main(globals(), 'test_socketserver') +#import_main(globals(), 'test_ssl') +import_main(globals(), 'test_thread') +#import_main(globals(), 'test_threading') +#import_main(globals(), 'test_threading_local') +import_main(globals(), 'test_timeout') +import_main(globals(), 'test_urllib') +#import_main(globals(), 'test_urllib2') +#import_main(globals(), 'test_urllib2_localnet') \ No newline at end of file diff --git a/tests/stdlib/test_timeout.py b/tests/stdlib/test_timeout.py index f0afec3..514d5ac 100644 --- a/tests/stdlib/test_timeout.py +++ b/tests/stdlib/test_timeout.py @@ -1,15 +1,15 @@ +from eventlet import patcher from eventlet.green import socket from eventlet.green import time -from test import test_timeout - -test_timeout.socket = socket -test_timeout.time = time +patcher.inject('test.test_timeout', + globals(), + ('socket', socket), + ('time', time)) # to get past the silly 'requires' check -test_timeout.__name__ = '__main__' - -from test.test_timeout import * +from test import test_support +test_support.use_resources = ['network'] if __name__ == "__main__": test_main() \ No newline at end of file