summaryrefslogtreecommitdiff
path: root/Lib/test/test_site.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_site.py')
-rw-r--r--Lib/test/test_site.py37
1 files changed, 27 insertions, 10 deletions
diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py
index da20a3d21a..d2fbb7ba2e 100644
--- a/Lib/test/test_site.py
+++ b/Lib/test/test_site.py
@@ -75,7 +75,7 @@ class HelperFunctionsTests(unittest.TestCase):
def test_init_pathinfo(self):
dir_set = site._init_pathinfo()
for entry in [site.makepath(path)[1] for path in sys.path
- if path and os.path.isdir(path)]:
+ if path and os.path.exists(path)]:
self.assertIn(entry, dir_set,
"%s from sys.path not found in set returned "
"by _init_pathinfo(): %s" % (entry, dir_set))
@@ -138,10 +138,8 @@ class HelperFunctionsTests(unittest.TestCase):
re.escape(os.path.join(pth_dir, pth_fn)))
# XXX: ditto previous XXX comment.
self.assertRegex(err_out.getvalue(), 'Traceback')
- self.assertRegex(err_out.getvalue(), 'ImportError')
+ self.assertRegex(err_out.getvalue(), 'ModuleNotFoundError')
- @unittest.skipIf(sys.platform == "win32", "Windows does not raise an "
- "error for file paths containing null characters")
def test_addpackage_import_bad_pth_file(self):
# Issue 5258
pth_dir, pth_fn = self.make_pth("abc\x00def\n")
@@ -243,13 +241,14 @@ class HelperFunctionsTests(unittest.TestCase):
self.assertEqual(len(dirs), 2)
wanted = os.path.join('/Library',
sysconfig.get_config_var("PYTHONFRAMEWORK"),
- sys.version[:3],
+ '%d.%d' % sys.version_info[:2],
'site-packages')
self.assertEqual(dirs[1], wanted)
elif os.sep == '/':
# OS X non-framwework builds, Linux, FreeBSD, etc
self.assertEqual(len(dirs), 1)
- wanted = os.path.join('xoxo', 'lib', 'python' + sys.version[:3],
+ wanted = os.path.join('xoxo', 'lib',
+ 'python%d.%d' % sys.version_info[:2],
'site-packages')
self.assertEqual(dirs[0], wanted)
else:
@@ -446,10 +445,9 @@ class StartupImportTests(unittest.TestCase):
popen = subprocess.Popen([sys.executable, '-I', '-v', '-c',
'import sys; print(set(sys.modules))'],
stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
+ stderr=subprocess.PIPE,
+ encoding='utf-8')
stdout, stderr = popen.communicate()
- stdout = stdout.decode('utf-8')
- stderr = stderr.decode('utf-8')
modules = eval(stdout)
self.assertIn('site', modules)
@@ -469,7 +467,26 @@ class StartupImportTests(unittest.TestCase):
'heapq', 'itertools', 'keyword', 'operator',
'reprlib', 'types', 'weakref'
}.difference(sys.builtin_module_names)
- self.assertFalse(modules.intersection(collection_mods), stderr)
+ # http://bugs.python.org/issue28095
+ if sys.platform != 'darwin':
+ self.assertFalse(modules.intersection(collection_mods), stderr)
+
+ def test_startup_interactivehook(self):
+ r = subprocess.Popen([sys.executable, '-c',
+ 'import sys; sys.exit(hasattr(sys, "__interactivehook__"))']).wait()
+ self.assertTrue(r, "'__interactivehook__' not added by site")
+
+ def test_startup_interactivehook_isolated(self):
+ # issue28192 readline is not automatically enabled in isolated mode
+ r = subprocess.Popen([sys.executable, '-I', '-c',
+ 'import sys; sys.exit(hasattr(sys, "__interactivehook__"))']).wait()
+ self.assertFalse(r, "'__interactivehook__' added in isolated mode")
+
+ def test_startup_interactivehook_isolated_explicit(self):
+ # issue28192 readline can be explicitly enabled in isolated mode
+ r = subprocess.Popen([sys.executable, '-I', '-c',
+ 'import site, sys; site.enablerlcompleter(); sys.exit(hasattr(sys, "__interactivehook__"))']).wait()
+ self.assertTrue(r, "'__interactivehook__' not added by enablerlcompleter()")
if __name__ == "__main__":