Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update tests, add a few more cases
  • Loading branch information
AA-Turner committed May 5, 2025
commit 414e61daf26ae10c48f80f2082b7b0713bd6398b
28 changes: 12 additions & 16 deletions Lib/test/test_cmd_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -1159,23 +1159,19 @@ def test_cpu_count_default(self):
self.assertEqual(self.res2int(res), (os.cpu_count(), os.process_cpu_count()))

def test_import_time(self):
code = "import os"
res = assert_python_ok('-X', 'importtime', '-c', code)
res_err = res.err.decode("utf-8")
self.assertRegex(res_err, r"import time: \s*\d+ \| \s*\d+ \| \s*os")
self.assertNotRegex(res_err, r"import time: cached\s* \| cached\s* \| os")

code = "import os"
res = assert_python_ok('-X', 'importtime=true', '-c', code)
res_err = res.err.decode("utf-8")
self.assertRegex(res_err, r"import time: \s*\d+ \| \s*\d+ \| \s*os")
self.assertNotRegex(res_err, r"import time: cached\s* \| cached\s* \| os")

code = "import os; import os"
# os is not imported at startup
code = 'import os; import os'

for case in 'importtime', 'importtime=1', 'importtime=true':
res = assert_python_ok('-X', case, '-c', code)
res_err = res.err.decode('utf-8')
self.assertRegex(res_err, r'import time: \s*\d+ \| \s*\d+ \| \s*os')
self.assertNotRegex(res_err, r'import time: cached\s* \| cached\s* \| os')

res = assert_python_ok('-X', 'importtime=2', '-c', code)
res_err = res.err.decode("utf-8")
self.assertRegex(res_err, r"import time: \s*\d+ \| \s*\d+ \| \s*os")
self.assertRegex(res_err, r"import time: cached\s* \| cached\s* \| os")
res_err = res.err.decode('utf-8')
self.assertRegex(res_err, r'import time: \s*\d+ \| \s*\d+ \| \s*os')
self.assertRegex(res_err, r'import time: cached\s* \| cached\s* \| os')

assert_python_failure('-X', 'importtime=-1', '-c', code)
assert_python_failure('-X', 'importtime=3', '-c', code)
Expand Down
6 changes: 3 additions & 3 deletions Lib/test/test_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ def test_init_from_config(self):
'hash_seed': 123,
'tracemalloc': 2,
'perf_profiling': 0,
'import_time': 0,
'import_time': 2,
'code_debug_ranges': False,
'show_ref_count': True,
'malloc_stats': True,
Expand Down Expand Up @@ -1064,7 +1064,7 @@ def test_init_compat_env(self):
'use_hash_seed': True,
'hash_seed': 42,
'tracemalloc': 2,
'import_time': 0,
'import_time': 1,
'code_debug_ranges': False,
'malloc_stats': True,
'inspect': True,
Expand Down Expand Up @@ -1100,7 +1100,7 @@ def test_init_python_env(self):
'use_hash_seed': True,
'hash_seed': 42,
'tracemalloc': 2,
'import_time': 0,
'import_time': 1,
'code_debug_ranges': False,
'malloc_stats': True,
'inspect': True,
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ def test_args_from_interpreter_flags(self):
['-Wignore', '-X', 'dev'],
['-X', 'faulthandler'],
['-X', 'importtime'],
['-X', 'importtime=2'],
['-X', 'showrefcount'],
['-X', 'tracemalloc'],
['-X', 'tracemalloc=3'],
Expand Down
4 changes: 2 additions & 2 deletions Programs/_testembed.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,8 @@ static int test_init_from_config(void)
putenv("PYTHONTRACEMALLOC=0");
config.tracemalloc = 2;

putenv("PYTHONPROFILEIMPORTTIME=0");
config.import_time = 0;
putenv("PYTHONPROFILEIMPORTTIME=1");
config.import_time = 2;

putenv("PYTHONNODEBUGRANGES=0");
config.code_debug_ranges = 0;
Expand Down