def test_run(self): instructions = [Mov(AX, '2'), Mov(AX, '4')] context = Context(instructions) context.run() self.assertEqual(context.registers.get(AX).value, 0) context.step() self.assertEqual(context.registers.get(AX).value, 2) context.step() self.assertEqual(context.registers.get(AX).value, 4)
def run_program(program_file): lines = program_file.readlines() parser = Parser() instructions = parser.parse_text(lines) if len(instructions) == 0: die(1, 'nothing to run, aborting.') context = Context(instructions) view = MainView(100, 40, context) while True: view.paint() inp = input() if inp == 'r': context.run() elif inp == '': try: if not context.step(): break except Exception as e: die(1, str(e)) elif inp == 'a': die(0, 'exiting program.')