Example #1
0
def test_path_completion_cwd():
    # Run path complete with no path and no search text
    text = ''
    line = 'shell ls {}'.format(text)
    endidx = len(line)
    begidx = endidx - len(text)
    completions_empty = path_complete(text, line, begidx, endidx)

    # Run path complete with path set to the CWD
    cwd = os.getcwd()
    line = 'shell ls {}'.format(cwd)
    endidx = len(line)
    begidx = endidx - len(text)
    completions_cwd = path_complete(text, line, begidx, endidx)

    # Verify that the results are the same in both cases and that there is something there
    assert completions_empty == completions_cwd
    assert completions_cwd
Example #2
0
def test_path_completion_syntax_err(request):
    test_dir = os.path.dirname(request.module.__file__)

    text = 'c'
    path = os.path.join(test_dir, text)
    line = 'shell cat " {}'.format(path)

    endidx = len(line)
    begidx = endidx - len(text)

    assert path_complete(text, line, begidx, endidx) == []
Example #3
0
def test_path_completion_single_mid(request):
    test_dir = os.path.dirname(request.module.__file__)

    text = 'tes'
    path = os.path.join(test_dir, 'c')
    line = 'shell cat {}'.format(path)

    begidx = line.find(text)
    endidx = begidx + len(text)

    assert path_complete(text, line, begidx, endidx) == ['tests' + os.path.sep]
Example #4
0
def test_path_completion_directories_only(request):
    test_dir = os.path.dirname(request.module.__file__)

    text = 's'
    path = os.path.join(test_dir, text)
    line = 'shell cat {}'.format(path)

    endidx = len(line)
    begidx = endidx - len(text)

    assert path_complete(text, line, begidx, endidx,
                         dir_only=True) == ['scripts' + os.path.sep]
Example #5
0
def test_path_completion_doesnt_match_wildcards(request):
    test_dir = os.path.dirname(request.module.__file__)

    text = 'c*'
    path = os.path.join(test_dir, text)
    line = 'shell cat {}'.format(path)

    endidx = len(line)
    begidx = endidx - len(text)

    # Currently path completion doesn't accept wildcards, so will always return empty results
    assert path_complete(text, line, begidx, endidx) == []
Example #6
0
def test_path_completion_multiple(request):
    test_dir = os.path.dirname(request.module.__file__)

    text = 's'
    path = os.path.join(test_dir, text)
    line = 'shell cat {}'.format(path)

    endidx = len(line)
    begidx = endidx - len(text)

    assert path_complete(text, line, begidx, endidx) == [
        'script.py', 'script.txt', 'scripts' + os.path.sep
    ]
Example #7
0
def test_path_completion_user_expansion():
    # Run path with just a tilde
    text = ''
    if sys.platform.startswith('win'):
        line = 'shell dir ~{}'.format(text)
    else:
        line = 'shell ls ~{}'.format(text)
    endidx = len(line)
    begidx = endidx - len(text)
    completions_tilde = path_complete(text, line, begidx, endidx)

    # Run path complete on the user's home directory
    user_dir = os.path.expanduser('~')
    if sys.platform.startswith('win'):
        line = 'shell dir {}'.format(user_dir)
    else:
        line = 'shell ls {}'.format(user_dir)
    endidx = len(line)
    begidx = endidx - len(text)
    completions_home = path_complete(text, line, begidx, endidx)

    # Verify that the results are the same in both cases
    assert completions_tilde == completions_home
Example #8
0
def test_path_completion_no_tokens():
    text = ''
    line = 'shell'
    endidx = len(line)
    begidx = endidx - len(text)
    assert path_complete(text, line, begidx, endidx) == []
Example #9
0
 def complete_show(self, text, line, start_index, end_index):
     return cmd2.path_complete(text, line, start_index, end_index)