diff options
author | Steve Dower <steve.dower@microsoft.com> | 2017-02-04 23:19:46 (GMT) |
---|---|---|
committer | Steve Dower <steve.dower@microsoft.com> | 2017-02-04 23:19:46 (GMT) |
commit | 824c6fdfaa79f601fa50b99ff1d20e565cdc4120 (patch) | |
tree | d54f789a3ba9b346041af8ebd8de5e9e6a48a837 /Lib | |
parent | 43fec9b419512d67e94b26f7da24c8392e835517 (diff) | |
parent | 5f9193a6edf1864a243def36ec4d1277054236c6 (diff) | |
download | cpython-824c6fdfaa79f601fa50b99ff1d20e565cdc4120.zip cpython-824c6fdfaa79f601fa50b99ff1d20e565cdc4120.tar.gz cpython-824c6fdfaa79f601fa50b99ff1d20e565cdc4120.tar.bz2 |
Issue #29326: Ignores blank lines in ._pth files (Patch by Alexey Izbyshev)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_site.py | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py index d245fd5..0620b24 100644 --- a/Lib/test/test_site.py +++ b/Lib/test/test_site.py @@ -511,16 +511,30 @@ class StartupImportTests(unittest.TestCase): os.unlink(_pth_file) os.unlink(exe_file) + @classmethod + def _calc_sys_path_for_underpth_nosite(self, sys_prefix, lines): + sys_path = [] + for line in lines: + if not line or line[0] == '#': + continue + abs_path = os.path.abspath(os.path.join(sys_prefix, line)) + sys_path.append(abs_path) + return sys_path + @unittest.skipUnless(sys.platform == 'win32', "only supported on Windows") def test_underpth_nosite_file(self): libpath = os.path.dirname(os.path.dirname(encodings.__file__)) exe_prefix = os.path.dirname(sys.executable) - exe_file = self._create_underpth_exe([ + pth_lines = [ 'fake-path-name', *[libpath for _ in range(200)], + '', '# comment', - 'import site' - ]) + ] + exe_file = self._create_underpth_exe(pth_lines) + sys_path = self._calc_sys_path_for_underpth_nosite( + os.path.dirname(exe_file), + pth_lines) try: env = os.environ.copy() @@ -529,14 +543,11 @@ class StartupImportTests(unittest.TestCase): rc = subprocess.call([exe_file, '-c', 'import sys; sys.exit(sys.flags.no_site and ' 'len(sys.path) > 200 and ' - '%r in sys.path and %r in sys.path and %r not in sys.path)' % ( - os.path.join(sys.prefix, 'fake-path-name'), - libpath, - os.path.join(sys.prefix, 'from-env'), - )], env=env) + 'sys.path == %r)' % sys_path, + ], env=env) finally: self._cleanup_underpth_exe(exe_file) - self.assertEqual(rc, 0) + self.assertTrue(rc, "sys.path is incorrect") @unittest.skipUnless(sys.platform == 'win32', "only supported on Windows") def test_underpth_file(self): @@ -545,23 +556,26 @@ class StartupImportTests(unittest.TestCase): exe_file = self._create_underpth_exe([ 'fake-path-name', *[libpath for _ in range(200)], + '', '# comment', 'import site' ]) + sys_prefix = os.path.dirname(exe_file) try: 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)' % ( - os.path.join(sys.prefix, 'fake-path-name'), + '%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'), + os.path.join(sys_prefix, 'from-env'), )], env=env) finally: self._cleanup_underpth_exe(exe_file) - self.assertEqual(rc, 0) + self.assertTrue(rc, "sys.path is incorrect") if __name__ == "__main__": |