diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/conftest.py | 2 | ||||
-rw-r--r-- | tests/test_argparse.py | 2 | ||||
-rw-r--r-- | tests/test_cmd2.py | 65 | ||||
-rw-r--r-- | tests/test_completion.py | 2 | ||||
-rw-r--r-- | tests/test_parsing.py | 3 | ||||
-rw-r--r-- | tests/test_transcript.py | 5 |
6 files changed, 38 insertions, 41 deletions
diff --git a/tests/conftest.py b/tests/conftest.py index 562ca4fa..90d45bd9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -10,7 +10,7 @@ import sys from pytest import fixture from unittest import mock -from cmd2 import cmd2 +import cmd2 # Prefer statically linked gnureadline if available (for macOS compatibility due to issues with libedit) try: diff --git a/tests/test_argparse.py b/tests/test_argparse.py index f1a2b357..469cbe76 100644 --- a/tests/test_argparse.py +++ b/tests/test_argparse.py @@ -5,7 +5,7 @@ Cmd2 testing for argument parsing import argparse import pytest -from cmd2 import cmd2 +import cmd2 from unittest import mock from .conftest import run_cmd, StdOut diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index 6e4a5a3e..662983f9 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -8,9 +8,9 @@ Released under MIT license, see LICENSE file import argparse import builtins from code import InteractiveConsole +import io import os import sys -import io import tempfile import pytest @@ -21,7 +21,8 @@ try: except ImportError: from unittest import mock -from cmd2 import cmd2 +import cmd2 +from cmd2 import utils from .conftest import run_cmd, normalize, BASE_HELP, BASE_HELP_VERBOSE, \ HELP_HISTORY, SHORTCUTS_TXT, SHOW_TXT, SHOW_LONG, StdOut @@ -109,44 +110,40 @@ def test_base_show_readonly(base_app): def test_cast(): - cast = cmd2.cast - # Boolean - assert cast(True, True) == True - assert cast(True, False) == False - assert cast(True, 0) == False - assert cast(True, 1) == True - assert cast(True, 'on') == True - assert cast(True, 'off') == False - assert cast(True, 'ON') == True - assert cast(True, 'OFF') == False - assert cast(True, 'y') == True - assert cast(True, 'n') == False - assert cast(True, 't') == True - assert cast(True, 'f') == False + assert utils.cast(True, True) == True + assert utils.cast(True, False) == False + assert utils.cast(True, 0) == False + assert utils.cast(True, 1) == True + assert utils.cast(True, 'on') == True + assert utils.cast(True, 'off') == False + assert utils.cast(True, 'ON') == True + assert utils.cast(True, 'OFF') == False + assert utils.cast(True, 'y') == True + assert utils.cast(True, 'n') == False + assert utils.cast(True, 't') == True + assert utils.cast(True, 'f') == False # Non-boolean same type - assert cast(1, 5) == 5 - assert cast(3.4, 2.7) == 2.7 - assert cast('foo', 'bar') == 'bar' - assert cast([1,2], [3,4]) == [3,4] + assert utils.cast(1, 5) == 5 + assert utils.cast(3.4, 2.7) == 2.7 + assert utils.cast('foo', 'bar') == 'bar' + assert utils.cast([1,2], [3,4]) == [3,4] def test_cast_problems(capsys): - cast = cmd2.cast - expected = 'Problem setting parameter (now {}) to {}; incorrect type?\n' # Boolean current, with new value not convertible to bool current = True new = [True, True] - assert cast(current, new) == current + assert utils.cast(current, new) == current out, err = capsys.readouterr() assert out == expected.format(current, new) # Non-boolean current, with new value not convertible to current type current = 1 new = 'octopus' - assert cast(current, new) == current + assert utils.cast(current, new) == current out, err = capsys.readouterr() assert out == expected.format(current, new) @@ -700,18 +697,18 @@ def test_pipe_to_shell_error(base_app, capsys): assert err.startswith("EXCEPTION of type '{}' occurred with message:".format(expected_error)) -@pytest.mark.skipif(not cmd2.can_clip, +@pytest.mark.skipif(not cmd2.cmd2.can_clip, reason="Pyperclip could not find a copy/paste mechanism for your system") def test_send_to_paste_buffer(base_app): # Test writing to the PasteBuffer/Clipboard run_cmd(base_app, 'help >') expected = normalize(BASE_HELP) - assert normalize(cmd2.get_paste_buffer()) == expected + assert normalize(cmd2.cmd2.get_paste_buffer()) == expected # Test appending to the PasteBuffer/Clipboard run_cmd(base_app, 'help history >>') expected = normalize(BASE_HELP + '\n' + HELP_HISTORY) - assert normalize(cmd2.get_paste_buffer()) == expected + assert normalize(cmd2.cmd2.get_paste_buffer()) == expected def test_base_timing(base_app, capsys): @@ -1365,18 +1362,18 @@ optional arguments: """ @pytest.mark.skipif(sys.platform.startswith('win'), - reason="cmd2._which function only used on Mac and Linux") + reason="utils.which function only used on Mac and Linux") def test_which_editor_good(): editor = 'vi' - path = cmd2._which(editor) + path = utils.which(editor) # Assert that the vi editor was found because it should exist on all Mac and Linux systems assert path @pytest.mark.skipif(sys.platform.startswith('win'), - reason="cmd2._which function only used on Mac and Linux") + reason="utils.which function only used on Mac and Linux") def test_which_editor_bad(): editor = 'notepad.exe' - path = cmd2._which(editor) + path = utils.which(editor) # Assert that the editor wasn't found because no notepad.exe on non-Windows systems ;-) assert path is None @@ -1421,7 +1418,7 @@ def test_multiline_complete_statement_without_terminator(multiline_app): def test_clipboard_failure(capsys): # Force cmd2 clipboard to be disabled - cmd2.disable_clip() + cmd2.cmd2.disable_clip() app = cmd2.Cmd() # Redirect command output to the clipboard when a clipboard isn't present @@ -1463,11 +1460,11 @@ def test_cmdresult(cmdresult_app): def test_is_text_file_bad_input(base_app): # Test with a non-existent file - file_is_valid = base_app.is_text_file('does_not_exist.txt') + file_is_valid = utils.is_text_file('does_not_exist.txt') assert not file_is_valid # Test with a directory - dir_is_valid = base_app.is_text_file('.') + dir_is_valid = utils.is_text_file('.') assert not dir_is_valid diff --git a/tests/test_completion.py b/tests/test_completion.py index c7650dbb..2faa4a08 100644 --- a/tests/test_completion.py +++ b/tests/test_completion.py @@ -12,8 +12,8 @@ import argparse import os import sys -from cmd2 import cmd2 import pytest +import cmd2 from .conftest import complete_tester, StdOut from examples.subcommands import SubcommandsExample diff --git a/tests/test_parsing.py b/tests/test_parsing.py index 7b361b7e..59f9a610 100644 --- a/tests/test_parsing.py +++ b/tests/test_parsing.py @@ -7,9 +7,8 @@ Released under MIT license, see LICENSE file """ import pytest -from cmd2 import cmd2 +import cmd2 from cmd2.parsing import StatementParser - from cmd2 import utils @pytest.fixture diff --git a/tests/test_transcript.py b/tests/test_transcript.py index 70658161..302d80c8 100644 --- a/tests/test_transcript.py +++ b/tests/test_transcript.py @@ -15,8 +15,9 @@ import tempfile from unittest import mock import pytest -from cmd2 import cmd2 +import cmd2 from .conftest import run_cmd, StdOut +from cmd2 import transcript class CmdLineApp(cmd2.Cmd): @@ -177,7 +178,7 @@ this is a \/multiline\/ command def test_parse_transcript_expected(expected, transformed): app = CmdLineApp() - class TestMyAppCase(cmd2.Cmd2TestCase): + class TestMyAppCase(transcript.Cmd2TestCase): cmdapp = app testcase = TestMyAppCase() |