Skip to content

Commit 0b0c56d

Browse files
committed
Update tests, add a few more cases
1 parent 0226aa1 commit 0b0c56d

File tree

4 files changed

+18
-21
lines changed

4 files changed

+18
-21
lines changed

Lib/test/test_cmd_line.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,23 +1159,19 @@ def test_cpu_count_default(self):
11591159
self.assertEqual(self.res2int(res), (os.cpu_count(), os.process_cpu_count()))
11601160

11611161
def test_import_time(self):
1162-
code = "import os"
1163-
res = assert_python_ok('-X', 'importtime', '-c', code)
1164-
res_err = res.err.decode("utf-8")
1165-
self.assertRegex(res_err, r"import time: \s*\d+ \| \s*\d+ \| \s*os")
1166-
self.assertNotRegex(res_err, r"import time: cached\s* \| cached\s* \| os")
1167-
1168-
code = "import os"
1169-
res = assert_python_ok('-X', 'importtime=true', '-c', code)
1170-
res_err = res.err.decode("utf-8")
1171-
self.assertRegex(res_err, r"import time: \s*\d+ \| \s*\d+ \| \s*os")
1172-
self.assertNotRegex(res_err, r"import time: cached\s* \| cached\s* \| os")
1173-
1174-
code = "import os; import os"
1162+
# os is not imported at startup
1163+
code = 'import os; import os'
1164+
1165+
for case in 'importtime', 'importtime=1', 'importtime=true':
1166+
res = assert_python_ok('-X', case, '-c', code)
1167+
res_err = res.err.decode('utf-8')
1168+
self.assertRegex(res_err, r'import time: \s*\d+ \| \s*\d+ \| \s*os')
1169+
self.assertNotRegex(res_err, r'import time: cached\s* \| cached\s* \| os')
1170+
11751171
res = assert_python_ok('-X', 'importtime=2', '-c', code)
1176-
res_err = res.err.decode("utf-8")
1177-
self.assertRegex(res_err, r"import time: \s*\d+ \| \s*\d+ \| \s*os")
1178-
self.assertRegex(res_err, r"import time: cached\s* \| cached\s* \| os")
1172+
res_err = res.err.decode('utf-8')
1173+
self.assertRegex(res_err, r'import time: \s*\d+ \| \s*\d+ \| \s*os')
1174+
self.assertRegex(res_err, r'import time: cached\s* \| cached\s* \| os')
11791175

11801176
assert_python_failure('-X', 'importtime=-1', '-c', code)
11811177
assert_python_failure('-X', 'importtime=3', '-c', code)

Lib/test/test_embed.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ def test_init_from_config(self):
998998
'hash_seed': 123,
999999
'tracemalloc': 2,
10001000
'perf_profiling': 0,
1001-
'import_time': 0,
1001+
'import_time': 2,
10021002
'code_debug_ranges': False,
10031003
'show_ref_count': True,
10041004
'malloc_stats': True,
@@ -1064,7 +1064,7 @@ def test_init_compat_env(self):
10641064
'use_hash_seed': True,
10651065
'hash_seed': 42,
10661066
'tracemalloc': 2,
1067-
'import_time': 0,
1067+
'import_time': 1,
10681068
'code_debug_ranges': False,
10691069
'malloc_stats': True,
10701070
'inspect': True,
@@ -1100,7 +1100,7 @@ def test_init_python_env(self):
11001100
'use_hash_seed': True,
11011101
'hash_seed': 42,
11021102
'tracemalloc': 2,
1103-
'import_time': 0,
1103+
'import_time': 1,
11041104
'code_debug_ranges': False,
11051105
'malloc_stats': True,
11061106
'inspect': True,

Lib/test/test_support.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ def test_args_from_interpreter_flags(self):
561561
['-Wignore', '-X', 'dev'],
562562
['-X', 'faulthandler'],
563563
['-X', 'importtime'],
564+
['-X', 'importtime=2'],
564565
['-X', 'showrefcount'],
565566
['-X', 'tracemalloc'],
566567
['-X', 'tracemalloc=3'],

Programs/_testembed.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,8 @@ static int test_init_from_config(void)
651651
putenv("PYTHONTRACEMALLOC=0");
652652
config.tracemalloc = 2;
653653

654-
putenv("PYTHONPROFILEIMPORTTIME=0");
655-
config.import_time = 0;
654+
putenv("PYTHONPROFILEIMPORTTIME=1");
655+
config.import_time = 2;
656656

657657
putenv("PYTHONNODEBUGRANGES=0");
658658
config.code_debug_ranges = 0;

0 commit comments

Comments
 (0)