|
1 | 1 | import dis |
2 | 2 | from test.support.import_helper import import_module |
3 | 3 | import unittest |
| 4 | +import opcode |
4 | 5 |
|
5 | 6 | _opcode = import_module("_opcode") |
6 | 7 | from _opcode import stack_effect |
@@ -64,5 +65,31 @@ def test_stack_effect_jump(self): |
64 | 65 | self.assertEqual(nojump, common) |
65 | 66 |
|
66 | 67 |
|
| 68 | +class SpecializationStatsTests(unittest.TestCase): |
| 69 | + def test_specialization_stats(self): |
| 70 | + stat_names = opcode._specialization_stats |
| 71 | + |
| 72 | + specialized_opcodes = [ |
| 73 | + op[:-len("_ADAPTIVE")].lower() for |
| 74 | + op in opcode._specialized_instructions |
| 75 | + if op.endswith("_ADAPTIVE")] |
| 76 | + self.assertIn('load_attr', specialized_opcodes) |
| 77 | + self.assertIn('binary_subscr', specialized_opcodes) |
| 78 | + |
| 79 | + stats = _opcode.get_specialization_stats() |
| 80 | + if stats is not None: |
| 81 | + self.assertIsInstance(stats, dict) |
| 82 | + self.assertCountEqual(stats.keys(), specialized_opcodes) |
| 83 | + self.assertCountEqual( |
| 84 | + stats['load_attr'].keys(), |
| 85 | + stat_names + ['fails']) |
| 86 | + for sn in stat_names: |
| 87 | + self.assertIsInstance(stats['load_attr'][sn], int) |
| 88 | + self.assertIsInstance(stats['load_attr']['fails'], dict) |
| 89 | + for k,v in stats['load_attr']['fails'].items(): |
| 90 | + self.assertIsInstance(k, tuple) |
| 91 | + self.assertIsInstance(v, int) |
| 92 | + |
| 93 | + |
67 | 94 | if __name__ == "__main__": |
68 | 95 | unittest.main() |
0 commit comments