|
220 | 220 | import _testinternalcapi |
221 | 221 | except ModuleNotFoundError: |
222 | 222 | _testinternalcapi = None |
223 | | -import test._code_definitions as defs |
224 | 223 |
|
225 | 224 | COPY_FREE_VARS = opmap['COPY_FREE_VARS'] |
226 | 225 |
|
@@ -672,6 +671,7 @@ def test_local_kinds(self): |
672 | 671 | VARARGS = CO_FAST_LOCAL | CO_FAST_ARG_VAR | CO_FAST_ARG_POS |
673 | 672 | VARKWARGS = CO_FAST_LOCAL | CO_FAST_ARG_VAR | CO_FAST_ARG_KW |
674 | 673 |
|
| 674 | + import test._code_definitions as defs |
675 | 675 | funcs = { |
676 | 676 | defs.spam_minimal: {}, |
677 | 677 | defs.spam_with_builtins: { |
@@ -897,6 +897,7 @@ def new_var_counts(*, |
897 | 897 | }, |
898 | 898 | } |
899 | 899 |
|
| 900 | + import test._code_definitions as defs |
900 | 901 | funcs = { |
901 | 902 | defs.spam_minimal: new_var_counts(), |
902 | 903 | defs.spam_with_builtins: new_var_counts( |
@@ -1024,70 +1025,55 @@ def new_var_counts(*, |
1024 | 1025 | counts = _testinternalcapi.get_code_var_counts(func.__code__) |
1025 | 1026 | self.assertEqual(counts, expected) |
1026 | 1027 |
|
1027 | | - func = defs.spam_with_globals_and_builtins |
| 1028 | + def func_with_globals_and_builtins(): |
| 1029 | + mod1 = _testinternalcapi |
| 1030 | + mod2 = dis |
| 1031 | + mods = (mod1, mod2) |
| 1032 | + checks = tuple(callable(m) for m in mods) |
| 1033 | + return callable(mod2), tuple(mods), list(mods), checks |
| 1034 | + |
| 1035 | + func = func_with_globals_and_builtins |
1028 | 1036 | with self.subTest(f'{func} code'): |
1029 | 1037 | expected = new_var_counts( |
1030 | | - purelocals=5, |
1031 | | - globalvars=6, |
| 1038 | + purelocals=4, |
| 1039 | + globalvars=5, |
1032 | 1040 | ) |
1033 | 1041 | counts = _testinternalcapi.get_code_var_counts(func.__code__) |
1034 | 1042 | self.assertEqual(counts, expected) |
1035 | 1043 |
|
1036 | 1044 | with self.subTest(f'{func} with own globals and builtins'): |
1037 | 1045 | expected = new_var_counts( |
1038 | | - purelocals=5, |
1039 | | - globalvars=(2, 4), |
| 1046 | + purelocals=4, |
| 1047 | + globalvars=(2, 3), |
1040 | 1048 | ) |
1041 | 1049 | counts = _testinternalcapi.get_code_var_counts(func) |
1042 | 1050 | self.assertEqual(counts, expected) |
1043 | 1051 |
|
1044 | 1052 | with self.subTest(f'{func} without globals'): |
1045 | 1053 | expected = new_var_counts( |
1046 | | - purelocals=5, |
1047 | | - globalvars=(0, 4, 2), |
| 1054 | + purelocals=4, |
| 1055 | + globalvars=(0, 3, 2), |
1048 | 1056 | ) |
1049 | 1057 | counts = _testinternalcapi.get_code_var_counts(func, globalsns={}) |
1050 | 1058 | self.assertEqual(counts, expected) |
1051 | 1059 |
|
1052 | 1060 | with self.subTest(f'{func} without both'): |
1053 | 1061 | expected = new_var_counts( |
1054 | | - purelocals=5, |
1055 | | - globalvars=6, |
| 1062 | + purelocals=4, |
| 1063 | + globalvars=5, |
1056 | 1064 | ) |
1057 | 1065 | counts = _testinternalcapi.get_code_var_counts(func, globalsns={}, |
1058 | 1066 | builtinsns={}) |
1059 | 1067 | self.assertEqual(counts, expected) |
1060 | 1068 |
|
1061 | 1069 | with self.subTest(f'{func} without builtins'): |
1062 | 1070 | expected = new_var_counts( |
1063 | | - purelocals=5, |
1064 | | - globalvars=(2, 0, 4), |
| 1071 | + purelocals=4, |
| 1072 | + globalvars=(2, 0, 3), |
1065 | 1073 | ) |
1066 | 1074 | counts = _testinternalcapi.get_code_var_counts(func, builtinsns={}) |
1067 | 1075 | self.assertEqual(counts, expected) |
1068 | 1076 |
|
1069 | | - @unittest.skipIf(_testinternalcapi is None, "missing _testinternalcapi") |
1070 | | - def test_stateless(self): |
1071 | | - self.maxDiff = None |
1072 | | - |
1073 | | - for func in defs.STATELESS_CODE: |
1074 | | - with self.subTest((func, '(code)')): |
1075 | | - _testinternalcapi.verify_stateless_code(func.__code__) |
1076 | | - for func in defs.STATELESS_FUNCTIONS: |
1077 | | - with self.subTest((func, '(func)')): |
1078 | | - _testinternalcapi.verify_stateless_code(func) |
1079 | | - |
1080 | | - for func in defs.FUNCTIONS: |
1081 | | - if func not in defs.STATELESS_CODE: |
1082 | | - with self.subTest((func, '(code)')): |
1083 | | - with self.assertRaises(Exception): |
1084 | | - _testinternalcapi.verify_stateless_code(func.__code__) |
1085 | | - |
1086 | | - if func not in defs.STATELESS_FUNCTIONS: |
1087 | | - with self.subTest((func, '(func)')): |
1088 | | - with self.assertRaises(Exception): |
1089 | | - _testinternalcapi.verify_stateless_code(func) |
1090 | | - |
1091 | 1077 |
|
1092 | 1078 | def isinterned(s): |
1093 | 1079 | return s is sys.intern(('_' + s + '_')[1:-1]) |
|
0 commit comments