summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2013-09-08 02:49:53 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2013-09-08 02:49:53 (GMT)
commitff6382b40dfe6c0c978f25f027a72ac91c5449a6 (patch)
treec7fb2363110942fe9e6845b56e3497532be7c0f6 /Lib
parent68d7f78703d8b1dbae79d51d8910b21bfefa1a32 (diff)
parent0494c2ae7f6a347590d66bb4fe7980dc0dc9ccda (diff)
downloadcpython-ff6382b40dfe6c0c978f25f027a72ac91c5449a6.zip
cpython-ff6382b40dfe6c0c978f25f027a72ac91c5449a6.tar.gz
cpython-ff6382b40dfe6c0c978f25f027a72ac91c5449a6.tar.bz2
Merge #18952 fix from 3.3
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/support/__init__.py31
1 files changed, 19 insertions, 12 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 5832ef6..5687ef9 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -860,24 +860,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."""
@@ -914,7 +921,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)