this repo has no description
1# Copyright (c) Facebook, Inc. and its affiliates. (http://www.facebook.com)
2try:
3 # These are PyRo-specific libraries
4 import _bytecode_utils
5 import _compiler_opcode
6except ImportError:
7 pass
8
9import opcode
10import unittest
11
12from test_support import pyro_only
13
14
15@pyro_only
16class OpcodeTests(unittest.TestCase):
17 def test_all_compiler_opcodes_exist_in_runtime(self):
18 compiler_opmap = _compiler_opcode.opcode.opmap
19 builtin_opmap = _bytecode_utils.opmap
20 for opname, opnum in compiler_opmap.items():
21 self.assertIn(opname, builtin_opmap, f"{opname} not found in builtin opmap")
22 self.assertEqual(
23 builtin_opmap[opname],
24 opnum,
25 f"expected {opname} to have value {opnum} but found {builtin_opmap[opname]}",
26 )
27
28 def test_all_opcode_opcodes_exist_in_runtime(self):
29 opcode_opmap = opcode.opmap
30 builtin_opmap = _bytecode_utils.opmap
31 for opname, opnum in opcode_opmap.items():
32 self.assertIn(opname, builtin_opmap, f"{opname} not found in builtin opmap")
33 self.assertEqual(
34 builtin_opmap[opname],
35 opnum,
36 f"expected {opname} to have value {opnum} but found {builtin_opmap[opname]}",
37 )
38
39
40if __name__ == "__main__":
41 unittest.main()