8000 gh-119574: Add some missing environment variables to '--help-env'. by devdanzin · Pull Request #120006 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-119574: Add some missing environment variables to '--help-env'. #120006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 18, 2024
Merged
Prev Previous commit
Next Next commit
Add some tests for the env vars newly added to '--help-env'.
  • Loading branch information
devdanzin committed Jun 8, 2024
commit e51a266febacf56c3741de538973f09445ff2ca4
68 changes: 68 additions & 0 deletions Lib/test/test_cmd_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import subprocess
import sys
import sysconfig
import tempfile
import textwrap
import unittest
Expand Down Expand Up @@ -912,6 +913,73 @@ def test_python_gil(self):
self.assertEqual(proc.stdout.rstrip(), expected)
self.assertEqual(proc.stderr, '')

def test_python_asyncio_debug(self):
code = "import asyncio; print(asyncio.get_event_loop().get_debug())"
rc, out, err = assert_python_ok('-c', code, PYTHONASYNCIODEBUG='1')
self.assertIn(b'True', out)

@unittest.skipUnless(sysconfig.get_config_var('Py_TRACE_REFS'), "Requires --with-trace-refs build option")
def test_python_dump_refs(self):
code = 'import sys; sys._clear_type_cache()'
rc, out, err = assert_python_ok('-c', code, PYTHONDUMPREFS='1')
self.assertEqual(rc, 0)

@unittest.skipUnless(sysconfig.get_config_var('Py_TRACE_REFS'), "Requires --with-trace-refs build option")
def test_python_dump_refs_file(self):
with tempfile.NamedTemporaryFile() as dump_file:
code = 'import sys; sys._clear_type_cache()'
rc, out, err = assert_python_ok('-c', code, PYTHONDUMPREFSFILE=dump_file.name)
self.assertEqual(rc, 0)
with open(dump_file.name, 'r') as file:
contents = file.read()
self.assertIn('Dumping', contents)

@unittest.skipUnless(sys.platform == 'darwin', 'PYTHONEXECUTABLE only works on macOS')
def test_python_executable(self):
code = 'import sys; print(sys.executable)'
expected = "/busr/bbin/bpython"
rc, out, err = assert_python_ok('-c', code, PYTHONEXECUTABLE=expected)
self.assertIn(expected.encode(), out)

@unittest.skipUnless(sys.platform == 'win32', 'Test only applicable on Windows')
def test_python_legacy_windows_fs_encoding(self):
code = "import sys; print(sys.getfilesystemencoding())"
expected = 'mbcs'
rc, out, err = assert_python_ok('-c', code, PYTHONLEGACYWINDOWSFSENCODING='1')
self.assertIn(expected.encode(), out)

@unittest.skipUnless(sys.platform == 'win32', 'Test only applicable on Windows')
def test_python_legacy_windows_stdio(self):
code = "import sys; print(sys.stdin.encoding, sys.stdout.encoding)"
expected = 'cp'
rc, out, err = assert_python_ok('-c', code, PYTHONLEGACYWINDOWSSTDIO='1')
self.assertIn(expected.encode(), out)

def test_python_malloc_stats(self):
code = "pass"
rc, out, err = assert_python_ok('-c', code, PYTHONMALLOCSTATS='1')
self.assertIn(b'Small block threshold', err)

def test_python_user_base(self):
code = "import site; print(site.USER_BASE)"
expected = "/custom/userbase"
rc, out, err = assert_python_ok('-c', code, PYTHONUSERBASE=expected)
self.assertIn(expected.encode(), out)

def test_python_basic_repl(self):
# Currently this only tests that the env var is set
code = "import os; print('PYTHON_BASIC_REPL' in os.environ)"
expected = "True"
rc, out, err = assert_python_ok('-c', code, PYTHON_BASIC_REPL='1')
self.assertIn(expected.encode(), out)

@unittest.skipUnless(sysconfig.get_config_var('HAVE_PERF_TRAMPOLINE'), "Requires HAVE_PERF_TRAMPOLINE support")
def test_python_perf_jit_support(self):
code = "import sys; print(sys.is_stack_trampoline_active())"
expected = "True"
rc, out, err = assert_python_ok('-c', code, PYTHON_PERF_JIT_SUPPORT='1')
self.assertIn(expected.encode(), out)

@unittest.skipUnless(sys.platform == 'win32',
'bpo-32457 only applies on Windows')
def test_argv0_normalization(self):
Expand Down
0