Force a blank token to make sure ArgparseCompleter consumes them like argparse does
(ac_app)
| 657 | |
| 658 | |
| 659 | def test_autocomp_blank_token(ac_app) -> None: |
| 660 | """Force a blank token to make sure ArgparseCompleter consumes them like argparse does""" |
| 661 | from cmd2.argparse_completer import ( |
| 662 | ArgparseCompleter, |
| 663 | ) |
| 664 | |
| 665 | blank = "" |
| 666 | |
| 667 | # Blank flag arg will be consumed. Therefore we expect to be completing the first positional. |
| 668 | text = "" |
| 669 | line = f"completer -c {blank} {text}" |
| 670 | endidx = len(line) |
| 671 | begidx = endidx - len(text) |
| 672 | |
| 673 | completer = ArgparseCompleter(ac_app.completer_parser, ac_app) |
| 674 | tokens = ["-c", blank, text] |
| 675 | completions = completer.complete(text, line, begidx, endidx, tokens) |
| 676 | expected = ArgparseCompleterTester.completions_for_pos_1 |
| 677 | assert completions.to_strings() == Completions.from_values(expected).to_strings() |
| 678 | |
| 679 | # Blank arg for first positional will be consumed. Therefore we expect to be completing the second positional. |
| 680 | text = "" |
| 681 | line = f"completer {blank} {text}" |
| 682 | endidx = len(line) |
| 683 | begidx = endidx - len(text) |
| 684 | |
| 685 | completer = ArgparseCompleter(ac_app.completer_parser, ac_app) |
| 686 | tokens = [blank, text] |
| 687 | completions = completer.complete(text, line, begidx, endidx, tokens) |
| 688 | expected = ArgparseCompleterTester.completions_for_pos_2 |
| 689 | assert completions.to_strings() == Completions.from_values(expected).to_strings() |
| 690 | |
| 691 | |
| 692 | @with_ansi_style(ru.AllowStyle.ALWAYS) |
nothing calls this directly
no test coverage detected
searching dependent graphs…