def test_simple(self): def func(): a, b, c = range(3) actual = [ bytecode.command_to_string(command, arg) for command, arg in bytecode.ByteCode(func.func_code.co_code) ] expected = [ 'LOAD_GLOBAL 0', 'LOAD_CONST 1', 'CALL_FUNCTION 1', 'UNPACK_SEQUENCE 3', 'STORE_FAST 0', 'STORE_FAST 1', 'STORE_FAST 2', 'LOAD_CONST 0', 'RETURN_VALUE' ] self.assertEqual(expected, actual)
def test_extended(self): code_str = ",".join(["v_%d" % idx for idx in xrange(70000)]) + "= range(70000)" actual = list(bytecode.ByteCode(compile(code_str, "a.py", "exec").co_code)) actual = [bytecode.command_to_string(command, arg) for command, arg in actual] expected = ['STORE_NAME 69993', 'STORE_NAME 69994', 'STORE_NAME 69995', 'STORE_NAME 69996', 'STORE_NAME 69997', 'STORE_NAME 69998', 'STORE_NAME 69999', 'STORE_NAME 70000', 'LOAD_CONST 1', 'RETURN_VALUE'] self.assertEqual(expected, actual[-10:])
def test_simple(self): def func(): a, b, c = range(3) actual = [bytecode.command_to_string(command, arg) for command, arg in bytecode.ByteCode(func.func_code.co_code)] expected = ['LOAD_GLOBAL 0', 'LOAD_CONST 1', 'CALL_FUNCTION 1', 'UNPACK_SEQUENCE 3', 'STORE_FAST 0', 'STORE_FAST 1', 'STORE_FAST 2', 'LOAD_CONST 0', 'RETURN_VALUE'] self.assertEqual(expected, actual)
def test_extended(self): code_str = ",".join(["v_%d" % idx for idx in xrange(70000)]) + "= range(70000)" actual = list( bytecode.ByteCode(compile(code_str, "a.py", "exec").co_code)) actual = [ bytecode.command_to_string(command, arg) for command, arg in actual ] expected = [ 'STORE_NAME 69993', 'STORE_NAME 69994', 'STORE_NAME 69995', 'STORE_NAME 69996', 'STORE_NAME 69997', 'STORE_NAME 69998', 'STORE_NAME 69999', 'STORE_NAME 70000', 'LOAD_CONST 1', 'RETURN_VALUE' ] self.assertEqual(expected, actual[-10:])