MCPcopy Index your code
hub / github.com/python/cpython / _run_repl_globals_test

Method _run_repl_globals_test

Lib/test/test_pyrepl/test_pyrepl.py:1928–1979  ·  view source on GitHub ↗
(self, expectations, *, as_file=False, as_module=False, pythonstartup=False)

Source from the content-addressed store, hash-verified

1926
1927 @force_not_colorized
1928 def _run_repl_globals_test(self, expectations, *, as_file=False, as_module=False, pythonstartup=False):
1929 clean_env = make_clean_env()
1930 clean_env["NO_COLOR"] = "1" # force_not_colorized doesn't touch subprocesses
1931
1932 with tempfile.TemporaryDirectory() as td:
1933 blue = pathlib.Path(td) / "blue"
1934 blue.mkdir()
1935 mod = blue / "calx.py"
1936 mod.write_text("FOO = 42", encoding="utf-8")
1937 startup = blue / "startup.py"
1938 startup.write_text("BAR = 64", encoding="utf-8")
1939 commands = [
1940 "print(f'^{" + var + "=}')" for var in expectations
1941 ] + ["exit()"]
1942 if pythonstartup:
1943 clean_env["PYTHONSTARTUP"] = str(startup)
1944 if as_file and as_module:
1945 self.fail("as_file and as_module are mutually exclusive")
1946 elif as_file:
1947 output, exit_code = self.run_repl(
1948 commands,
1949 cmdline_args=[str(mod)],
1950 env=clean_env,
1951 skip=True,
1952 )
1953 elif as_module:
1954 output, exit_code = self.run_repl(
1955 commands,
1956 cmdline_args=["-m", "blue.calx"],
1957 env=clean_env,
1958 cwd=td,
1959 skip=True,
1960 )
1961 else:
1962 output, exit_code = self.run_repl(
1963 commands,
1964 cmdline_args=[],
1965 env=clean_env,
1966 cwd=td,
1967 skip=True,
1968 )
1969
1970 self.assertEqual(exit_code, 0)
1971 for var, expected in expectations.items():
1972 with self.subTest(var=var, expected=expected):
1973 if m := re.search(rf"\^{var}=(.+?)[\r\n]", output):
1974 self._assertMatchOK(var, expected, actual=m.group(1))
1975 else:
1976 self.fail(f"{var}= not found in output: {output!r}\n\n{output}")
1977
1978 self.assertNotIn("Exception", output)
1979 self.assertNotIn("Traceback", output)
1980
1981 def test_globals_initialized_as_default(self):
1982 expectations = {

Calls 13

_assertMatchOKMethod · 0.95
make_clean_envFunction · 0.90
strFunction · 0.85
assertNotInMethod · 0.80
mkdirMethod · 0.45
write_textMethod · 0.45
failMethod · 0.45
run_replMethod · 0.45
assertEqualMethod · 0.45
itemsMethod · 0.45
subTestMethod · 0.45
searchMethod · 0.45

Tested by

no test coverage detected