From 1c6494f55ff32d1b077f7afa4f10b84c6b94e5ac Mon Sep 17 00:00:00 2001 From: Mike Naberezny Date: Wed, 21 Nov 2012 18:04:01 -0800 Subject: [PATCH] Don't display registers again on 'quit' command --- py65/monitor.py | 56 ++++++++++++++++++-------------------- py65/tests/test_monitor.py | 36 ++++++------------------ 2 files changed, 35 insertions(+), 57 deletions(-) diff --git a/py65/monitor.py b/py65/monitor.py index 632c44a..5070317 100644 --- a/py65/monitor.py +++ b/py65/monitor.py @@ -109,7 +109,9 @@ class Monitor(cmd.Cmd): error = 'Error: %s, %s: file: %s line: %s' % (t, v, file, line) self._output(error) - self._output_mpu_status() + if not line.startswith("quit"): + self._output_mpu_status() + return result def _reset(self, mpu_type): @@ -126,26 +128,28 @@ class Monitor(cmd.Cmd): self._assembler = Assembler(self._mpu, self._address_parser) def _add_shortcuts(self): - self._shortcuts = {'~': 'tilde', - 'a': 'assemble', - 'al': 'add_label', - 'd': 'disassemble', - 'dl': 'delete_label', - 'f': 'fill', - '>': 'fill', - 'g': 'goto', - 'h': 'help', - '?': 'help', - 'l': 'load', - 'm': 'mem', - 'q': 'quit', - 'r': 'registers', - 'ret': 'return', - 'rad': 'radix', - 's': 'save', - 'shl': 'show_labels', - 'x': 'quit', - 'z': 'step'} + self._shortcuts = {'EOF': 'quit', + '~': 'tilde', + 'a': 'assemble', + 'al': 'add_label', + 'd': 'disassemble', + 'dl': 'delete_label', + 'exit': 'quit', + 'f': 'fill', + '>': 'fill', + 'g': 'goto', + 'h': 'help', + '?': 'help', + 'l': 'load', + 'm': 'mem', + 'q': 'quit', + 'r': 'registers', + 'ret': 'return', + 'rad': 'radix', + 's': 'save', + 'shl': 'show_labels', + 'x': 'quit', + 'z': 'step'} def _preprocess_line(self, line): # line comments @@ -264,18 +268,12 @@ class Monitor(cmd.Cmd): self._output("mpu\t\tPrint available microprocessors.") self._output("mpu \tSelect a new microprocessor.") - def do_EOF(self, args): + def do_quit(self, args): self._output('') return 1 - def help_EOF(self): - self._output("To quit, type ^D or use the quit command.") - - def do_quit(self, args): - return self.do_EOF(args) - def help_quit(self): - return self.help_EOF() + self._output("To quit, type ^D or use the quit command.") def do_assemble(self, args): splitted = args.split(None, 1) diff --git a/py65/tests/test_monitor.py b/py65/tests/test_monitor.py index 686519e..e80944c 100644 --- a/py65/tests/test_monitor.py +++ b/py65/tests/test_monitor.py @@ -582,34 +582,14 @@ class MonitorTests(unittest.TestCase): # quit - def test_shortcut_x_for_quit(self): - stdout = StringIO() - mon = Monitor(stdout=stdout) - mon.do_help('x') + def test_shortcuts_for_quit(self): + for shortcut in ["exit", "x", "q", "EOF"]: + stdout = StringIO() + mon = Monitor(stdout=stdout) + mon.do_help(shortcut) - out = stdout.getvalue() - self.assertTrue(out.startswith('To quit')) - - def test_shortcut_q_for_quit(self): - stdout = StringIO() - mon = Monitor(stdout=stdout) - mon.do_help('q') - - out = stdout.getvalue() - self.assertTrue(out.startswith('To quit')) - - def test_do_EOF(self): - stdout = StringIO() - mon = Monitor(stdout=stdout) - exitnow = mon.do_EOF('') - self.assertEqual(True, exitnow) - - def test_help_EOF(self): - stdout = StringIO() - mon = Monitor(stdout=stdout) - mon.help_EOF() - out = stdout.getvalue() - self.assertTrue(out.startswith("To quit,")) + out = stdout.getvalue() + self.assertTrue(out.startswith('To quit')) def test_do_quit(self): stdout = StringIO() @@ -620,7 +600,7 @@ class MonitorTests(unittest.TestCase): def test_help_quit(self): stdout = StringIO() mon = Monitor(stdout=stdout) - mon.help_EOF() + mon.help_quit() out = stdout.getvalue() self.assertTrue(out.startswith("To quit,"))