Larry Hastings | 3a90797 | 2013-11-23 14:49:22 -0800 | [diff] [blame] | 1 | import dis |
Larry Hastings | c8635b4 | 2013-11-23 16:11:17 -0800 | [diff] [blame] | 2 | from test.support import run_unittest, import_module |
Larry Hastings | 3a90797 | 2013-11-23 14:49:22 -0800 | [diff] [blame] | 3 | import unittest |
| 4 | |
Larry Hastings | c8635b4 | 2013-11-23 16:11:17 -0800 | [diff] [blame] | 5 | _opcode = import_module("_opcode") |
| 6 | |
Larry Hastings | 3a90797 | 2013-11-23 14:49:22 -0800 | [diff] [blame] | 7 | class OpcodeTests(unittest.TestCase): |
| 8 | |
| 9 | def test_stack_effect(self): |
| 10 | self.assertEqual(_opcode.stack_effect(dis.opmap['POP_TOP']), -1) |
| 11 | self.assertEqual(_opcode.stack_effect(dis.opmap['DUP_TOP_TWO']), 2) |
| 12 | self.assertEqual(_opcode.stack_effect(dis.opmap['BUILD_SLICE'], 0), -1) |
| 13 | self.assertEqual(_opcode.stack_effect(dis.opmap['BUILD_SLICE'], 1), -1) |
| 14 | self.assertEqual(_opcode.stack_effect(dis.opmap['BUILD_SLICE'], 3), -2) |
| 15 | self.assertRaises(ValueError, _opcode.stack_effect, 30000) |
| 16 | self.assertRaises(ValueError, _opcode.stack_effect, dis.opmap['BUILD_SLICE']) |
| 17 | self.assertRaises(ValueError, _opcode.stack_effect, dis.opmap['POP_TOP'], 0) |
| 18 | |
| 19 | def test_main(): |
| 20 | run_unittest(OpcodeTests) |
| 21 | |
| 22 | if __name__ == "__main__": |
| 23 | test_main() |