From 74129347da01bae550a56f3ecc09be7aec64d5c8 Mon Sep 17 00:00:00 2001 From: Kevin Van Brunt Date: Thu, 27 Sep 2018 20:01:02 -0400 Subject: Made _func_named() more reliable Added unit tests --- tests/conftest.py | 4 +--- tests/test_completion.py | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/conftest.py b/tests/conftest.py index b86622ac..949d5419 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_completion.py b/tests/test_completion.py index 40299954..8741fbd5 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' -- cgit v1.2.1