|
9 | 9 | import pytest |
10 | 10 |
|
11 | 11 | import shtab |
12 | | -from shtab.main import extract_stdout, get_main_parser, main |
| 12 | +from shtab.main import get_main_parser, main |
13 | 13 |
|
14 | 14 | fix_shell = pytest.mark.parametrize("shell", shtab.SUPPORTED_SHELLS) |
15 | 15 |
|
@@ -82,6 +82,31 @@ def test_main_self_completion(shell, caplog, capsys): |
82 | 82 | assert not caplog.record_tuples |
83 | 83 |
|
84 | 84 |
|
| 85 | +@pytest.mark.parametrize('output', ["-", "stdout", "test.txt"]) |
| 86 | +@fix_shell |
| 87 | +def test_main_output_path(shell, caplog, capsys, change_dir, output): |
| 88 | + assert not capsys.readouterr().out |
| 89 | + with caplog.at_level(logging.INFO): |
| 90 | + try: |
| 91 | + main(["-s", shell, "shtab.main.get_main_parser", "-o", output]) |
| 92 | + except SystemExit: |
| 93 | + pass |
| 94 | + |
| 95 | + captured = capsys.readouterr() |
| 96 | + assert not captured.err |
| 97 | + expected = { |
| 98 | + "bash": "complete -o filenames -F _shtab_shtab shtab", "zsh": "_shtab_shtab_commands()", |
| 99 | + "tcsh": "complete shtab"} |
| 100 | + |
| 101 | + if output in ("-", "stdout"): |
| 102 | + assert expected[shell] in captured.out |
| 103 | + else: |
| 104 | + assert not captured.out |
| 105 | + assert expected[shell] in (change_dir / output).read_text() |
| 106 | + |
| 107 | + assert not caplog.record_tuples |
| 108 | + |
| 109 | + |
85 | 110 | @fix_shell |
86 | 111 | def test_prog_override(shell, caplog, capsys): |
87 | 112 | with caplog.at_level(logging.INFO): |
@@ -342,17 +367,3 @@ def test_path_completion_after_redirection(caplog, change_dir): |
342 | 367 | shell.test('"${COMPREPLY[@]}" = "test_file.txt"', f"Redirection {redirection} failed") |
343 | 368 |
|
344 | 369 | assert not caplog.record_tuples |
345 | | - |
346 | | - |
347 | | -def test_extract_stdout(tmp_path): |
348 | | - path = tmp_path / "completions" |
349 | | - with extract_stdout(path) as output: |
350 | | - output.write("completion") |
351 | | - assert path.read_text() == "completion" |
352 | | - |
353 | | - |
354 | | -def test_extract_stdout_empty(capsys): |
355 | | - with extract_stdout(None) as output: |
356 | | - output.write("completion") |
357 | | - captured = capsys.readouterr() |
358 | | - assert captured.out == "completion" |
|
0 commit comments