Mercurial > p > roundup > code
diff test/test_admin.py @ 8440:254f70dfc585
bug, refactor, test: make pragma history_length work interactively
history_length could be set interactively, but it was never used to set
readline/pyreadline3's internal state. Using the pragma setting on the
roundup-admin command line did set readline's state.
Also refactored 2 calls to self.readline.get_current_history_length()
into one call and storing in a variable. Also changed method for
creating history strings for printing.
Tests added for history_length pragma on cli and interactive use.
Added test for exiting roundup-admin with EOF on input.
Added test for 'readline nosuchdirective' error case.
Added test to readline with a command directive to set an internal
variable. This last one has no real test to see if it was successful
because I can't emulate a real keyboard/tty which is needed to test.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sun, 31 Aug 2025 20:59:04 -0400 |
| parents | 3bdae15252c6 |
| children | 9c3ec0a5c7fc |
line wrap: on
line diff
--- a/test/test_admin.py Sun Aug 31 16:54:17 2025 -0400 +++ b/test/test_admin.py Sun Aug 31 20:59:04 2025 -0400 @@ -184,6 +184,31 @@ AdminTool.my_input = orig_input + # test EOF exit + inputs = ["help"] + + self._monkeypatch.setattr( + 'sys.stdin', + io.StringIO("\n".join(inputs))) + + # preserve directory self.install_init() + self.admin=AdminTool() + + # disable all features + self.admin.settings['history_features'] = 7 + sys.argv=['main', '-i', self.dirname] + + with captured_output() as (out, err): + ret = self.admin.main() + out = out.getvalue().strip().split('\n') + + print(ret) + self.assertTrue(ret == 0) + + # 4 includes 2 commands in saved history + expected = 'roundup> exit...' + self.assertIn(expected, out) + def testGet(self): ''' Note the tests will fail if you run this under pdb. the context managers capture the pdb prompts and this screws @@ -1947,6 +1972,120 @@ self.assertIn(expected, out) + # --- test 3,4 - make sure readline gets history_length pragma. + # test CLI and interactive. + + inputs = ["pragma list", "q"] + + self._monkeypatch.setattr( + 'sys.stdin', + io.StringIO("\n".join(inputs))) + + self.install_init() + self.admin=AdminTool() + + # disable all config/history + self.admin.settings['history_features'] = 7 + sys.argv=['main', '-i', self.dirname, '-P', 'history_length=11'] + + with captured_output() as (out, err): + ret = self.admin.main() + out = out.getvalue().strip().split('\n') + + print(ret) + self.assertTrue(ret == 0) + self.assertEqual(self.admin.readline.get_history_length(), + 11) + + # 4 + inputs = ["pragma history_length=17", "q"] + + self._monkeypatch.setattr( + 'sys.stdin', + io.StringIO("\n".join(inputs))) + + self.install_init() + self.admin=AdminTool() + + # disable all config/history + self.admin.settings['history_features'] = 7 + # keep pragma in CLI. Make sure it's overridden by interactive + sys.argv=['main', '-i', self.dirname, '-P', 'history_length=11'] + + with captured_output() as (out, err): + ret = self.admin.main() + out = out.getvalue().strip().split('\n') + + print(ret) + self.assertTrue(ret == 0) + # should not be 11. + self.assertEqual(self.admin.readline.get_history_length(), + 17) + + # --- test 5 invalid single word parameter + + inputs = ["readline nosuchdirective", "q"] + + self._monkeypatch.setattr( + 'sys.stdin', + io.StringIO("\n".join(inputs))) + + self.install_init() + self.admin=AdminTool() + + # disable loading and saving history + self.admin.settings['history_features'] = 3 + sys.argv=['main', '-i', self.dirname] + + with captured_output() as (out, err): + ret = self.admin.main() + out = out.getvalue().strip().split('\n') + + print(ret) + self.assertTrue(ret == 0) + + expected = ('roundup> Unknown readline parameter nosuchdirective') + + self.assertIn(expected, out) + + # --- test 6 set keystroke command. + # FIXME: unable to test key binding/setting actually works. + # + # No errors seem to come back from readline or + # pyreadline3 even when the keybinding makes no + # sense. Errors are only reported when reading + # from init file. Using "set answer 42" does print + # 'readline: answer: unknown variable name' when + # attached to tty/pty and interactive, but not + # inside test case. Pyreadline3 doesn't + # report errors at all. + # + # Even if I set a keybidning, I can't invoke it + # because I am not running inside a pty, so + # editing is disabled and I have no way to + # simulate keyboard keystrokes for readline to act + # upon. + + inputs = ['readline set meaning 42', "q"] + + self._monkeypatch.setattr( + 'sys.stdin', + io.StringIO("\n".join(inputs))) + + self.install_init() + self.admin=AdminTool() + + # disable loading and saving history + self.admin.settings['history_features'] = 3 + sys.argv=['main', '-i', self.dirname] + + with captured_output() as (out, err): + ret = self.admin.main() + out = out.getvalue().strip().split('\n') + + print(ret) + self.assertTrue(ret == 0) + # === cleanup if original_home: os.environ['HOME'] = original_home
