mirror of
https://github.com/simonw/files-to-prompt.git
synced 2025-10-23 00:02:47 +03:00
Add --cxml flag (#16)
Refs #15 --------- Co-authored-by: Simon Willison <swillison@gmail.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import os
|
||||
|
||||
from click.testing import CliRunner
|
||||
|
||||
from files_to_prompt.cli import cli
|
||||
|
||||
|
||||
@@ -186,3 +188,56 @@ def test_binary_file_warning(tmpdir):
|
||||
"Warning: Skipping file test_dir/binary_file.bin due to UnicodeDecodeError"
|
||||
in stderr
|
||||
)
|
||||
|
||||
|
||||
def test_xml_format_dir(tmpdir):
|
||||
runner = CliRunner()
|
||||
with tmpdir.as_cwd():
|
||||
os.makedirs("test_dir")
|
||||
with open("test_dir/file1.txt", "w") as f:
|
||||
f.write("Contents of file1")
|
||||
with open("test_dir/file2.txt", "w") as f:
|
||||
f.write("Contents of file2")
|
||||
|
||||
result = runner.invoke(cli, ["test_dir", "--cxml"])
|
||||
assert result.exit_code == 0
|
||||
actual = result.output
|
||||
expected = """
|
||||
<documents>
|
||||
<document path="test_dir/file1.txt">
|
||||
Contents of file1
|
||||
</document>
|
||||
<document path="test_dir/file2.txt">
|
||||
Contents of file2
|
||||
</document>
|
||||
</documents>
|
||||
"""
|
||||
assert expected.strip() == actual.strip()
|
||||
|
||||
|
||||
def test_cxml_format_multiple_paths(tmpdir):
|
||||
runner = CliRunner()
|
||||
with tmpdir.as_cwd():
|
||||
os.makedirs("test_dir")
|
||||
with open("test_dir/file1.txt", "w") as f:
|
||||
f.write("Contents of file1")
|
||||
with open("test_dir/file2.txt", "w") as f:
|
||||
f.write("Contents of file2")
|
||||
|
||||
result = runner.invoke(
|
||||
cli, ["test_dir/file1.txt", "test_dir/file2.txt", "--cxml"]
|
||||
)
|
||||
|
||||
assert result.exit_code == 0
|
||||
actual = result.output
|
||||
expected = """
|
||||
<documents>
|
||||
<document path="test_dir/file1.txt">
|
||||
Contents of file1
|
||||
</document>
|
||||
<document path="test_dir/file2.txt">
|
||||
Contents of file2
|
||||
</document>
|
||||
</documents>
|
||||
"""
|
||||
assert expected.strip() == actual.strip()
|
||||
|
||||
Reference in New Issue
Block a user