Developer tools dump stack traces, exit codes, and jargon. Figuring out *what to do next* often means searching the same Stack Overflow answers again.
| 1 | """Tests for stdin / file helpers.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | from pathlib import Path |
| 6 | |
| 7 | import pytest |
| 8 | |
| 9 | from why_failed.stdin import InputError, join_args, read_file, stdin_is_piped |
| 10 | |
| 11 | |
| 12 | def test_join_args() -> None: |
| 13 | assert join_args(["a", "b", "c"]) == "a b c" |
| 14 | |
| 15 | |
| 16 | def test_read_file(tmp_path: Path) -> None: |
| 17 | path = tmp_path / "err.txt" |
| 18 | path.write_text("fatal: not a git repository", encoding="utf-8") |
| 19 | assert "not a git repository" in read_file(path) |
| 20 | |
| 21 | |
| 22 | def test_read_file_missing(tmp_path: Path) -> None: |
| 23 | with pytest.raises(InputError, match="File not found"): |
| 24 | read_file(tmp_path / "missing.log") |
| 25 | |
| 26 | |
| 27 | def test_stdin_is_piped_returns_bool() -> None: |
| 28 | assert isinstance(stdin_is_piped(), bool) |