diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-09-28 20:35:15 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-09-28 20:35:15 -0400 |
commit | c2b1f611be7589ac2bdae34897d0140f5df75c9f (patch) | |
tree | a291427e17d0eb3208a1f1dd64a1a177805ed98f /tests/test_cmd2.py | |
parent | bd84b4234442c03a29dd096d85bda13af56f603a (diff) | |
download | cmd2-git-c2b1f611be7589ac2bdae34897d0140f5df75c9f.tar.gz |
Added unit test for onchange_hook
Diffstat (limited to 'tests/test_cmd2.py')
-rw-r--r-- | tests/test_cmd2.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index a87cba18..3ce7a11d 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -184,6 +184,30 @@ now: True assert out == ['quiet: True'] +class OnChangeHookApp(cmd2.Cmd): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + def _onchange_quiet(self, old, new) -> None: + """Runs when quiet is changed via set command""" + self.poutput("You changed quiet") + +@pytest.fixture +def onchange_app(): + app = OnChangeHookApp() + app.stdout = utils.StdSim(app.stdout) + return app + +def test_set_onchange_hook(onchange_app): + out = run_cmd(onchange_app, 'set quiet True') + expected = normalize(""" +quiet - was: False +now: True +You changed quiet +""") + assert out == expected + + def test_base_shell(base_app, monkeypatch): m = mock.Mock() monkeypatch.setattr("{}.Popen".format('subprocess'), m) |