diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-06-30 20:54:02 -0400 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-06-30 20:54:02 -0400 |
commit | 01c8612f26a98ef145d1ce8636124a6a39ff9762 (patch) | |
tree | 85e39c1fec60dcbe46eb8db29558b95620cb132d /tests/test_cmd2.py | |
parent | ed54110d6fa27833467f55051c47c0cea77fabee (diff) | |
download | cmd2-git-01c8612f26a98ef145d1ce8636124a6a39ff9762.tar.gz |
Refactored clipboard code to make it a tiny bit simpler
Also added a few unit tests related to running an empty statement and dealing with precmd hook success and failure.
Diffstat (limited to 'tests/test_cmd2.py')
-rw-r--r-- | tests/test_cmd2.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index d288f78f..791d6b59 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -25,6 +25,11 @@ def test_ver(): assert cmd2.__version__ == '0.7.4' +def test_empty_statement(base_app): + out = run_cmd(base_app, '') + expected = normalize('') + assert out == expected + def test_base_help(base_app): out = run_cmd(base_app, 'help') expected = normalize(BASE_HELP) @@ -683,3 +688,29 @@ def test_cmdloop_without_rawinput(): app.cmdloop() out = app.stdout.buffer assert out == expected + + +class HookFailureApp(cmd2.Cmd): + def __init__(self, *args, **kwargs): + # Need to use this older form of invoking super class constructor to support Python 2.x and Python 3.x + cmd2.Cmd.__init__(self, *args, **kwargs) + + def postparsing_precmd(self, statement): + """Simulate precmd hook failure.""" + return True, statement + + +@pytest.fixture +def hook_failure(): + app = HookFailureApp() + app.stdout = StdOut() + return app + +def test_precmd_hook_success(base_app): + out = base_app.onecmd_plus_hooks('help') + assert out is None + + +def test_precmd_hook_failure(hook_failure): + out = hook_failure.onecmd_plus_hooks('help') + assert out == True |