(cmd2_app)
| 584 | |
| 585 | |
| 586 | def 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 | |
| 618 | def test_basic_completion(cmd2_app) -> None: |
nothing calls this directly
no test coverage detected
searching dependent graphs…