summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_site.py
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@python.org>2021-04-07 00:02:07 (GMT)
committerGitHub <noreply@github.com>2021-04-07 00:02:07 (GMT)
commit04732ca993fa077a8b9640cc77fb2f152339585a (patch)
treee5aec9caf5770fd1aff72efc13640712155b8cbe /Lib/test/test_site.py
parentb57e045320d1d2a70eab236b7d31a3ebb75037c3 (diff)
downloadcpython-04732ca993fa077a8b9640cc77fb2f152339585a.zip
cpython-04732ca993fa077a8b9640cc77fb2f152339585a.tar.gz
cpython-04732ca993fa077a8b9640cc77fb2f152339585a.tar.bz2
bpo-43105: Importlib now resolves relative paths when creating module spec objects from file locations (GH-25121)
Diffstat (limited to 'Lib/test/test_site.py')
-rw-r--r--Lib/test/test_site.py50
1 files changed, 1 insertions, 49 deletions
diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py
index 6060288..9b4ab42 100644
--- a/Lib/test/test_site.py
+++ b/Lib/test/test_site.py
@@ -173,6 +173,7 @@ class HelperFunctionsTests(unittest.TestCase):
pth_dir, pth_fn = self.make_pth("abc\x00def\n")
with captured_stderr() as err_out:
self.assertFalse(site.addpackage(pth_dir, pth_fn, set()))
+ self.maxDiff = None
self.assertEqual(err_out.getvalue(), "")
for path in sys.path:
if isinstance(path, str):
@@ -408,55 +409,6 @@ class ImportSideEffectTests(unittest.TestCase):
"""Restore sys.path"""
sys.path[:] = self.sys_path
- def test_abs_paths(self):
- # Make sure all imported modules have their __file__ and __cached__
- # attributes as absolute paths. Arranging to put the Lib directory on
- # PYTHONPATH would cause the os module to have a relative path for
- # __file__ if abs_paths() does not get run. sys and builtins (the
- # only other modules imported before site.py runs) do not have
- # __file__ or __cached__ because they are built-in.
- try:
- parent = os.path.relpath(os.path.dirname(os.__file__))
- cwd = os.getcwd()
- except ValueError:
- # Failure to get relpath probably means we need to chdir
- # to the same drive.
- cwd, parent = os.path.split(os.path.dirname(os.__file__))
- with change_cwd(cwd):
- env = os.environ.copy()
- env['PYTHONPATH'] = parent
- code = ('import os, sys',
- # use ASCII to avoid locale issues with non-ASCII directories
- 'os_file = os.__file__.encode("ascii", "backslashreplace")',
- r'sys.stdout.buffer.write(os_file + b"\n")',
- 'os_cached = os.__cached__.encode("ascii", "backslashreplace")',
- r'sys.stdout.buffer.write(os_cached + b"\n")')
- command = '\n'.join(code)
- # First, prove that with -S (no 'import site'), the paths are
- # relative.
- proc = subprocess.Popen([sys.executable, '-S', '-c', command],
- env=env,
- stdout=subprocess.PIPE)
- stdout, stderr = proc.communicate()
-
- self.assertEqual(proc.returncode, 0)
- os__file__, os__cached__ = stdout.splitlines()[:2]
- self.assertFalse(os.path.isabs(os__file__))
- self.assertFalse(os.path.isabs(os__cached__))
- # Now, with 'import site', it works.
- proc = subprocess.Popen([sys.executable, '-c', command],
- env=env,
- stdout=subprocess.PIPE)
- stdout, stderr = proc.communicate()
- self.assertEqual(proc.returncode, 0)
- os__file__, os__cached__ = stdout.splitlines()[:2]
- self.assertTrue(os.path.isabs(os__file__),
- "expected absolute path, got {}"
- .format(os__file__.decode('ascii')))
- self.assertTrue(os.path.isabs(os__cached__),
- "expected absolute path, got {}"
- .format(os__cached__.decode('ascii')))
-
def test_abs_paths_cached_None(self):
"""Test for __cached__ is None.