]> granicus.if.org Git - python/commitdiff
Close #18952: correctly download test support data
authorNick Coghlan <ncoghlan@gmail.com>
Sun, 8 Sep 2013 01:40:34 +0000 (11:40 +1000)
committerNick Coghlan <ncoghlan@gmail.com>
Sun, 8 Sep 2013 01:40:34 +0000 (11:40 +1000)
When test.support was converted to a package, it started silently
skipping the tests which needed to download support data to run.

This change refactors the affected code, and also tidies up
test.support.findfile to remove the unused *here* parameter, document
the *subdir* parameter and rename the *filename* parameter to avoid
shadowing the file builtin and be consistent with the documentation.

The unexpected skips were noticed and reported by Zachary Ware

Doc/library/test.rst
Lib/test/support/__init__.py
Misc/NEWS

index bce0f647f39238129044e40d7f294b0fdd1ad9cd..c1270f4320b1b68ff00fa0f8210a84dc43262284 100644 (file)
@@ -263,12 +263,15 @@ The :mod:`test.support` module defines the following functions:
    Used when tests are executed by :mod:`test.regrtest`.
 
 
-.. function:: findfile(filename)
+.. function:: findfile(filename, subdir=None)
 
    Return the path to the file named *filename*. If no match is found
    *filename* is returned. This does not equal a failure since it could be the
    path to the file.
 
+    Setting *subdir* indicates a relative path to use to find the file
+    rather than looking directly in the path directories.
+
 
 .. function:: run_unittest(\*classes)
 
index 956fe988ccb62cad34ac08f42b57257173520743..dbd784673731e76c03b19e40063e3dab42763bc1 100644 (file)
@@ -853,24 +853,31 @@ if hasattr(os, "umask"):
         finally:
             os.umask(oldmask)
 
-# TEST_HOME refers to the top level directory of the "test" package
+# TEST_HOME_DIR refers to the top level directory of the "test" package
 # that contains Python's regression test suite
-TEST_HOME = os.path.dirname(os.path.abspath(__file__))
+TEST_SUPPORT_DIR = os.path.dirname(os.path.abspath(__file__))
+TEST_HOME_DIR = os.path.dirname(TEST_SUPPORT_DIR)
 
-def findfile(file, here=TEST_HOME, subdir=None):
+# TEST_DATA_DIR is used as a target download location for remote resources
+TEST_DATA_DIR = os.path.join(TEST_HOME_DIR, "data")
+
+def findfile(filename, subdir=None):
     """Try to find a file on sys.path or in the test directory.  If it is not
     found the argument passed to the function is returned (this does not
-    necessarily signal failure; could still be the legitimate path)."""
-    if os.path.isabs(file):
-        return file
+    necessarily signal failure; could still be the legitimate path).
+
+    Setting *subdir* indicates a relative path to use to find the file
+    rather than looking directly in the path directories.
+    """
+    if os.path.isabs(filename):
+        return filename
     if subdir is not None:
-        file = os.path.join(subdir, file)
-    path = sys.path
-    path = [os.path.dirname(here)] + path
+        filename = os.path.join(subdir, filename)
+    path = [TEST_HOME_DIR] + sys.path
     for dn in path:
-        fn = os.path.join(dn, file)
+        fn = os.path.join(dn, filename)
         if os.path.exists(fn): return fn
-    return file
+    return filename
 
 def create_empty_file(filename):
     """Create an empty file. If the file already exists, truncate it."""
@@ -907,7 +914,7 @@ def open_urlresource(url, *args, **kw):
 
     filename = urllib.parse.urlparse(url)[2].split('/')[-1] # '/': it's URL!
 
-    fn = os.path.join(os.path.dirname(__file__), "data", filename)
+    fn = os.path.join(TEST_DATA_DIR, filename)
 
     def check_valid_file(fn):
         f = open(fn, *args, **kw)
index 1c0f3b23b6a4c62268a967091f39c666cb8cc5cb..ed5f6cd1c3d002bc1572d8e38d8b4f2a64e25d7d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -332,6 +332,10 @@ IDLE
 Tests
 -----
 
+- Issue #18952: Fix regression in support data downloads introduced when
+  test.support was converted to a package. Regression noticed by Zachary
+  Ware.
+
 - Issue #12037: Fix test_email for desktop Windows.
 
 - Issue #15507: test_subprocess's test_send_signal could fail if the test