summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_importlib
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2013-10-18 15:39:04 (GMT)
committerBrett Cannon <brett@python.org>2013-10-18 15:39:04 (GMT)
commit27e27f7ee1f366e52cfd576b427e923190b6202e (patch)
tree895d1caeba83a4151556fdb06fcad6141bd49f12 /Lib/test/test_importlib
parent40b22d0661c45ac350a7252a32ef665b81b1643c (diff)
downloadcpython-27e27f7ee1f366e52cfd576b427e923190b6202e.zip
cpython-27e27f7ee1f366e52cfd576b427e923190b6202e.tar.gz
cpython-27e27f7ee1f366e52cfd576b427e923190b6202e.tar.bz2
Issue #18416: Have importlib.machinery.PathFinder treat '' as the cwd
and stop importlib.machinery.FileFinder treating '' as '.'. Previous PathFinder transformed '' into '.' which led to __file__ for modules imported from the cwd to always be relative paths. This meant the values of the attribute were wrong as soon as the cwd changed. This change now means that as long as the site module is run (which makes all entries in sys.path absolute) then all values for __file__ will also be absolute unless it's for __main__ when specified by file path in a relative way (modules imported by runpy will have an absolute path). Now that PathFinder is no longer treating '' as '.' it only makes sense for FileFinder to stop doing so as well. Now no transformation is performed for the directory given to the __init__ method. Thanks to Madison May for the initial patch.
Diffstat (limited to 'Lib/test/test_importlib')
-rw-r--r--Lib/test/test_importlib/import_/test_path.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/Lib/test/test_importlib/import_/test_path.py b/Lib/test/test_importlib/import_/test_path.py
index d82b7f6..98391be 100644
--- a/Lib/test/test_importlib/import_/test_path.py
+++ b/Lib/test/test_importlib/import_/test_path.py
@@ -82,11 +82,11 @@ class FinderTests(unittest.TestCase):
path = ''
module = '<test module>'
importer = util.mock_modules(module)
- hook = import_util.mock_path_hook(os.curdir, importer=importer)
+ hook = import_util.mock_path_hook(os.getcwd(), importer=importer)
with util.import_state(path=[path], path_hooks=[hook]):
loader = machinery.PathFinder.find_module(module)
self.assertIs(loader, importer)
- self.assertIn(os.curdir, sys.path_importer_cache)
+ self.assertIn(os.getcwd(), sys.path_importer_cache)
def test_None_on_sys_path(self):
# Putting None in sys.path[0] caused an import regression from Python