]> granicus.if.org Git - python/commitdiff
Issue #18492: Allow all resources when tests are not run by regrtest.py.
authorZachary Ware <zachary.ware@gmail.com>
Mon, 2 Jun 2014 21:01:16 +0000 (16:01 -0500)
committerZachary Ware <zachary.ware@gmail.com>
Mon, 2 Jun 2014 21:01:16 +0000 (16:01 -0500)
This changeset also includes cleanup allowed by this behavior change.

13 files changed:
Lib/idlelib/FormatParagraph.py
Lib/idlelib/IdleHistory.py
Lib/idlelib/SearchEngine.py
Lib/idlelib/idle_test/README.txt
Lib/lib-tk/test/runtktests.py
Lib/test/test_codecmaps_hk.py
Lib/test/test_decimal.py
Lib/test/test_idle.py
Lib/test/test_imaplib.py
Lib/test/test_support.py
Lib/test/test_tk.py
Lib/test/test_ttk_guionly.py
Misc/NEWS

index 2ac87e45ea1a7216f3b708d50f796438cfc9eafc..9b10c0a7601f2e54a420eed01e2bb4d82962d7f1 100644 (file)
@@ -188,7 +188,6 @@ def get_comment_header(line):
     return m.group(1)
 
 if __name__ == "__main__":
-    from test import support; support.use_resources = ['gui']
     import unittest
     unittest.main('idlelib.idle_test.test_formatparagraph',
             verbosity=2, exit=False)
index 931d5b28e43cae85ab1988297a1fce6aa586b31f..078af2905325b5df1912ea345669f513ff9c6a5e 100644 (file)
@@ -100,7 +100,5 @@ class History:
         self.prefix = None
 
 if __name__ == "__main__":
-    from test import test_support as support
-    support.use_resources = ['gui']
     from unittest import main
     main('idlelib.idle_test.test_idlehistory', verbosity=2, exit=False)
index 9517412477d1fe653f3e33bde2e3c3c195e90c99..b3b7b4df0abec5d5f8eceac949a7cc2e71532e83 100644 (file)
@@ -229,6 +229,5 @@ def get_line_col(index):
     return line, col
 
 if __name__ == "__main__":
-    from test import test_support; test_support.use_resources = ['gui']
     import unittest
     unittest.main('idlelib.idle_test.test_searchengine', verbosity=2, exit=False)
index 6b924831930fda5e64054e54be2cb30d524ca33e..f6b6a21ad5aa8ccbce5fc10300cf29492853eb6e 100644 (file)
@@ -26,7 +26,6 @@ Once test_xyy is written, the following should go at the end of xyy.py,
 with xyz (lowercased) added after 'test_'.
 ---
 if __name__ == "__main__":
-    from test import support; support.use_resources = ['gui']
     import unittest
     unittest.main('idlelib.idle_test.test_', verbosity=2, exit=False)
 ---
@@ -34,12 +33,12 @@ if __name__ == "__main__":
 
 2. Gui Tests
 
-Gui tests need 'requires' and 'use_resources' from test.support
-(test.test_support in 2.7). A test is a gui test if it creates a Tk root or
-master object either directly or indirectly by instantiating a tkinter or
-idle class. For the benefit of buildbot machines that do not have a graphics
-screen, gui tests must be 'guarded' by "requires('gui')" in a setUp
-function or method. This will typically be setUpClass.
+Gui tests need 'requires' from test.support (test.test_support in 2.7). A
+test is a gui test if it creates a Tk root or master object either directly
+or indirectly by instantiating a tkinter or idle class. For the benefit of
+test processes that either have no graphical environment available or are not
+allowed to use it, gui tests must be 'guarded' by "requires('gui')" in a
+setUp function or method. This will typically be setUpClass.
 
 To avoid interfering with other gui tests, all gui objects must be destroyed
 and deleted by the end of the test.  If a widget, such as a Tk root, is created
@@ -57,11 +56,17 @@ and class attributes, also delete the widget.
         del cls.root
 ---
 
-Support.requires('gui') returns true if it is either called in a main module
-(which never happens on buildbots) or if use_resources contains 'gui'.
-Use_resources is set by test.regrtest but not by unittest. So when running
-tests in another module with unittest, we set it ourselves, as in the xyz.py
-template above.
+Support.requires('gui') causes the test(s) it guards to be skipped if any of
+a few conditions are met:
+ - The tests are being run by regrtest.py, and it was started without
+   enabling the "gui" resource with the "-u" command line option.
+ - The tests are being run on Windows by a service that is not allowed to
+   interact with the graphical environment.
+ - The tests are being run on Mac OSX in a process that cannot make a window
+   manager connection.
+ - tkinter.Tk cannot be successfully instantiated for some reason.
+ - test.support.use_resources has been set by something other than
+   regrtest.py and does not contain "gui".
 
 Since non-gui tests always run, but gui tests only sometimes, tests of non-gui
 operations should best avoid needing a gui. Methods that make incidental use of
@@ -88,8 +93,8 @@ python -m idlelib.idle_test.test_xyz
 
 To run all idle_test/test_*.py tests, either interactively
 ('>>>', with unittest imported) or from a command line, use one of the
-following. (Notes: unittest does not run gui tests; in 2.7, 'test ' (with the
-space) is 'test.regrtest '; where present, -v and -ugui can be omitted.)
+following. (Notes: in 2.7, 'test ' (with the space) is 'test.regrtest ';
+where present, -v and -ugui can be omitted.)
 
 >>> unittest.main('idlelib.idle_test', verbosity=2, exit=False)
 python -m unittest -v idlelib.idle_test
