Skip to content

Commit dc7da4d

Browse files
tests: fix instr arg validation logic
1 parent 75013eb commit dc7da4d

1 file changed

Lines changed: 33 additions & 41 deletions

File tree

tests/test_instr.py

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -163,47 +163,6 @@ def test_invalid_arg(self):
163163
label = Label()
164164
block = BasicBlock()
165165

166-
for name in (opcode.opname[op] for op in BINARY_OPS):
167-
assert name == "BINARY_OP", f"expected BINARY_OP but got {name=}"
168-
Instr(name, BinaryOp.ADD)
169-
Instr(name, BinaryOp.ADD.value)
170-
self.assertRaises(TypeError, Instr, name, "")
171-
172-
for name in (opcode.opname[op] for op in SPECIAL_OPS):
173-
assert name == "LOAD_SPECIAL", f"expected LOAD_SPECIAL but got {name=}"
174-
Instr("LOAD_SPECIAL", SpecialMethod.EXIT)
175-
self.assertRaises(
176-
TypeError, Instr, "LOAD_SPECIAL", SpecialMethod.EXIT.value
177-
)
178-
179-
for name in (opcode.opname[op] for op in COMMON_CONSTANT_OPS):
180-
assert name == "LOAD_COMMON_CONSTANT", (
181-
f"expected LOAD_COMMON_CONSTANT but got {name=}"
182-
)
183-
Instr("LOAD_COMMON_CONSTANT", CommonConstant.BUILTIN_ALL)
184-
self.assertRaises(
185-
TypeError,
186-
Instr,
187-
"LOAD_COMMON_CONSTANT",
188-
CommonConstant.BUILTIN_ALL.value,
189-
)
190-
191-
for name in (opcode.opname[op] for op in SMALL_INT_OPS):
192-
assert name == "LOAD_SMALL_INT", f"expected LOAD_SMALL_INT but got {name=}"
193-
Instr("LOAD_SMALL_INT", 1)
194-
self.assertRaises(ValueError, Instr, "LOAD_SMALL_INT", 256)
195-
196-
for name in (opcode.opname[op] for op in FORMAT_VALUE_OPS):
197-
if name in BITFLAG_OPCODES:
198-
Instr(name, (True, FormatValue.STR))
199-
Instr(name, (False, FormatValue.STR))
200-
self.assertRaises(TypeError, Instr, name, True, FormatValue.STR)
201-
self.assertRaises(TypeError, Instr, name, False, FormatValue.STR)
202-
else:
203-
Instr(name, FormatValue.STR)
204-
Instr(name, FormatValue.STR.value)
205-
self.assertRaises(TypeError, Instr, name, "STR")
206-
207166
# EXTENDED_ARG
208167
self.assertRaises(ValueError, Instr, "EXTENDED_ARG", 0)
209168

@@ -286,6 +245,39 @@ def test_invalid_arg(self):
286245
self.assertRaises(TypeError, Instr, name, 1)
287246
Instr(name, Intrinsic2Op.INTRINSIC_PREP_RERAISE_STAR)
288247

248+
for name in (opcode.opname[op] for op in BINARY_OPS):
249+
Instr(name, BinaryOp.ADD)
250+
Instr(name, BinaryOp.ADD.value)
251+
self.assertRaises(TypeError, Instr, name, "")
252+
253+
for name in (opcode.opname[op] for op in SPECIAL_OPS):
254+
Instr(name, SpecialMethod.EXIT)
255+
self.assertRaises(TypeError, Instr, name, SpecialMethod.EXIT.value)
256+
257+
for name in (opcode.opname[op] for op in COMMON_CONSTANT_OPS):
258+
Instr(name, CommonConstant.BUILTIN_ALL)
259+
self.assertRaises(
260+
TypeError,
261+
Instr,
262+
name,
263+
CommonConstant.BUILTIN_ALL.value,
264+
)
265+
266+
for name in (opcode.opname[op] for op in SMALL_INT_OPS):
267+
Instr(name, 1)
268+
self.assertRaises(ValueError, Instr, name, 256)
269+
270+
for op, name in ((op, opcode.opname[op]) for op in FORMAT_VALUE_OPS):
271+
if op in BITFLAG_OPCODES:
272+
Instr(name, (True, FormatValue.STR))
273+
Instr(name, (False, FormatValue.STR))
274+
self.assertRaises(TypeError, Instr, name, True, FormatValue.STR)
275+
self.assertRaises(TypeError, Instr, name, False, FormatValue.STR)
276+
else:
277+
Instr(name, FormatValue.STR)
278+
Instr(name, FormatValue.STR.value)
279+
self.assertRaises(TypeError, Instr, name, "STR")
280+
289281
def test_require_arg(self):
290282
i = Instr(CALL, 3)
291283
self.assertTrue(i.require_arg())

0 commit comments

Comments
 (0)