Skip to content

Commit e566196

Browse files
committed
Added unit test for path completion in root directory
1 parent ebe8873 commit e566196

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/test_completion.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,25 @@ def test_path_completion_no_path(cmd2_app):
400400
assert completions_no_text == completions_cwd
401401
assert completions_cwd
402402

403+
404+
@pytest.mark.skipif(sys.platform == 'win32', reason="this only applies on systems where the root directory is a slash")
405+
def test_path_completion_cwd_is_root_dir(cmd2_app):
406+
# Change our CWD to root dir
407+
cwd = os.getcwd()
408+
os.chdir(os.path.sep)
409+
410+
text = ''
411+
line = 'shell ls {}'.format(text)
412+
endidx = len(line)
413+
begidx = endidx - len(text)
414+
completions = cmd2_app.path_complete(text, line, begidx, endidx)
415+
416+
# No match should start with a slash
417+
assert not any(match.startswith(os.path.sep) for match in completions)
418+
419+
# Restore CWD
420+
os.chdir(cwd)
421+
403422
def test_path_completion_doesnt_match_wildcards(cmd2_app, request):
404423
test_dir = os.path.dirname(request.module.__file__)
405424

0 commit comments

Comments
 (0)