Debian Codegraph @

tests/integrations/file/test_File__sorted_depth_first_groups.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", "groups"),
10 [
11 # Files in a single directory are sorted lexically into the same group
12 (
13 ["foo/bar/a.txt", "foo/bar/c.txt", "foo/bar/b.txt"],
14 [
15 ["foo/bar/c.txt", "foo/bar/b.txt", "foo/bar/a.txt"],
16 ],
17 ),
18 # Subfolders are sorted before files in that directory, and in a different
19 # group; but sorted lexically in themselves
20 (
21 [
22 "foo/bar/b",
23 "foo/bar/b/aaa.txt",
24 "foo/bar/b/zzz.txt",
25 "foo/bar/b/deeper",
26 "foo/bar/b/deeper/deeper_db2.txt",
27 "foo/bar/b/deeper/deeper_db1.txt",
28 "foo/bar/a.txt",
29 "foo/bar/c.txt",
30 "foo/bar/e.txt",
31 "foo/bar/d",
32 "foo/bar/d/deep_d2.txt",
33 "foo/bar/d/deep_d1.txt",
34 ],
35 [
36 ["foo/bar/d/deep_d2.txt", "foo/bar/d/deep_d1.txt"],
37 ["foo/bar/b/deeper/deeper_db2.txt", "foo/bar/b/deeper/deeper_db1.txt"],
38 ["foo/bar/b/deeper"],
39 ["foo/bar/b/zzz.txt", "foo/bar/b/aaa.txt"],
40 ["foo/bar/d", "foo/bar/b"],
41 ["foo/bar/e.txt", "foo/bar/c.txt", "foo/bar/a.txt"],
42 ],
43 ),
44 # If a folder contains both folders and files, the folders are in a different
45 # group the files, and are returned first.
46 (
47 [
48 "foo/bar/a",
49 "foo/bar/b.txt",
50 "foo/bar/c",
51 ],
52 [
53 [
54 "foo/bar/c",
55 "foo/bar/a",
56 ],
57 [
58 "foo/bar/b.txt",
59 ],
60 ],
61 ),
62 ],
63 )
64 def test_sorted_depth_first_groups(files, groups, tmp_path):
65 # Convert the strings into paths in the temp folder
66 paths = [tmp_path / file_path for file_path in files]
67
68 # Create files for all paths that have a suffix; otherwise, ensure the folder
69 # exists.
70 for file_path in paths:
71 if file_path.suffix:
72 create_file(tmp_path / file_path, content=str(file_path))
73 else:
74 file_path.mkdir(parents=True, exist_ok=True)
75
76 assert [list(group) for group in File.sorted_depth_first_groups(paths)] == [
77 [tmp_path / file_path for file_path in group] for group in groups
78 ]