diff options
author | Zachary Ware <zachary.ware@gmail.com> | 2014-06-02 21:01:29 (GMT) |
---|---|---|
committer | Zachary Ware <zachary.ware@gmail.com> | 2014-06-02 21:01:29 (GMT) |
commit | 66f29284797c31190ad06554d9909d7ed8a894d1 (patch) | |
tree | 0388a5b7cd0084afc8ed45855bb16f0d631971e1 /Lib/test | |
parent | 8dd49fe09fc4ac3b527914a0703c0dc0429aa125 (diff) | |
download | cpython-66f29284797c31190ad06554d9909d7ed8a894d1.zip cpython-66f29284797c31190ad06554d9909d7ed8a894d1.tar.gz cpython-66f29284797c31190ad06554d9909d7ed8a894d1.tar.bz2 |
Issue #18492: Allow all resources when tests are not run by regrtest.py.
This changeset also includes cleanup allowed by this behavior change.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/support/__init__.py | 20 | ||||
-rw-r--r-- | Lib/test/test_codecmaps_hk.py | 1 | ||||
-rw-r--r-- | Lib/test/test_decimal.py | 4 | ||||
-rw-r--r-- | Lib/test/test_idle.py | 4 | ||||
-rw-r--r-- | Lib/test/test_imaplib.py | 1 | ||||
-rw-r--r-- | Lib/test/test_robotparser.py | 1 | ||||
-rw-r--r-- | Lib/test/test_tk.py | 10 | ||||
-rw-r--r-- | Lib/test/test_ttk_guionly.py | 10 |
8 files changed, 13 insertions, 38 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 40aab96..c1a187d 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -454,23 +454,17 @@ def _is_gui_available(): return _is_gui_available.result def is_resource_enabled(resource): - """Test whether a resource is enabled. Known resources are set by - regrtest.py.""" - return use_resources is not None and resource in use_resources + """Test whether a resource is enabled. -def requires(resource, msg=None): - """Raise ResourceDenied if the specified resource is not available. - - If the caller's module is __main__ then automatically return True. The - possibility of False being returned occurs when regrtest.py is - executing. + Known resources are set by regrtest.py. If not running under regrtest.py, + all resources are assumed enabled unless use_resources has been set. """ + return use_resources is None or resource in use_resources + +def requires(resource, msg=None): + """Raise ResourceDenied if the specified resource is not available.""" if resource == 'gui' and not _is_gui_available(): raise ResourceDenied(_is_gui_available.reason) - # see if the caller's module is __main__ - if so, treat as if - # the resource was set - if sys._getframe(1).f_globals.get("__name__") == "__main__": - return if not is_resource_enabled(resource): if msg is None: msg = "Use of the %r resource not enabled" % resource diff --git a/Lib/test/test_codecmaps_hk.py b/Lib/test/test_codecmaps_hk.py index 278ae2f..9570af2 100644 --- a/Lib/test/test_codecmaps_hk.py +++ b/Lib/test/test_codecmaps_hk.py @@ -16,5 +16,4 @@ def test_main(): support.run_unittest(__name__) if __name__ == "__main__": - support.use_resources = ['urlfetch'] test_main() diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py index 4b27907..8358ba6 100644 --- a/Lib/test/test_decimal.py +++ b/Lib/test/test_decimal.py @@ -5429,7 +5429,7 @@ else: all_tests.insert(0, CheckAttributes) -def test_main(arith=False, verbose=None, todo_tests=None, debug=None): +def test_main(arith=None, verbose=None, todo_tests=None, debug=None): """ Execute the tests. Runs all arithmetic tests if arith is True or if the "decimal" resource @@ -5439,7 +5439,7 @@ def test_main(arith=False, verbose=None, todo_tests=None, debug=None): init(C) init(P) global TEST_ALL, DEBUG - TEST_ALL = arith or is_resource_enabled('decimal') + TEST_ALL = arith if arith is not None else is_resource_enabled('decimal') DEBUG = debug if todo_tests is None: diff --git a/Lib/test/test_idle.py b/Lib/test/test_idle.py index 2eb0e6e..141e89e 100644 --- a/Lib/test/test_idle.py +++ b/Lib/test/test_idle.py @@ -13,8 +13,4 @@ idletest = import_module('idlelib.idle_test') load_tests = idletest.load_tests if __name__ == '__main__': - # Until unittest supports resources, we emulate regrtest's -ugui - # so loaded tests run the same as if textually present here. - # If any Idle test ever needs another resource, add it to the list. - support.use_resources = ['gui'] # use_resources is initially None unittest.main(verbosity=2, exit=False) diff --git a/Lib/test/test_imaplib.py b/Lib/test/test_imaplib.py index 5e0eaea..a6d83d4 100644 --- a/Lib/test/test_imaplib.py +++ b/Lib/test/test_imaplib.py @@ -501,5 +501,4 @@ def load_tests(*args): if __name__ == "__main__": - support.use_resources = ['network'] unittest.main() diff --git a/Lib/test/test_robotparser.py b/Lib/test/test_robotparser.py index ebc819c..b6b8caf 100644 --- a/Lib/test/test_robotparser.py +++ b/Lib/test/test_robotparser.py @@ -291,5 +291,4 @@ def load_tests(loader, suite, pattern): return suite if __name__=='__main__': - support.use_resources = ['network'] unittest.main() diff --git a/Lib/test/test_tk.py b/Lib/test/test_tk.py index 589f66d..62729f0 100644 --- a/Lib/test/test_tk.py +++ b/Lib/test/test_tk.py @@ -10,15 +10,9 @@ support.requires('gui') from tkinter.test import runtktests -def test_main(enable_gui=False): - if enable_gui: - if support.use_resources is None: - support.use_resources = ['gui'] - elif 'gui' not in support.use_resources: - support.use_resources.append('gui') - +def test_main(): support.run_unittest( *runtktests.get_tests(text=False, packages=['test_tkinter'])) if __name__ == '__main__': - test_main(enable_gui=True) + test_main() diff --git a/Lib/test/test_ttk_guionly.py b/Lib/test/test_ttk_guionly.py index 502b067..e7a654f 100644 --- a/Lib/test/test_ttk_guionly.py +++ b/Lib/test/test_ttk_guionly.py @@ -22,13 +22,7 @@ except TclError as msg: # assuming ttk is not available raise unittest.SkipTest("ttk not available: %s" % msg) -def test_main(enable_gui=False): - if enable_gui: - if support.use_resources is None: - support.use_resources = ['gui'] - elif 'gui' not in support.use_resources: - support.use_resources.append('gui') - +def test_main(): try: support.run_unittest( *runtktests.get_tests(text=False, packages=['test_ttk'])) @@ -36,4 +30,4 @@ def test_main(enable_gui=False): get_tk_root().destroy() if __name__ == '__main__': - test_main(enable_gui=True) + test_main() |