diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2017-06-30 16:19:50 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2017-06-30 16:19:50 -0400 |
commit | aa18449d189cd7ac3c1ce4f99abff7f767d1e63d (patch) | |
tree | ff8e7f63cafa4e78723e9f8d188a23bf8269239a /tests | |
parent | 346ff6cf7e35329ae7052a018814e64d59382052 (diff) | |
download | cmd2-git-aa18449d189cd7ac3c1ce4f99abff7f767d1e63d.tar.gz |
Added unit tests
Diffstat (limited to 'tests')
-rw-r--r-- | tests/scripts/binary.bin | bin | 0 -> 51 bytes | |||
-rw-r--r-- | tests/scripts/empty.txt | 0 | ||||
-rw-r--r-- | tests/scripts/utf8.txt | 1 | ||||
-rw-r--r-- | tests/test_cmd2.py | 38 |
4 files changed, 39 insertions, 0 deletions
diff --git a/tests/scripts/binary.bin b/tests/scripts/binary.bin Binary files differnew file mode 100644 index 00000000..c18394ef --- /dev/null +++ b/tests/scripts/binary.bin diff --git a/tests/scripts/empty.txt b/tests/scripts/empty.txt new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/tests/scripts/empty.txt diff --git a/tests/scripts/utf8.txt b/tests/scripts/utf8.txt new file mode 100644 index 00000000..7cd59ba3 --- /dev/null +++ b/tests/scripts/utf8.txt @@ -0,0 +1 @@ +!echo γνωρίζω diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index 9be1158b..db7f8cf7 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -303,6 +303,44 @@ def test_base_load_with_nonexistent_file(base_app, capsys): assert "does not exist or is not a file" in str(err) +def test_base_load_with_empty_file(base_app, capsys, request): + test_dir = os.path.dirname(request.module.__file__) + filename = os.path.join(test_dir, 'scripts', 'empty.txt') + + # The way the load command works, we can't directly capture its stdout or stderr + run_cmd(base_app, 'load {}'.format(filename)) + out, err = capsys.readouterr() + + # The load command requires non-empty scripts files + assert str(err).startswith("ERROR") + assert "is empty" in str(err) + + +def test_base_load_with_binary_file(base_app, capsys, request): + test_dir = os.path.dirname(request.module.__file__) + filename = os.path.join(test_dir, 'scripts', 'binary.bin') + + # The way the load command works, we can't directly capture its stdout or stderr + run_cmd(base_app, 'load {}'.format(filename)) + out, err = capsys.readouterr() + + # The load command requires non-empty scripts files + assert str(err).startswith("ERROR") + assert "is not an ASCII or UTF-8 encoded text file" in str(err) + + +def test_base_load_with_utf8_file(base_app, capsys, request): + test_dir = os.path.dirname(request.module.__file__) + filename = os.path.join(test_dir, 'scripts', 'utf8.txt') + + # The way the load command works, we can't directly capture its stdout or stderr + run_cmd(base_app, 'load {}'.format(filename)) + out, err = capsys.readouterr() + + # TODO Make this test better once shell command is fixed to used cmd2's stdout + assert str(err) == '' + + def test_base_relative_load(base_app, request): test_dir = os.path.dirname(request.module.__file__) filename = os.path.join(test_dir, 'script.txt') |