summaryrefslogtreecommitdiffstats
path: root/python/mozbuild/mozbuild/test/test_vendor_tools.py
blob: 271be6d7dace2ba871b347b7648bb52a0acdf542 (plain)
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
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import mozunit

from mozbuild.vendor.vendor_manifest import list_of_paths_to_readable_string


def test_list_of_paths_to_readable_string():
    paths = ["/tmp/a", "/tmp/b"]
    s = list_of_paths_to_readable_string(paths)
    assert not s.endswith(", ]")
    assert s.endswith("]")
    assert "/tmp/a" in s
    assert "/tmp/b" in s

    paths = ["/tmp/a", "/tmp/b", "/tmp/c", "/tmp/d"]
    s = list_of_paths_to_readable_string(paths)
    assert not s.endswith(", ")
    assert s.endswith("]")
    assert "/tmp/a" not in s
    assert "/tmp/b" not in s
    assert "4 items in /tmp" in s

    paths = [
        "/tmp/a",
        "/tmp/b",
        "/tmp/c",
        "/tmp/d",
        "/tmp/d",
        "/tmp/d",
        "/tmp/d",
        "/tmp/d",
        "/tmp/d",
        "/tmp/d",
    ]
    s = list_of_paths_to_readable_string(paths)
    assert not s.endswith(", ")
    assert s.endswith("]")
    assert "/tmp/a" not in s
    assert " a" not in s
    assert "/tmp/b" not in s
    assert "10 (omitted) items in /tmp" in s

    paths = ["/tmp", "/foo"]
    s = list_of_paths_to_readable_string(paths)
    assert not s.endswith(", ")
    assert s.endswith("]")
    assert "/tmp" in s
    assert "/foo" in s

    paths = [
        "/tmp/a",
        "/tmp/b",
        "/tmp/c",
        "/tmp/d",
        "/tmp/d",
        "/tmp/d",
        "/tmp/d",
        "/tmp/d",
        "/tmp/d",
        "/tmp/d",
    ]
    paths.extend(["/foo/w", "/foo/x", "/foo/y", "/foo/z"])
    paths.extend(["/bar/m", "/bar/n"])
    paths.extend(["/etc"])
    s = list_of_paths_to_readable_string(paths)
    assert not s.endswith(", ")
    assert s.endswith("]")
    assert "/tmp/a" not in s
    assert " d" not in s
    assert "/tmp/b" not in s
    assert "10 (omitted) items in /tmp" in s

    assert "/foo/w" not in s
    assert "/foo/x" not in s
    assert "4 items in /foo" in s
    assert " w" in s

    assert "/bar/m" in s
    assert "/bar/n" in s

    assert "/etc" in s

    assert len(s) < len(str(paths))


if __name__ == "__main__":
    mozunit.main()