-
-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathtest_files_to_prompt.py
164 lines (140 loc) · 6.93 KB
/
test_files_to_prompt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import os
from click.testing import CliRunner
from files_to_prompt.cli import cli
def test_basic_functionality(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"])
assert result.exit_code == 0
assert "test_dir/file1.txt" in result.output
assert "Contents of file1" in result.output
assert "test_dir/file2.txt" in result.output
assert "Contents of file2" in result.output
def test_include_hidden(tmpdir):
runner = CliRunner()
with tmpdir.as_cwd():
os.makedirs("test_dir")
with open("test_dir/.hidden.txt", "w") as f:
f.write("Contents of hidden file")
result = runner.invoke(cli, ["test_dir"])
assert result.exit_code == 0
assert "test_dir/.hidden.txt" not in result.output
result = runner.invoke(cli, ["test_dir", "--include-hidden"])
assert result.exit_code == 0
assert "test_dir/.hidden.txt" in result.output
assert "Contents of hidden file" in result.output
def test_ignore_gitignore(tmpdir):
runner = CliRunner()
with tmpdir.as_cwd():
os.makedirs("test_dir")
with open("test_dir/.gitignore", "w") as f:
f.write("ignored.txt")
with open("test_dir/ignored.txt", "w") as f:
f.write("This file should be ignored")
with open("test_dir/included.txt", "w") as f:
f.write("This file should be included")
result = runner.invoke(cli, ["test_dir"])
assert result.exit_code == 0
assert "test_dir/ignored.txt" not in result.output
assert "test_dir/included.txt" in result.output
result = runner.invoke(cli, ["test_dir", "--ignore-gitignore"])
assert result.exit_code == 0
assert "test_dir/ignored.txt" in result.output
assert "This file should be ignored" in result.output
assert "test_dir/included.txt" in result.output
def test_multiple_paths(tmpdir):
runner = CliRunner()
with tmpdir.as_cwd():
os.makedirs("test_dir1")
with open("test_dir1/file1.txt", "w") as f:
f.write("Contents of file1")
os.makedirs("test_dir2")
with open("test_dir2/file2.txt", "w") as f:
f.write("Contents of file2")
with open("single_file.txt", "w") as f:
f.write("Contents of single file")
result = runner.invoke(cli, ["test_dir1", "test_dir2", "single_file.txt"])
assert result.exit_code == 0
assert "test_dir1/file1.txt" in result.output
assert "Contents of file1" in result.output
assert "test_dir2/file2.txt" in result.output
assert "Contents of file2" in result.output
assert "single_file.txt" in result.output
assert "Contents of single file" in result.output
def test_ignore_patterns(tmpdir):
runner = CliRunner()
with tmpdir.as_cwd():
os.makedirs("test_dir")
with open("test_dir/file_to_ignore.txt", "w") as f:
f.write("This file should be ignored due to ignore patterns")
with open("test_dir/file_to_include.txt", "w") as f:
f.write("This file should be included")
result = runner.invoke(cli, ["test_dir", "--ignore", "*.txt"])
assert result.exit_code == 0
assert "test_dir/file_to_ignore.txt" not in result.output
assert "This file should be ignored due to ignore patterns" not in result.output
assert "test_dir/file_to_include.txt" not in result.output
result = runner.invoke(cli, ["test_dir", "--ignore", "file_to_ignore.*"])
assert result.exit_code == 0
assert "test_dir/file_to_ignore.txt" not in result.output
assert "This file should be ignored due to ignore patterns" not in result.output
assert "test_dir/file_to_include.txt" in result.output
assert "This file should be included" in result.output
def test_mixed_paths_with_options(tmpdir):
runner = CliRunner()
with tmpdir.as_cwd():
os.makedirs("test_dir")
with open("test_dir/.gitignore", "w") as f:
f.write("ignored_in_gitignore.txt\n.hidden_ignored_in_gitignore.txt")
with open("test_dir/ignored_in_gitignore.txt", "w") as f:
f.write("This file should be ignored by .gitignore")
with open("test_dir/.hidden_ignored_in_gitignore.txt", "w") as f:
f.write("This hidden file should be ignored by .gitignore")
with open("test_dir/included.txt", "w") as f:
f.write("This file should be included")
with open("test_dir/.hidden_included.txt", "w") as f:
f.write("This hidden file should be included")
with open("single_file.txt", "w") as f:
f.write("Contents of single file")
result = runner.invoke(cli, ["test_dir", "single_file.txt"])
assert result.exit_code == 0
assert "test_dir/ignored_in_gitignore.txt" not in result.output
assert "test_dir/.hidden_ignored_in_gitignore.txt" not in result.output
assert "test_dir/included.txt" in result.output
assert "test_dir/.hidden_included.txt" not in result.output
assert "single_file.txt" in result.output
assert "Contents of single file" in result.output
result = runner.invoke(cli, ["test_dir", "single_file.txt", "--include-hidden"])
assert result.exit_code == 0
assert "test_dir/ignored_in_gitignore.txt" not in result.output
assert "test_dir/.hidden_ignored_in_gitignore.txt" not in result.output
assert "test_dir/included.txt" in result.output
assert "test_dir/.hidden_included.txt" in result.output
assert "single_file.txt" in result.output
assert "Contents of single file" in result.output
result = runner.invoke(
cli, ["test_dir", "single_file.txt", "--ignore-gitignore"]
)
assert result.exit_code == 0
assert "test_dir/ignored_in_gitignore.txt" in result.output
assert "test_dir/.hidden_ignored_in_gitignore.txt" not in result.output
assert "test_dir/included.txt" in result.output
assert "test_dir/.hidden_included.txt" not in result.output
assert "single_file.txt" in result.output
assert "Contents of single file" in result.output
result = runner.invoke(
cli,
["test_dir", "single_file.txt", "--ignore-gitignore", "--include-hidden"],
)
assert result.exit_code == 0
assert "test_dir/ignored_in_gitignore.txt" in result.output
assert "test_dir/.hidden_ignored_in_gitignore.txt" in result.output
assert "test_dir/included.txt" in result.output
assert "test_dir/.hidden_included.txt" in result.output
assert "single_file.txt" in result.output
assert "Contents of single file" in result.output