Debian Codegraph @

tests/integrations/file/test_File__sorted_depth_first.py

raw
1 import pytest
2
3 from briefcase.integrations.file import File
4
5 from ...utils import create_file
6
7
8 @pytest.mark.parametrize(
9 ("files", "sorted"),
10 [
11 # Files in a directory are sorted lexically
12 (
13 ["foo/bar/a.txt", "foo/bar/c.txt", "foo/bar/b.txt"],
14 ["foo/bar/c.txt", "foo/bar/b.txt", "foo/bar/a.txt"],
15 ),
16 # Subfolders are sorted before files in that directory; but sorted lexically in themselves
17 (
18 [
19 "foo/bar/b",
20 "foo/bar/b/aaa.txt",
21 "foo/bar/b/zzz.txt",
22 "foo/bar/b/deeper",
23 "foo/bar/b/deeper/deeper_db2.txt",
24 "foo/bar/b/deeper/deeper_db1.txt",
25 "foo/bar/a.txt",
26 "foo/bar/c.txt",
27 "foo/bar/e.txt",
28 "foo/bar/d",
29 "foo/bar/d/deep_d2.txt",
30 "foo/bar/d/deep_d1.txt",
31 ],
32 [
33 "foo/bar/d/deep_d2.txt",
34 "foo/bar/d/deep_d1.txt",
35 "foo/bar/b/deeper/deeper_db2.txt",
36 "foo/bar/b/deeper/deeper_db1.txt",
37 "foo/bar/b/deeper",
38 "foo/bar/b/zzz.txt",
39 "foo/bar/b/aaa.txt",
40 "foo/bar/d",
41 "foo/bar/b",
42 "foo/bar/e.txt",
43 "foo/bar/c.txt",
44 "foo/bar/a.txt",
45 ],
46 ),
47 # If a folder contains both folders and files, the folders are returned first.
48 (
49 [
50 "foo/bar/a",
51 "foo/bar/b.txt",
52 "foo/bar/c",
53 ],
54 [
55 "foo/bar/c",
56 "foo/bar/a",
57 "foo/bar/b.txt",
58 ],
59 ),
60 ],
61 )
62 def test_sorted_depth_first(files, sorted, tmp_path):
63 # Convert the strings into paths in the temp folder
64 paths = [tmp_path / file_path for file_path in files]
65
66 # Create all the paths that have a suffix
67 for file_path in paths:
68 if file_path.suffix:
69 create_file(tmp_path / file_path, content=str(file_path))
70 else:
71 file_path.mkdir(parents=True, exist_ok=True)
72
73 assert File.sorted_depth_first(paths) == [
74 tmp_path / file_path for file_path in sorted
75 ]