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

Function test_path_completion_user_path_expansion

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

Source from the content-addressed store, hash-verified

584
585
586def test_path_completion_user_path_expansion(cmd2_app) -> None:
587 # Run path with a tilde and a slash
588 if sys.platform.startswith("win"):
589 cmd = "dir"
590 else:
591 cmd = "ls"
592
593 # Use a ~ which will be expanded into the user's home directory
594 text = f"~{os.path.sep}"
595 line = f"shell {cmd} {text}"
596 endidx = len(line)
597 begidx = endidx - len(text)
598 completions_tilde_slash = cmd2_app.path_complete(text, line, begidx, endidx)
599
600 # To compare matches, strip off ~/ from the front of completions_tilde_slash.
601 stripped_paths = [CompletionItem(value=item.text.replace(text, "", 1)) for item in completions_tilde_slash]
602 completions_tilde_slash = dataclasses.replace(completions_tilde_slash, items=stripped_paths)
603
604 # Run path complete on the user's home directory
605 text = os.path.expanduser("~") + os.path.sep
606 line = f"shell {cmd} {text}"
607 endidx = len(line)
608 begidx = endidx - len(text)
609 completions_home = cmd2_app.path_complete(text, line, begidx, endidx)
610
611 # To compare matches, strip off user's home directory from the front of completions_home.
612 stripped_paths = [CompletionItem(value=item.text.replace(text, "", 1)) for item in completions_home]
613 completions_home = dataclasses.replace(completions_home, items=stripped_paths)
614
615 assert completions_tilde_slash == completions_home
616
617
618def test_basic_completion(cmd2_app) -> None:

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…