summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/importlib/_bootstrap.py5
-rw-r--r--Lib/test/coding20731.py8
-rw-r--r--Lib/test/test_cmd_line.py23
-rw-r--r--Lib/test/test_site.py9
4 files changed, 36 insertions, 9 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index a531a03..891bd06 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -1134,12 +1134,15 @@ def _setup(sys_module, _imp_module):
def _install(sys_module, _imp_module):
- """Install importlib as the implementation of import."""
+ """Install importers for builtin and frozen modules"""
_setup(sys_module, _imp_module)
sys.meta_path.append(BuiltinImporter)
sys.meta_path.append(FrozenImporter)
+
+def _install_external_importers():
+ """Install importers that require external filesystem access"""
global _bootstrap_external
import _frozen_importlib_external
_bootstrap_external = _frozen_importlib_external
diff --git a/Lib/test/coding20731.py b/Lib/test/coding20731.py
index b0e227a..ca4962e 100644
--- a/Lib/test/coding20731.py
+++ b/Lib/test/coding20731.py
@@ -1,4 +1,4 @@
-#coding:latin1
-
-
-
+#coding:latin1
+
+
+
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py
index 958d282..5f96d61 100644
--- a/Lib/test/test_cmd_line.py
+++ b/Lib/test/test_cmd_line.py
@@ -485,8 +485,29 @@ class CmdLineTest(unittest.TestCase):
cwd=tmpdir)
self.assertEqual(out.strip(), b"ok")
+
+class IgnoreEnvironmentTest(unittest.TestCase):
+
+ def run_ignoring_vars(self, predicate, **env_vars):
+ # Runs a subprocess with -E set, even though we're passing
+ # specific environment variables
+ # Logical inversion to match predicate check to a zero return
+ # code indicating success
+ code = "import sys; sys.stderr.write(str(sys.flags)); sys.exit(not ({}))".format(predicate)
+ return assert_python_ok('-E', '-c', code, **env_vars)
+
+ def test_ignore_PYTHONPATH(self):
+ path = "should_be_ignored"
+ self.run_ignoring_vars("'{}' not in sys.path".format(path),
+ PYTHONPATH=path)
+
+ def test_ignore_PYTHONHASHSEED(self):
+ self.run_ignoring_vars("sys.flags.hash_randomization == 1",
+ PYTHONHASHSEED="0")
+
+
def test_main():
- test.support.run_unittest(CmdLineTest)
+ test.support.run_unittest(CmdLineTest, IgnoreEnvironmentTest)
test.support.reap_children()
if __name__ == "__main__":
diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py
index 3aa46df..0924f01 100644
--- a/Lib/test/test_site.py
+++ b/Lib/test/test_site.py
@@ -183,6 +183,7 @@ class HelperFunctionsTests(unittest.TestCase):
@unittest.skipUnless(site.ENABLE_USER_SITE, "requires access to PEP 370 "
"user-site (site.ENABLE_USER_SITE)")
def test_s_option(self):
+ # (ncoghlan) Change this to use script_helper...
usersite = site.USER_SITE
self.assertIn(usersite, sys.path)
@@ -199,7 +200,7 @@ class HelperFunctionsTests(unittest.TestCase):
if usersite == site.getsitepackages()[0]:
self.assertEqual(rc, 1)
else:
- self.assertEqual(rc, 0)
+ self.assertEqual(rc, 0, "User site still added to path with -s")
env = os.environ.copy()
env["PYTHONNOUSERSITE"] = "1"
@@ -209,14 +210,16 @@ class HelperFunctionsTests(unittest.TestCase):
if usersite == site.getsitepackages()[0]:
self.assertEqual(rc, 1)
else:
- self.assertEqual(rc, 0)
+ self.assertEqual(rc, 0,
+ "User site still added to path with PYTHONNOUSERSITE")
env = os.environ.copy()
env["PYTHONUSERBASE"] = "/tmp"
rc = subprocess.call([sys.executable, '-c',
'import sys, site; sys.exit(site.USER_BASE.startswith("/tmp"))'],
env=env)
- self.assertEqual(rc, 1)
+ self.assertEqual(rc, 1,
+ "User base not set by PYTHONUSERBASE")
def test_getuserbase(self):
site.USER_BASE = None