Mostly borrowed from argcomplete's unit tests Modified to take an application instead of an ArgumentParser Command is the current command being completed and point is the index into the command where the completion is triggered.
(
self,
app: ArgcompleteApp,
command: str,
point: t.Union[str, int, None] = None,
**kwargs: t.Any,
)
| 96 | os.environ = _old_environ |
| 97 | |
| 98 | def run_completer( |
| 99 | self, |
| 100 | app: ArgcompleteApp, |
| 101 | command: str, |
| 102 | point: t.Union[str, int, None] = None, |
| 103 | **kwargs: t.Any, |
| 104 | ) -> t.List[str]: |
| 105 | """Mostly borrowed from argcomplete's unit tests |
| 106 | |
| 107 | Modified to take an application instead of an ArgumentParser |
| 108 | |
| 109 | Command is the current command being completed and point is the index |
| 110 | into the command where the completion is triggered. |
| 111 | """ |
| 112 | if point is None: |
| 113 | point = str(len(command)) |
| 114 | # Flushing tempfile was leading to CI failures with Bad file descriptor, not sure why. |
| 115 | # Fortunately we can just write to a StringIO instead. |
| 116 | # print("Writing completions to temp file with mode=", write_mode) |
| 117 | # from tempfile import TemporaryFile |
| 118 | # with TemporaryFile(mode=write_mode) as t: |
| 119 | strio = io.StringIO() |
| 120 | os.environ["COMP_LINE"] = command |
| 121 | os.environ["COMP_POINT"] = str(point) |
| 122 | |
| 123 | with pytest.raises(CustomError) as cm: # noqa: PT012 |
| 124 | app.argcomplete_kwargs = dict( |
| 125 | output_stream=strio, exit_method=CustomError.exit, **kwargs |
| 126 | ) |
| 127 | app.initialize() |
| 128 | |
| 129 | if str(cm.value) != "0": |
| 130 | raise RuntimeError(f"Unexpected exit code {cm.value}") |
| 131 | out = strio.getvalue() |
| 132 | return out.split(self.IFS) |
| 133 | |
| 134 | def test_complete_simple_app(self, argcomplete_on): |
| 135 | app = ArgcompleteApp() |
no test coverage detected