diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-01-29 22:54:29 -0500 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-01-29 22:54:29 -0500 |
commit | 95c5ceee69720e51f20f6b02d457936768cc154e (patch) | |
tree | 8afbffa24ccd17a10c6cc7b3c948de47c6f51d2d /tests/test_cmd2.py | |
parent | f182c7ad46b72bae377265a5c67468d2d52c3f27 (diff) | |
download | cmd2-git-95c5ceee69720e51f20f6b02d457936768cc154e.tar.gz |
Added a basic unit test for the save command
Diffstat (limited to 'tests/test_cmd2.py')
-rw-r--r-- | tests/test_cmd2.py | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index 2005f678..6f169ffc 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -5,7 +5,7 @@ Cmd2 unit/functional testing Copyright 2016 Federico Ceratto <federico.ceratto@gmail.com> Released under MIT license, see LICENSE file """ - +import os import mock from conftest import run_cmd, _normalize from six import StringIO @@ -200,3 +200,28 @@ def test_base_cmdenvironment(base_app): out_params = set(out[2].split("Settable parameters: ")[1].split()) assert settable_params == out_params + + +def test_base_save(base_app, capsys): + # TODO: Use a temporary directory for the file + filename = 'deleteme.txt' + run_cmd(base_app, 'help') + run_cmd(base_app, 'help save') + run_cmd(base_app, 'save * {}'.format(filename)) + out, err = capsys.readouterr() + assert out == 'Saved to deleteme.txt\n' + + with open(filename) as f: + content = [line.strip() for line in f.readlines()] + expected = _normalize(""" +help + +help save + +save * deleteme.txt +""") + + assert content == expected + + # Delete file that was created + os.remove(filename) |