Test that file paths can handle tab completion.
(
tmp_path_factory: pytest.TempPathFactory, spawn_timeout: int
)
| 175 | reason="pexpect.spawn does not work on Windows", |
| 176 | ) |
| 177 | def test_path_completion( |
| 178 | tmp_path_factory: pytest.TempPathFactory, spawn_timeout: int |
| 179 | ) -> None: |
| 180 | """Test that file paths can handle tab completion.""" |
| 181 | from pexpect.pty_spawn import spawn as pexpect_spawn |
| 182 | |
| 183 | src, dst, completedir = map(tmp_path_factory.mktemp, ("src", "dst", "my-directory")) |
| 184 | with local.cwd(src): |
| 185 | build_file_tree(PATH_TREE) |
| 186 | git_save(tag="v1") |
| 187 | git("commit", "--allow-empty", "-m", "v2") |
| 188 | git("tag", "v2") |
| 189 | with local.cwd(dst): |
| 190 | # Disable subprocess timeout if debugging (except coverage) |
| 191 | # See https://stackoverflow.com/a/67065084/1468388 |
| 192 | tracer = getattr(sys, "gettrace", lambda: None)() |
| 193 | timeout = ( |
| 194 | None |
| 195 | if not isinstance(tracer, (CTracer, type(None))) or spawn_timeout == 0 |
| 196 | else spawn_timeout |
| 197 | ) |
| 198 | |
| 199 | # Copy the v1 template |
| 200 | cmd = COPIER_PATH + ("copy", str(src), ".", "--vcs-ref=v1") |
| 201 | tui = pexpect_spawn(cmd[0], list(cmd[1:]), timeout=timeout) |
| 202 | |
| 203 | # Check that default values are maintained |
| 204 | expect_prompt(tui, "current_location", "path") |
| 205 | tui.sendline() |
| 206 | |
| 207 | # Check tab completion of a filesystem path (/path/to/my-direct<TAB> should |
| 208 | # complete to /path/to/my-directory0) |
| 209 | expect_prompt(tui, "star_location", "path", help="Location of a bonus star") |
| 210 | tui.send(str(completedir)[:-4]) |
| 211 | tui.send(Keyboard.Tab) |
| 212 | tui.sendline() |
| 213 | tui.sendline() |
| 214 | |
| 215 | tui.expect_exact(pexpect.EOF) |
| 216 | |
| 217 | answers = load_answersfile_data(".") |
| 218 | assert answers.get("_commit") == "v1" |
| 219 | assert answers.get("current_location") == "/dev/warppipe0" |
| 220 | assert answers.get("star_location") == str(completedir) |
| 221 | |
| 222 | |
| 223 | @pytest.mark.parametrize( |
nothing calls this directly
no test coverage detected