summaryrefslogtreecommitdiff
path: root/tests/test_cmd2.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2017-06-30 16:19:50 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2017-06-30 16:19:50 -0400
commitaa18449d189cd7ac3c1ce4f99abff7f767d1e63d (patch)
treeff8e7f63cafa4e78723e9f8d188a23bf8269239a /tests/test_cmd2.py
parent346ff6cf7e35329ae7052a018814e64d59382052 (diff)
downloadcmd2-git-aa18449d189cd7ac3c1ce4f99abff7f767d1e63d.tar.gz
Added unit tests
Diffstat (limited to 'tests/test_cmd2.py')
-rw-r--r--tests/test_cmd2.py38
1 files changed, 38 insertions, 0 deletions
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')