MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / test_path_completion_no_path

Function test_path_completion_no_path

tests/test_completion.py:513–534  ·  view source on GitHub ↗
(cmd2_app)

Source from the content-addressed store, hash-verified

511
512
513def test_path_completion_no_path(cmd2_app) -> None:
514 # Run path complete with search text that isn't preceded by a path. This should use CWD as the path.
515 text = "p"
516 line = f"shell ls {text}"
517 endidx = len(line)
518 begidx = endidx - len(text)
519 completions_no_text = cmd2_app.path_complete(text, line, begidx, endidx)
520
521 # Run path complete with path set to the CWD
522 text = os.getcwd() + os.path.sep + text
523 line = f"shell ls {text}"
524 endidx = len(line)
525 begidx = endidx - len(text)
526 completions_cwd = cmd2_app.path_complete(text, line, begidx, endidx)
527
528 # To compare matches, strip off the CWD from the front of completions_cwd (leave the 's').
529 stripped_paths = [CompletionItem(value=item.text.replace(text[:-1], "", 1)) for item in completions_cwd]
530 completions_cwd = dataclasses.replace(completions_cwd, items=stripped_paths)
531
532 # Verify that the first test gave results for entries in the cwd
533 assert completions_no_text == completions_cwd
534 assert completions_cwd
535
536
537@pytest.mark.skipif(sys.platform == "win32", reason="this only applies on systems where the root directory is a slash")

Callers

nothing calls this directly

Calls 2

CompletionItemClass · 0.90
path_completeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…