diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-06-23 19:43:42 -0400 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-06-23 19:43:42 -0400 |
commit | c8381601e4e3b31969ea6108617356572a7d1ca3 (patch) | |
tree | 023e67165ce45eba33739f248c1ee53b7c975d8f /tests | |
parent | c7feaa60e46563cd60c217d27f888a05c9c3439d (diff) | |
download | cmd2-git-c8381601e4e3b31969ea6108617356572a7d1ca3.tar.gz |
Deprecated CmdResult helper class and promoted CommandResult
These classes are subtly different, particularly in terms of their truthiness.
CmdResult
- attributes: out, err, war
- truthy: if err is falsy
CommandResult
- attributes: stdout, stderr, data
- truthy: if err is falsy AND data is not None
So CmdResult was oriented to provide essentially info, error, and warning messages to the user (typically as stirngs), whereas CommandResult is geared towards providing info and error messages to the user as strings in addition to data to the user in a command-specific format which is arbitrary other than it should never be None if the command succeeds.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_cmd2.py | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index 26df4807..94cd42f9 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -1468,32 +1468,33 @@ def test_clipboard_failure(base_app, capsys): assert "Cannot redirect to paste buffer; install 'pyperclip' and re-run to enable" in err -class CmdResultApp(cmd2.Cmd): +class CommandResultApp(cmd2.Cmd): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def do_affirmative(self, arg): - self._last_result = cmd2.CmdResult(arg) + self._last_result = cmd2.CommandResult(arg, data=True) def do_negative(self, arg): - self._last_result = cmd2.CmdResult('', arg) + self._last_result = cmd2.CommandResult(arg) @pytest.fixture -def cmdresult_app(): - app = CmdResultApp() +def commandresult_app(): + app = CommandResultApp() app.stdout = StdOut() return app -def test_cmdresult(cmdresult_app): +def test_commandresult_truthy(commandresult_app): arg = 'foo' - run_cmd(cmdresult_app, 'affirmative {}'.format(arg)) - assert cmdresult_app._last_result - assert cmdresult_app._last_result == cmd2.CmdResult(arg) + run_cmd(commandresult_app, 'affirmative {}'.format(arg)) + assert commandresult_app._last_result + assert commandresult_app._last_result == cmd2.CommandResult(arg, data=True) +def test_commandresult_falsy(commandresult_app): arg = 'bar' - run_cmd(cmdresult_app, 'negative {}'.format(arg)) - assert not cmdresult_app._last_result - assert cmdresult_app._last_result == cmd2.CmdResult('', arg) + run_cmd(commandresult_app, 'negative {}'.format(arg)) + assert not commandresult_app._last_result + assert commandresult_app._last_result == cmd2.CommandResult(arg) def test_is_text_file_bad_input(base_app): |