MCPcopy Index your code
hub / github.com/RustPython/RustPython / do_test_with_pip

Method do_test_with_pip

Lib/test/test_venv.py:937–1031  ·  view source on GitHub ↗
(self, system_site_packages)

Source from the content-addressed store, hash-verified

935 self.assertTrue(os.path.exists(os.devnull))
936
937 def do_test_with_pip(self, system_site_packages):
938 rmtree(self.env_dir)
939 with EnvironmentVarGuard() as envvars:
940 # pip's cross-version compatibility may trigger deprecation
941 # warnings in current versions of Python. Ensure related
942 # environment settings don't cause venv to fail.
943 envvars["PYTHONWARNINGS"] = "ignore"
944 # ensurepip is different enough from a normal pip invocation
945 # that we want to ensure it ignores the normal pip environment
946 # variable settings. We set PIP_NO_INSTALL here specifically
947 # to check that ensurepip (and hence venv) ignores it.
948 # See http://bugs.python.org/issue19734
949 envvars["PIP_NO_INSTALL"] = "1"
950 # Also check that we ignore the pip configuration file
951 # See http://bugs.python.org/issue20053
952 with tempfile.TemporaryDirectory() as home_dir:
953 envvars["HOME"] = home_dir
954 bad_config = "[global]\nno-install=1"
955 # Write to both config file names on all platforms to reduce
956 # cross-platform variation in test code behaviour
957 win_location = ("pip", "pip.ini")
958 posix_location = (".pip", "pip.conf")
959 # Skips win_location due to http://bugs.python.org/issue20541
960 for dirname, fname in (posix_location,):
961 dirpath = os.path.join(home_dir, dirname)
962 os.mkdir(dirpath)
963 fpath = os.path.join(dirpath, fname)
964 with open(fpath, 'w') as f:
965 f.write(bad_config)
966
967 # Actually run the create command with all that unhelpful
968 # config in place to ensure we ignore it
969 with self.nicer_error():
970 self.run_with_capture(venv.create, self.env_dir,
971 system_site_packages=system_site_packages,
972 with_pip=True)
973 # Ensure pip is available in the virtual environment
974 # Ignore DeprecationWarning since pip code is not part of Python
975 out, err = check_output([self.envpy(real_env_dir=True),
976 '-W', 'ignore::DeprecationWarning',
977 '-W', 'ignore::ImportWarning', '-I',
978 '-m', 'pip', '--version'])
979 # We force everything to text, so unittest gives the detailed diff
980 # if we get unexpected results
981 err = err.decode("latin-1") # Force to text, prevent decoding errors
982 self.assertEqual(err, "")
983 out = out.decode("latin-1") # Force to text, prevent decoding errors
984 expected_version = "pip {}".format(ensurepip.version())
985 self.assertEqual(out[:len(expected_version)], expected_version)
986 env_dir = os.fsencode(self.env_dir).decode("latin-1")
987 self.assertIn(env_dir, out)
988
989 # http://bugs.python.org/issue19728
990 # Check the private uninstall command provided for the Windows
991 # installers works (at least in a virtual environment)
992 with EnvironmentVarGuard() as envvars:
993 with self.nicer_error():
994 # It seems ensurepip._uninstall calls subprocesses which do not

Callers 1

test_with_pipMethod · 0.95

Calls 15

nicer_errorMethod · 0.95
rmtreeFunction · 0.90
EnvironmentVarGuardClass · 0.90
lenFunction · 0.85
run_with_captureMethod · 0.80
envpyMethod · 0.80
fsencodeMethod · 0.80
assertInMethod · 0.80
check_outputFunction · 0.70
openFunction · 0.50
joinMethod · 0.45

Tested by

no test coverage detected