diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-09-27 21:52:38 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-09-27 21:52:38 -0400 |
commit | a67c694c153fd1d15c266d89bab29076d00919d5 (patch) | |
tree | 560dc2c7563e0cf4712e600c2f6c254e666c223d /tests | |
parent | 848372592577f02e03c063c6ec29a349a0f40071 (diff) | |
parent | b4e217239cf176b96aeb3b124eef3609e688d791 (diff) | |
download | cmd2-git-a67c694c153fd1d15c266d89bab29076d00919d5.tar.gz |
Merge branch 'macro' into argparse_conversion
Diffstat (limited to 'tests')
-rw-r--r-- | tests/conftest.py | 4 | ||||
-rw-r--r-- | tests/test_cmd2.py | 6 | ||||
-rw-r--r-- | tests/test_completion.py | 19 |
3 files changed, 22 insertions, 7 deletions
diff --git a/tests/conftest.py b/tests/conftest.py index 4083c50e..93348098 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -160,11 +160,9 @@ def complete_tester(text: str, line: str, begidx: int, endidx: int, app) -> Opti def get_endidx(): return endidx - first_match = None with mock.patch.object(readline, 'get_line_buffer', get_line): with mock.patch.object(readline, 'get_begidx', get_begidx): with mock.patch.object(readline, 'get_endidx', get_endidx): # Run the readline tab-completion function with readline mocks in place first_match = app.complete(text, 0) - - return first_match + return first_match diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index 37a5ed96..a87cba18 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -1852,7 +1852,7 @@ def test_alias_create_with_macro_name(base_app, capsys): run_cmd(base_app, 'macro create {} help'.format(macro)) run_cmd(base_app, 'alias create {} help'.format(macro)) out, err = capsys.readouterr() - assert "Aliases cannot have the same name as a macro" in err + assert "Alias cannot have the same name as a macro" in err def test_alias_list_invalid_alias(base_app, capsys): # Look up invalid alias @@ -1953,13 +1953,13 @@ def test_macro_create_with_alias_name(base_app, capsys): run_cmd(base_app, 'alias create {} help'.format(macro)) run_cmd(base_app, 'macro create {} help'.format(macro)) out, err = capsys.readouterr() - assert "Macros cannot have the same name as an alias" in err + assert "Macro cannot have the same name as an alias" in err def test_macro_create_with_command_name(base_app, capsys): macro = "my_macro" run_cmd(base_app, 'macro create help stuff') out, err = capsys.readouterr() - assert "Macros cannot have the same name as a command" in err + assert "Macro cannot have the same name as a command" in err def test_macro_create_with_args(base_app, capsys): # Create the macro diff --git a/tests/test_completion.py b/tests/test_completion.py index 7179d2f5..8bf0cc02 100644 --- a/tests/test_completion.py +++ b/tests/test_completion.py @@ -15,7 +15,7 @@ import sys import pytest import cmd2 from cmd2 import utils -from .conftest import complete_tester +from .conftest import base_app, complete_tester, normalize, run_cmd from examples.subcommands import SubcommandsExample # List of strings used with completion functions @@ -113,6 +113,23 @@ def test_complete_bogus_command(cmd2_app): first_match = complete_tester(text, line, begidx, endidx, cmd2_app) assert first_match is None +def test_complete_macro(base_app, request): + # Create the macro + out = run_cmd(base_app, 'macro create fake pyscript {1}') + assert out == normalize("Macro 'fake' created") + + # Macros do path completion + test_dir = os.path.dirname(request.module.__file__) + + text = os.path.join(test_dir, 'script.py') + line = 'fake {}'.format(text) + + endidx = len(line) + begidx = endidx - len(text) + + first_match = complete_tester(text, line, begidx, endidx, base_app) + assert first_match == text + ' ' + def test_cmd2_command_completion_multiple(cmd2_app): text = 'h' |