summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@microsoft.com>2016-10-29 15:50:31 (GMT)
committerSteve Dower <steve.dower@microsoft.com>2016-10-29 15:50:31 (GMT)
commit1da055ee0dd11b8c16644c27381a2b20bf0ff205 (patch)
tree812dc70c0451b27c1cf1113c943da1cc837492fa
parent0eacef3ecf84a2c41432f7a8be6304ab6427c35f (diff)
downloadcpython-1da055ee0dd11b8c16644c27381a2b20bf0ff205.zip
cpython-1da055ee0dd11b8c16644c27381a2b20bf0ff205.tar.gz
cpython-1da055ee0dd11b8c16644c27381a2b20bf0ff205.tar.bz2
Makes test_underpth* tests more robust by copying the executable.
-rw-r--r--Lib/test/test_site.py73
-rw-r--r--PCbuild/rt.bat3
2 files changed, 51 insertions, 25 deletions
diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py
index 5aedbdb..d245fd5 100644
--- a/Lib/test/test_site.py
+++ b/Lib/test/test_site.py
@@ -14,6 +14,7 @@ import re
import encodings
import urllib.request
import urllib.error
+import shutil
import subprocess
import sysconfig
from copy import copy
@@ -488,22 +489,44 @@ class StartupImportTests(unittest.TestCase):
'import site, sys; site.enablerlcompleter(); sys.exit(hasattr(sys, "__interactivehook__"))']).wait()
self.assertTrue(r, "'__interactivehook__' not added by enablerlcompleter()")
- @unittest.skipUnless(sys.platform == 'win32', "only supported on Windows")
- def test_underpth_nosite_file(self):
- _pth_file = os.path.splitext(sys.executable)[0] + '._pth'
+ @classmethod
+ def _create_underpth_exe(self, lines):
+ exe_file = os.path.join(os.getenv('TEMP'), os.path.split(sys.executable)[1])
+ shutil.copy(sys.executable, exe_file)
+
+ _pth_file = os.path.splitext(exe_file)[0] + '._pth'
try:
- libpath = os.path.dirname(os.path.dirname(encodings.__file__))
with open(_pth_file, 'w') as f:
- print('fake-path-name', file=f)
- # Ensure the generated path is very long so that buffer
- # resizing in getpathp.c is exercised
- for _ in range(200):
- print(libpath, file=f)
- print('# comment', file=f)
+ for line in lines:
+ print(line, file=f)
+ return exe_file
+ except:
+ os.unlink(_pth_file)
+ os.unlink(exe_file)
+ raise
+
+ @classmethod
+ def _cleanup_underpth_exe(self, exe_file):
+ _pth_file = os.path.splitext(exe_file)[0] + '._pth'
+ os.unlink(_pth_file)
+ os.unlink(exe_file)
+
+ @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([
+ 'fake-path-name',
+ *[libpath for _ in range(200)],
+ '# comment',
+ 'import site'
+ ])
+ try:
env = os.environ.copy()
env['PYTHONPATH'] = 'from-env'
- rc = subprocess.call([sys.executable, '-c',
+ env['PATH'] = '{};{}'.format(exe_prefix, os.getenv('PATH'))
+ 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)' % (
@@ -511,34 +534,34 @@ class StartupImportTests(unittest.TestCase):
libpath,
os.path.join(sys.prefix, 'from-env'),
)], env=env)
- self.assertEqual(rc, 0)
finally:
- os.unlink(_pth_file)
+ self._cleanup_underpth_exe(exe_file)
+ self.assertEqual(rc, 0)
@unittest.skipUnless(sys.platform == 'win32', "only supported on Windows")
def test_underpth_file(self):
- _pth_file = os.path.splitext(sys.executable)[0] + '._pth'
+ 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'
+ ])
try:
- libpath = os.path.dirname(os.path.dirname(encodings.__file__))
- with open(_pth_file, 'w') as f:
- print('fake-path-name', file=f)
- for _ in range(200):
- print(libpath, file=f)
- print('# comment', file=f)
- print('import site', file=f)
-
env = os.environ.copy()
env['PYTHONPATH'] = 'from-env'
- rc = subprocess.call([sys.executable, '-c',
+ 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'),
libpath,
os.path.join(sys.prefix, 'from-env'),
)], env=env)
- self.assertEqual(rc, 0)
finally:
- os.unlink(_pth_file)
+ self._cleanup_underpth_exe(exe_file)
+ self.assertEqual(rc, 0)
if __name__ == "__main__":
diff --git a/PCbuild/rt.bat b/PCbuild/rt.bat
index 7d4d071..3582672 100644
--- a/PCbuild/rt.bat
+++ b/PCbuild/rt.bat
@@ -48,6 +48,9 @@ if defined qmode goto Qmode
echo Deleting .pyc/.pyo files ...
"%exe%" "%pcbuild%rmpyc.py"
+echo Cleaning _pth files ...
+if exist %prefix%*._pth del %prefix%*._pth
+
echo on
%cmd%
@echo off