|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
| 3 | +import platform |
| 4 | +import subprocess |
3 | 5 | import sys
|
4 | 6 | from pathlib import Path
|
5 | 7 | from typing import Any, Dict, List, Mapping, Protocol, Union
|
@@ -997,3 +999,53 @@ def test_secret_validator(
|
997 | 999 | tui.sendline(default)
|
998 | 1000 | tui.expect_exact("******")
|
999 | 1001 | tui.expect_exact(pexpect.EOF)
|
| 1002 | + |
| 1003 | + |
| 1004 | +# Related to https://github.com/prompt-toolkit/python-prompt-toolkit/issues/1243#issuecomment-706668723) |
| 1005 | +@pytest.mark.xfail( |
| 1006 | + platform.system() == "Windows", |
| 1007 | + reason="prompt-toolkit in subprocess call fails on Windows", |
| 1008 | +) |
| 1009 | +def test_interactive_session_required_for_question_prompt( |
| 1010 | + question_tree: QuestionTreeFixture, |
| 1011 | +) -> None: |
| 1012 | + """Answering a question prompt requires an interactive session.""" |
| 1013 | + src, dst = question_tree(type="str") |
| 1014 | + process = subprocess.run( |
| 1015 | + (*COPIER_PATH, "copy", str(src), str(dst)), |
| 1016 | + stdin=subprocess.PIPE, # Prevents interactive input |
| 1017 | + capture_output=True, |
| 1018 | + timeout=10, |
| 1019 | + ) |
| 1020 | + assert process.returncode == 1 |
| 1021 | + assert ( |
| 1022 | + b"Interactive session required: Use `--defaults` and/or `--data`/`--data-file`" |
| 1023 | + ) in process.stderr |
| 1024 | + |
| 1025 | + |
| 1026 | +# Related to https://github.com/prompt-toolkit/python-prompt-toolkit/issues/1243#issuecomment-706668723) |
| 1027 | +@pytest.mark.xfail( |
| 1028 | + platform.system() == "Windows", |
| 1029 | + reason="prompt-toolkit in subprocess call fails on Windows", |
| 1030 | +) |
| 1031 | +def test_interactive_session_required_for_overwrite_prompt( |
| 1032 | + tmp_path_factory: pytest.TempPathFactory, |
| 1033 | +) -> None: |
| 1034 | + """Overwriting a file without `--overwrite` flag requires an interactive session.""" |
| 1035 | + src, dst = map(tmp_path_factory.mktemp, ("src", "dst")) |
| 1036 | + build_file_tree( |
| 1037 | + { |
| 1038 | + (src / "foo.txt.jinja"): "bar", |
| 1039 | + (dst / "foo.txt"): "baz", |
| 1040 | + } |
| 1041 | + ) |
| 1042 | + process = subprocess.run( |
| 1043 | + (*COPIER_PATH, "copy", str(src), str(dst)), |
| 1044 | + stdin=subprocess.PIPE, # Prevents interactive input |
| 1045 | + capture_output=True, |
| 1046 | + timeout=10, |
| 1047 | + ) |
| 1048 | + assert process.returncode == 1 |
| 1049 | + assert ( |
| 1050 | + b"Interactive session required: Consider using `--overwrite`" in process.stderr |
| 1051 | + ) |
0 commit comments