-o/--output option, closes #9

This commit is contained in:
Simon Willison
2024-09-08 22:43:42 -07:00
parent d016523c22
commit 243799505d
3 changed files with 83 additions and 21 deletions

View File

@@ -222,3 +222,35 @@ Contents of file2.txt
</documents>
"""
assert expected.strip() == actual.strip()
@pytest.mark.parametrize("arg", ("-o", "--output"))
def test_output_option(tmpdir, arg):
runner = CliRunner()
with tmpdir.as_cwd():
os.makedirs("test_dir")
with open("test_dir/file1.txt", "w") as f:
f.write("Contents of file1.txt")
with open("test_dir/file2.txt", "w") as f:
f.write("Contents of file2.txt")
output_file = "output.txt"
result = runner.invoke(
cli, ["test_dir", arg, output_file], catch_exceptions=False
)
assert result.exit_code == 0
assert not result.output
with open(output_file, "r") as f:
actual = f.read()
expected = """
test_dir/file1.txt
---
Contents of file1.txt
---
test_dir/file2.txt
---
Contents of file2.txt
---
"""
assert expected.strip() == actual.strip()