summaryrefslogtreecommitdiffstats
path: root/python/mozbuild/mozbuild/test/test_telemetry.py
blob: 894e32ee2d092efcd3765b7b08f48442a33ae510 (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
91
92
93
94
95
96
97
98
99
100
101
102
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/

import os

import buildconfig
import mozunit

from mozbuild.telemetry import filter_args

TELEMETRY_LOAD_ERROR = """
Error loading telemetry. mach output:
=========================================================
%s
=========================================================
"""


def test_path_filtering():
    srcdir_path = os.path.join(buildconfig.topsrcdir, "a")
    srcdir_path_2 = os.path.join(buildconfig.topsrcdir, "a/b/c")
    objdir_path = os.path.join(buildconfig.topobjdir, "x")
    objdir_path_2 = os.path.join(buildconfig.topobjdir, "x/y/z")
    home_path = os.path.join(os.path.expanduser("~"), "something_in_home")
    other_path = "/other/path"
    args = filter_args(
        "pass",
        [
            "python",
            "-c",
            "pass",
            srcdir_path,
            srcdir_path_2,
            objdir_path,
            objdir_path_2,
            home_path,
            other_path,
        ],
        buildconfig.topsrcdir,
        buildconfig.topobjdir,
        cwd=buildconfig.topsrcdir,
    )

    expected = [
        "a",
        "a/b/c",
        "$topobjdir/x",
        "$topobjdir/x/y/z",
        "$HOME/something_in_home",
        "<path omitted>",
    ]
    assert args == expected


def test_path_filtering_in_objdir():
    srcdir_path = os.path.join(buildconfig.topsrcdir, "a")
    srcdir_path_2 = os.path.join(buildconfig.topsrcdir, "a/b/c")
    objdir_path = os.path.join(buildconfig.topobjdir, "x")
    objdir_path_2 = os.path.join(buildconfig.topobjdir, "x/y/z")
    other_path = "/other/path"
    args = filter_args(
        "pass",
        [
            "python",
            "-c",
            "pass",
            srcdir_path,
            srcdir_path_2,
            objdir_path,
            objdir_path_2,
            other_path,
        ],
        buildconfig.topsrcdir,
        buildconfig.topobjdir,
        cwd=buildconfig.topobjdir,
    )
    expected = ["$topsrcdir/a", "$topsrcdir/a/b/c", "x", "x/y/z", "<path omitted>"]
    assert args == expected


def test_path_filtering_other_cwd(tmpdir):
    srcdir_path = os.path.join(buildconfig.topsrcdir, "a")
    srcdir_path_2 = os.path.join(buildconfig.topsrcdir, "a/b/c")
    other_path = str(tmpdir.join("other"))
    args = filter_args(
        "pass",
        ["python", "-c", "pass", srcdir_path, srcdir_path_2, other_path],
        buildconfig.topsrcdir,
        buildconfig.topobjdir,
        cwd=str(tmpdir),
    )
    expected = [
        "$topsrcdir/a",
        "$topsrcdir/a/b/c",
        # cwd-relative paths should be relativized
        "other",
    ]
    assert args == expected


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