@@ -98,13 +103,13 @@ python -m test.test_idle
 
 The idle tests are 'discovered' by idlelib.idle_test.__init__.load_tests,
 which is also imported into test.test_idle. Normally, neither file should be
-changed when working on individual test modules. The third command runs runs
+changed when working on individual test modules. The third command runs
 unittest indirectly through regrtest. The same happens when the entire test
 suite is run with 'python -m test'. So that command must work for buildbots
 to stay green. Idle tests must not disturb the environment in a way that
 makes other tests fail (issue 18081).
 
 To run an individual Testcase or test method, extend the dotted name given to
-unittest on the command line. (But gui tests will not this way.)
+unittest on the command line.
 
 python -m unittest -v idlelib.idle_test.test_xyz.Test_case.test_meth
index aff6441b200551ea7fb0665d28751761aab2c0e3..d4b18931ec36b3a596278492993f51c5de544913 100644 (file)
@@ -67,5 +67,4 @@ def get_tests(text=True, gui=True, packages=None):
                 yield test
 
 if __name__ == "__main__":
-    test.test_support.use_resources = ['gui']
     test.test_support.run_unittest(*get_tests())
index 7ba191b1cdbe3f74ff1af7f2d6c1adf2589fd9bf..3fd3eb816ddf8530c09bd2dd7c7eebc81cadb178 100644 (file)
@@ -16,5 +16,4 @@ def test_main():
     test_support.run_unittest(__name__)
 
 if __name__ == "__main__":
-    test_support.use_resources = ['urlfetch']
     test_main()
index 87e8816bdebfe3df48e5f82ae9399401fe19fd39..09022786ecbe81bde7f87e9dc2bd51a2fc3f4fa9 100644 (file)
@@ -2271,7 +2271,7 @@ class ContextFlags(unittest.TestCase):
                                   "operation raises different flags depending on flags set: " +
                                   "expected %s, got %s" % (expected_flags, new_flags))
 
-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
@@ -2280,7 +2280,7 @@ def test_main(arith=False, verbose=None, todo_tests=None, debug=None):
 
     init()
     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:
index 66dd8af24f77cfbc650026416a8bb06efa4a7774..9bd38fe9969b609e472b3f1c93fe76a9eee49e88 100644 (file)
@@ -17,8 +17,4 @@ def test_main():
     support.run_unittest(unittest.TestLoader().loadTestsFromModule(idletest))
 
 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)
index 1beb39e3863b22c1d80c72451988e94079e701be..405b7ea8dd7097f0f1cf1e6049acc10e0acc70e0 100644 (file)
@@ -249,5 +249,4 @@ def test_main():
 
 
 if __name__ == "__main__":
-    support.use_resources = ['network']
     test_main()
index b8149527bd879441975c2e66beaa7e818f4b8eb4..e1ee3f537ece06344053a134c4a773d24ed6ce03 100644 (file)
@@ -346,21 +346,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.
+    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
 
-    If the caller's module is __main__ then automatically return True.  The
-    possibility of False being returned occurs when regrtest.py is executing."""
+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 `%s' resource not enabled" % resource
index 56eef47dfa83050108e7591bccdefa167c04678a..f3e264bfc733457749513ea2ab5b1b7ad0546919 100644 (file)
@@ -12,16 +12,10 @@ lib_tk_test = os.path.abspath(os.path.join(this_dir, os.path.pardir,
 with test_support.DirsOnSysPath(lib_tk_test):
     import runtktests
 
-def test_main(enable_gui=False):
-    if enable_gui:
-        if test_support.use_resources is None:
-            test_support.use_resources = ['gui']
-        elif 'gui' not in test_support.use_resources:
-            test_support.use_resources.append('gui')
-
+def test_main():
     with test_support.DirsOnSysPath(lib_tk_test):
         test_support.run_unittest(
             *runtktests.get_tests(text=False, packages=['test_tkinter']))
 
 if __name__ == '__main__':
-    test_main(enable_gui=True)
+    test_main()
index 47ddefb11c8fca74ccffb34c97ebf4cb5ff38c72..caa69303ccc08dce38c28c1d26a17ba6526d924c 100644 (file)
@@ -22,13 +22,7 @@ except TclError, msg:
     # assuming ttk is not available
     raise unittest.SkipTest("ttk not available: %s" % msg)
 
-def test_main(enable_gui=False):
-    if enable_gui:
-        if test_support.use_resources is None:
-            test_support.use_resources = ['gui']
-        elif 'gui' not in test_support.use_resources:
-            test_support.use_resources.append('gui')
-
+def test_main():
     with test_support.DirsOnSysPath(lib_tk_test):
         from test_ttk.support import get_tk_root
         try:
@@ -38,4 +32,4 @@ def test_main(enable_gui=False):
             get_tk_root().destroy()
 
 if __name__ == '__main__':
-    test_main(enable_gui=True)
+    test_main()
index 8320b0ea6e77716fde230928cc107b03db4e145f..4cf70a664d92ebd9f0dc6e5fefd59819956867ed 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -46,6 +46,9 @@ Library
 Tests
 -----
 
+- Issue #18492: All resources are now allowed when tests are not run by
+  regrtest.py.
+
 - Issue #21605: Added tests for Tkinter images.
 
 - Issue #21493: Added test for ntpath.expanduser().  Original patch by