File: test_File__sorted_depth_first.py

package info (click to toggle)
python-briefcase 0.3.22-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,300 kB
  • sloc: python: 59,405; makefile: 57
file content (75 lines) | stat: -rw-r--r-- 2,309 bytes parent folder | download | duplicates (2)
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
import pytest

from briefcase.integrations.file import File

from ...utils import create_file


@pytest.mark.parametrize(
    "files, sorted",
    [
        # Files in a directory are sorted lexically
        (
            ["foo/bar/a.txt", "foo/bar/c.txt", "foo/bar/b.txt"],
            ["foo/bar/c.txt", "foo/bar/b.txt", "foo/bar/a.txt"],
        ),
        # Subfolders are sorted before files in that directory; but sorted lexically in themselves
        (
            [
                "foo/bar/b",
                "foo/bar/b/aaa.txt",
                "foo/bar/b/zzz.txt",
                "foo/bar/b/deeper",
                "foo/bar/b/deeper/deeper_db2.txt",
                "foo/bar/b/deeper/deeper_db1.txt",
                "foo/bar/a.txt",
                "foo/bar/c.txt",
                "foo/bar/e.txt",
                "foo/bar/d",
                "foo/bar/d/deep_d2.txt",
                "foo/bar/d/deep_d1.txt",
            ],
            [
                "foo/bar/d/deep_d2.txt",
                "foo/bar/d/deep_d1.txt",
                "foo/bar/b/deeper/deeper_db2.txt",
                "foo/bar/b/deeper/deeper_db1.txt",
                "foo/bar/b/deeper",
                "foo/bar/b/zzz.txt",
                "foo/bar/b/aaa.txt",
                "foo/bar/d",
                "foo/bar/b",
                "foo/bar/e.txt",
                "foo/bar/c.txt",
                "foo/bar/a.txt",
            ],
        ),
        # If a folder contains both folders and files, the folders are returned first.
        (
            [
                "foo/bar/a",
                "foo/bar/b.txt",
                "foo/bar/c",
            ],
            [
                "foo/bar/c",
                "foo/bar/a",
                "foo/bar/b.txt",
            ],
        ),
    ],
)
def test_sorted_depth_first(files, sorted, tmp_path):
    # Convert the strings into paths in the temp folder
    paths = [tmp_path / file_path for file_path in files]

    # Create all the paths that have a suffix
    for file_path in paths:
        if file_path.suffix:
            create_file(tmp_path / file_path, content=str(file_path))
        else:
            file_path.mkdir(parents=True, exist_ok=True)

    assert File.sorted_depth_first(paths) == [
        tmp_path / file_path for file_path in sorted
    ]