Skip to content
Merged
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
Update test__opcode from 3.14.2
  • Loading branch information
CPython Devleopers authored and youknowone committed Jan 19, 2026
commit 67febe675f06e5e4ab8a48d2c4b10e19680d04ba
17 changes: 12 additions & 5 deletions Lib/test/test__opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def check_bool_function_result(self, func, ops, expected):
self.assertEqual(func(op), expected)

def test_invalid_opcodes(self):
invalid = [-100, -1, 255, 512, 513, 1000]
invalid = [-100, -1, 512, 513, 1000]
self.check_bool_function_result(_opcode.is_valid, invalid, False)
self.check_bool_function_result(_opcode.has_arg, invalid, False)
self.check_bool_function_result(_opcode.has_const, invalid, False)
Expand All @@ -38,6 +38,14 @@ def test_is_valid(self):
opcodes = [dis.opmap[opname] for opname in names]
self.check_bool_function_result(_opcode.is_valid, opcodes, True)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_opmaps(self):
def check_roundtrip(name, map):
return self.assertEqual(opcode.opname[map[name]], name)

check_roundtrip('BINARY_OP', opcode.opmap)
check_roundtrip('BINARY_OP_ADD_INT', opcode._specialized_opmap)

def test_oplists(self):
def check_function(self, func, expected):
for op in [-10, 520]:
Expand All @@ -58,8 +66,7 @@ def check_function(self, func, expected):
class StackEffectTests(unittest.TestCase):
def test_stack_effect(self):
self.assertEqual(stack_effect(dis.opmap['POP_TOP']), -1)
self.assertEqual(stack_effect(dis.opmap['BUILD_SLICE'], 0), -1)
self.assertEqual(stack_effect(dis.opmap['BUILD_SLICE'], 1), -1)
self.assertEqual(stack_effect(dis.opmap['BUILD_SLICE'], 2), -1)
self.assertEqual(stack_effect(dis.opmap['BUILD_SLICE'], 3), -2)
self.assertRaises(ValueError, stack_effect, 30000)
# All defined opcodes
Expand Down Expand Up @@ -110,7 +117,7 @@ def test_stack_effect_jump(self):


class SpecializationStatsTests(unittest.TestCase):
@unittest.expectedFailure # TODO: RUSTPYTHON - no specialization stats
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_specialization_stats(self):
stat_names = ["success", "failure", "hit", "deferred", "miss", "deopt"]
specialized_opcodes = [
Expand All @@ -119,7 +126,7 @@ def test_specialization_stats(self):
if opcode._inline_cache_entries.get(op, 0)
]
self.assertIn('load_attr', specialized_opcodes)
self.assertIn('binary_subscr', specialized_opcodes)
self.assertIn('binary_op', specialized_opcodes)

stats = _opcode.get_specialization_stats()
if stats is not None:
Expand Down
Loading