summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_site.py
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@python.org>2020-07-15 21:56:49 (GMT)
committerGitHub <noreply@github.com>2020-07-15 21:56:49 (GMT)
commit936a66094591dc0e67d4a60c170148bb700ec016 (patch)
treebc7baca1fdac8311369908c55f45f213a7fadb32 /Lib/test/test_site.py
parentaf4eda46d1538b1da700a86588bdb94b0a4d1ff2 (diff)
downloadcpython-936a66094591dc0e67d4a60c170148bb700ec016.zip
cpython-936a66094591dc0e67d4a60c170148bb700ec016.tar.gz
cpython-936a66094591dc0e67d4a60c170148bb700ec016.tar.bz2
bpo-41304: Ensure python3x._pth is loaded on Windows (GH-21495)
Diffstat (limited to 'Lib/test/test_site.py')
-rw-r--r--Lib/test/test_site.py36
1 files changed, 34 insertions, 2 deletions
diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py
index 9751c64..ec86c64 100644
--- a/Lib/test/test_site.py
+++ b/Lib/test/test_site.py
@@ -598,12 +598,19 @@ class StartupImportTests(unittest.TestCase):
@unittest.skipUnless(sys.platform == 'win32', "only supported on Windows")
class _pthFileTests(unittest.TestCase):
- def _create_underpth_exe(self, lines):
+ def _create_underpth_exe(self, lines, exe_pth=True):
+ import _winapi
temp_dir = tempfile.mkdtemp()
self.addCleanup(test.support.rmtree, temp_dir)
exe_file = os.path.join(temp_dir, os.path.split(sys.executable)[1])
+ dll_src_file = _winapi.GetModuleFileName(sys.dllhandle)
+ dll_file = os.path.join(temp_dir, os.path.split(dll_src_file)[1])
shutil.copy(sys.executable, exe_file)
- _pth_file = os.path.splitext(exe_file)[0] + '._pth'
+ shutil.copy(dll_src_file, dll_file)
+ if exe_pth:
+ _pth_file = os.path.splitext(exe_file)[0] + '._pth'
+ else:
+ _pth_file = os.path.splitext(dll_file)[0] + '._pth'
with open(_pth_file, 'w') as f:
for line in lines:
print(line, file=f)
@@ -671,5 +678,30 @@ class _pthFileTests(unittest.TestCase):
self.assertTrue(rc, "sys.path is incorrect")
+ def test_underpth_dll_file(self):
+ libpath = os.path.dirname(os.path.dirname(encodings.__file__))
+ exe_prefix = os.path.dirname(sys.executable)
+ exe_file = self._create_underpth_exe([
+ 'fake-path-name',
+ *[libpath for _ in range(200)],
+ '',
+ '# comment',
+ 'import site'
+ ], exe_pth=False)
+ sys_prefix = os.path.dirname(exe_file)
+ env = os.environ.copy()
+ env['PYTHONPATH'] = 'from-env'
+ env['PATH'] = '{};{}'.format(exe_prefix, os.getenv('PATH'))
+ rc = subprocess.call([exe_file, '-c',
+ 'import sys; sys.exit(not sys.flags.no_site and '
+ '%r in sys.path and %r in sys.path and %r not in sys.path and '
+ 'all("\\r" not in p and "\\n" not in p for p in sys.path))' % (
+ os.path.join(sys_prefix, 'fake-path-name'),
+ libpath,
+ os.path.join(sys_prefix, 'from-env'),
+ )], env=env)
+ self.assertTrue(rc, "sys.path is incorrect")
+
+
if __name__ == "__main__":
unittest.main()