@@ -32,7 +32,6 @@ def setUpClass(self):
32
32
self .path = Path (self .tmp .name )
33
33
open (self .path / "file.cpp" , mode = "w" ).close ()
34
34
open (self .path / "other.cpp" , mode = "w" ).close ()
35
- open (self .path / "unused.cpp" , mode = "w" ).close ()
36
35
os .symlink (self .path / "file.cpp" , self .path / "symlink.cpp" )
37
36
38
37
@classmethod
@@ -153,6 +152,72 @@ def test_report(self):
153
152
self .assertTrue ("[-B | 1 | 100.00 | 50.00]" in output )
154
153
self .assertTrue ("[A- | 1 | 100.00 | 50.00]" in output )
155
154
155
+ def test_levels (self ):
156
+ """Check report --levels flag works correctly"""
157
+ # Set up subdirectories for this test
158
+ tmp = tempfile .TemporaryDirectory ()
159
+ path = Path (tmp .name )
160
+ os .makedirs (path / "first" / "second" / "third" )
161
+ open (path / "first" / "one.cpp" , mode = "w" ).close ()
162
+ open (path / "first" / "second" / "two.cpp" , mode = "w" ).close ()
163
+
164
+ codebase = CodeBase (path )
165
+ configuration = {
166
+ "X" : [
167
+ {
168
+ "file" : str (path / "first" / "one.cpp" ),
169
+ "defines" : [],
170
+ "include_paths" : [],
171
+ "include_files" : [],
172
+ },
173
+ ],
174
+ "Y" : [
175
+ {
176
+ "file" : str (path / "first" / "second" / "two.cpp" ),
177
+ "defines" : [],
178
+ "include_paths" : [],
179
+ "include_files" : [],
180
+ },
181
+ ],
182
+ }
183
+ state = finder .find (
184
+ path ,
185
+ codebase ,
186
+ configuration ,
187
+ show_progress = False ,
188
+ )
189
+
190
+ # By default, we should see all levels of the tree.
191
+ stream = io .StringIO ()
192
+ report .files (codebase , state , stream = stream )
193
+ output = stream .getvalue ()
194
+ self .assertTrue (str (path ) in output )
195
+ self .assertTrue ("first/" in output )
196
+ self .assertTrue ("one.cpp" in output )
197
+ self .assertTrue ("two.cpp" in output )
198
+
199
+ # With two levels, the "second" directory should be collapsed.
200
+ # This will hide "two.cpp" from the output.
201
+ stream = io .StringIO ()
202
+ report .files (codebase , state , stream = stream , levels = 2 )
203
+ output = stream .getvalue ()
204
+ self .assertTrue (str (path ) in output )
205
+ self .assertTrue ("first/" in output )
206
+ self .assertTrue ("one.cpp" in output )
207
+ self .assertFalse ("two.cpp" in output )
208
+
209
+ # With just one level, the "first" directory should be collapsed.
210
+ # This will hide "one.cpp" and "two.cpp" from the output.
211
+ stream = io .StringIO ()
212
+ report .files (codebase , state , stream = stream , levels = 1 )
213
+ output = stream .getvalue ()
214
+ self .assertTrue (str (path ) in output )
215
+ self .assertTrue ("first/" in output )
216
+ self .assertFalse ("one.cpp" in output )
217
+ self .assertFalse ("two.cpp" in output )
218
+
219
+ tmp .cleanup ()
220
+
156
221
157
222
if __name__ == "__main__" :
158
223
unittest .main ()
0 commit comments