|
1 | 1 | import os |
2 | 2 | import pytest |
| 3 | +import re |
3 | 4 |
|
4 | 5 | from click.testing import CliRunner |
5 | 6 |
|
6 | 7 | from files_to_prompt.cli import cli |
7 | 8 |
|
8 | 9 |
|
| 10 | +def filenames_from_cxml(cxml_string): |
| 11 | + "Return set of filenames from <source>...</source> tags" |
| 12 | + return set(re.findall(r"<source>(.*?)</source>", cxml_string)) |
| 13 | + |
| 14 | + |
9 | 15 | def test_basic_functionality(tmpdir): |
10 | 16 | runner = CliRunner() |
11 | 17 | with tmpdir.as_cwd(): |
@@ -44,23 +50,44 @@ def test_ignore_gitignore(tmpdir): |
44 | 50 | runner = CliRunner() |
45 | 51 | with tmpdir.as_cwd(): |
46 | 52 | os.makedirs("test_dir") |
| 53 | + os.makedirs("test_dir/nested_include") |
| 54 | + os.makedirs("test_dir/nested_ignore") |
47 | 55 | with open("test_dir/.gitignore", "w") as f: |
48 | 56 | f.write("ignored.txt") |
49 | 57 | with open("test_dir/ignored.txt", "w") as f: |
50 | 58 | f.write("This file should be ignored") |
51 | 59 | with open("test_dir/included.txt", "w") as f: |
52 | 60 | f.write("This file should be included") |
53 | | - |
54 | | - result = runner.invoke(cli, ["test_dir"]) |
| 61 | + with open("test_dir/nested_include/included2.txt", "w") as f: |
| 62 | + f.write("This nested file should be included") |
| 63 | + with open("test_dir/nested_ignore/.gitignore", "w") as f: |
| 64 | + f.write("nested_ignore.txt") |
| 65 | + with open("test_dir/nested_ignore/nested_ignore.txt", "w") as f: |
| 66 | + f.write("This nested file should not be included") |
| 67 | + with open("test_dir/nested_ignore/actually_include.txt", "w") as f: |
| 68 | + f.write("This nested file should actually be included") |
| 69 | + |
| 70 | + result = runner.invoke(cli, ["test_dir", "-c"]) |
55 | 71 | assert result.exit_code == 0 |
56 | | - assert "test_dir/ignored.txt" not in result.output |
57 | | - assert "test_dir/included.txt" in result.output |
58 | | - |
59 | | - result = runner.invoke(cli, ["test_dir", "--ignore-gitignore"]) |
60 | | - assert result.exit_code == 0 |
61 | | - assert "test_dir/ignored.txt" in result.output |
62 | | - assert "This file should be ignored" in result.output |
63 | | - assert "test_dir/included.txt" in result.output |
| 72 | + filenames = filenames_from_cxml(result.output) |
| 73 | + |
| 74 | + assert filenames == { |
| 75 | + "test_dir/included.txt", |
| 76 | + "test_dir/nested_include/included2.txt", |
| 77 | + "test_dir/nested_ignore/actually_include.txt", |
| 78 | + } |
| 79 | + |
| 80 | + result2 = runner.invoke(cli, ["test_dir", "-c", "--ignore-gitignore"]) |
| 81 | + assert result2.exit_code == 0 |
| 82 | + filenames2 = filenames_from_cxml(result2.output) |
| 83 | + |
| 84 | + assert filenames2 == { |
| 85 | + "test_dir/included.txt", |
| 86 | + "test_dir/ignored.txt", |
| 87 | + "test_dir/nested_include/included2.txt", |
| 88 | + "test_dir/nested_ignore/nested_ignore.txt", |
| 89 | + "test_dir/nested_ignore/actually_include.txt", |
| 90 | + } |
64 | 91 |
|
65 | 92 |
|
66 | 93 | def test_multiple_paths(tmpdir): |
|
0 commit comments