|
3 | 3 | import unittest
|
4 | 4 | import dis
|
5 | 5 | import io
|
6 |
| -from _testinternalcapi import compiler_codegen, optimize_cfg, assemble_code_object |
| 6 | +try: |
| 7 | + import _testinternalcapi |
| 8 | +except ImportError: |
| 9 | + _testinternalcapi = None |
7 | 10 |
|
8 | 11 | _UNSPECIFIED = object()
|
9 | 12 |
|
@@ -133,23 +136,26 @@ def complete_insts_info(self, insts):
|
133 | 136 | return res
|
134 | 137 |
|
135 | 138 |
|
| 139 | +@unittest.skipIf(_testinternalcapi is None, "requires _testinternalcapi") |
136 | 140 | class CodegenTestCase(CompilationStepTestCase):
|
137 | 141 |
|
138 | 142 | def generate_code(self, ast):
|
139 |
| - insts, _ = compiler_codegen(ast, "my_file.py", 0) |
| 143 | + insts, _ = _testinternalcapi.compiler_codegen(ast, "my_file.py", 0) |
140 | 144 | return insts
|
141 | 145 |
|
142 | 146 |
|
| 147 | +@unittest.skipIf(_testinternalcapi is None, "requires _testinternalcapi") |
143 | 148 | class CfgOptimizationTestCase(CompilationStepTestCase):
|
144 | 149 |
|
145 | 150 | def get_optimized(self, insts, consts, nlocals=0):
|
146 | 151 | insts = self.normalize_insts(insts)
|
147 | 152 | insts = self.complete_insts_info(insts)
|
148 |
| - insts = optimize_cfg(insts, consts, nlocals) |
| 153 | + insts = _testinternalcapi.optimize_cfg(insts, consts, nlocals) |
149 | 154 | return insts, consts
|
150 | 155 |
|
| 156 | +@unittest.skipIf(_testinternalcapi is None, "requires _testinternalcapi") |
151 | 157 | class AssemblerTestCase(CompilationStepTestCase):
|
152 | 158 |
|
153 | 159 | def get_code_object(self, filename, insts, metadata):
|
154 |
| - co = assemble_code_object(filename, insts, metadata) |
| 160 | + co = _testinternalcapi.assemble_code_object(filename, insts, metadata) |
155 | 161 | return co
|
0 commit comments