From aa18449d189cd7ac3c1ce4f99abff7f767d1e63d Mon Sep 17 00:00:00 2001 From: Kevin Van Brunt Date: Fri, 30 Jun 2017 16:19:50 -0400 Subject: Added unit tests --- a | 0 tests/scripts/binary.bin | Bin 0 -> 51 bytes tests/scripts/empty.txt | 0 tests/scripts/utf8.txt | 1 + tests/test_cmd2.py | 38 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 39 insertions(+) delete mode 100644 a create mode 100644 tests/scripts/binary.bin create mode 100644 tests/scripts/empty.txt create mode 100644 tests/scripts/utf8.txt diff --git a/a b/a deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/scripts/binary.bin b/tests/scripts/binary.bin new file mode 100644 index 00000000..c18394ef Binary files /dev/null and b/tests/scripts/binary.bin differ diff --git a/tests/scripts/empty.txt b/tests/scripts/empty.txt new file mode 100644 index 00000000..e69de29b 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') -- cgit v1.2.1