Add python-eventlet 0.16.1
[packages/trusty/python-eventlet.git] / eventlet / tests / stdlib / all.py
1 """ Convenience module for running standard library tests with nose.  The standard
2 tests are not especially homogeneous, but they mostly expose a test_main method that
3 does the work of selecting which tests to run based on what is supported by the
4 platform.  On its own, Nose would run all possible tests and many would fail; therefore
5 we collect all of the test_main methods here in one module and Nose can run it.
6
7 Hopefully in the future the standard tests get rewritten to be more nosey.
8
9 Many of these tests make connections to external servers, and all.py tries to skip these
10 tests rather than failing them, so you can get some work done on a plane.
11 """
12
13 from eventlet import debug
14 debug.hub_prevent_multiple_readers(False)
15
16
17 def restart_hub():
18     from eventlet import hubs
19     hub = hubs.get_hub()
20     hub_shortname = hub.__module__.split('.')[-1]
21     # don't restart the pyevent hub; it's not necessary
22     if hub_shortname != 'pyevent':
23         hub.abort()
24         hubs.use_hub(hub_shortname)
25
26
27 def assimilate_patched(name):
28     try:
29         modobj = __import__(name, globals(), locals(), ['test_main'])
30         restart_hub()
31     except ImportError:
32         print("Not importing %s, it doesn't exist in this installation/version of Python" % name)
33         return
34     else:
35         method_name = name + "_test_main"
36         try:
37             test_method = modobj.test_main
38
39             def test_main():
40                 restart_hub()
41                 test_method()
42                 restart_hub()
43             globals()[method_name] = test_main
44             test_main.__name__ = name + '.test_main'
45         except AttributeError:
46             print("No test_main for %s, assuming it tests on import" % name)
47
48 import all_modules
49
50 for m in all_modules.get_modules():
51     assimilate_patched(m)