aboutsummaryrefslogtreecommitdiff
blob: 624dc90a10b8636807c1e3598590dad2b4e32cea (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
from pkgcheck.checks import imlate
from snakeoil.cli import arghparse

from .. import misc


def mk_check(
    selected_arches=("x86", "ppc", "amd64"), arches=None, stable_arches=None, source_arches=None
):
    if arches is None:
        arches = selected_arches
    if stable_arches is None:
        stable_arches = selected_arches
    return imlate.ImlateCheck(
        arghparse.Namespace(
            selected_arches=selected_arches,
            arches=arches,
            stable_arches=stable_arches,
            source_arches=source_arches,
        )
    )


def mk_pkg(ver, keywords="", slot="0"):
    return misc.FakePkg(f"dev-util/diffball-{ver}", data={"SLOT": slot, "KEYWORDS": keywords})


class TestImlateCheck(misc.ReportTestCase):

    check_kls = imlate.ImlateCheck

    def test_all_unstable(self):
        self.assertNoReport(mk_check(), [mk_pkg(str(x), "~x86 ~amd64") for x in range(10)])

    def test_all_stable(self):
        self.assertNoReport(mk_check(), [mk_pkg("0.9", "amd64 x86")])

    def test_unselected_arch(self):
        self.assertNoReport(mk_check(), [mk_pkg("0.9", "~mips amd64")])

    def test_specified_stable_arches(self):
        # pkg doesn't have any unstable arches we care about
        self.assertNoReport(mk_check(source_arches=("arm", "arm64")), [mk_pkg("0.9", "~x86 amd64")])

        # pkg doesn't have any stable arches we care about
        self.assertNoReport(mk_check(source_arches=("arm64",)), [mk_pkg("0.9", "~x86 amd64")])

        # only flag arches we care about
        r = self.assertReport(
            mk_check(source_arches=("amd64",), selected_arches=("arm64",)),
            [mk_pkg("0.9", "~arm64 ~x86 amd64")],
        )
        assert isinstance(r, imlate.PotentialStable)
        assert r.stable == ("amd64",)
        assert r.keywords == ("~arm64",)
        assert r.version == "0.9"

    def test_lagging_keyword(self):
        r = self.assertReport(mk_check(), [mk_pkg("0.8", "x86 amd64"), mk_pkg("0.9", "x86 ~amd64")])
        assert isinstance(r, imlate.LaggingStable)
        assert r.stable == ("x86",)
        assert r.keywords == ("~amd64",)
        assert r.version == "0.9"
        assert "x86" in str(r) and "~amd64" in str(r)

    def test_potential_keyword(self):
        r = self.assertReport(mk_check(), [mk_pkg("0.9", "~x86 amd64")])
        assert isinstance(r, imlate.PotentialStable)
        assert r.stable == ("amd64",)
        assert r.keywords == ("~x86",)
        assert r.version == "0.9"
        assert "amd64" in str(r) and "~x86" in str(r)

    def test_multiple_unstable_pkgs(self):
        r = self.assertReport(
            mk_check(), [mk_pkg("0.7", "~x86"), mk_pkg("0.8", "~x86"), mk_pkg("0.9", "~x86 amd64")]
        )
        assert r.stable == ("amd64",)
        assert r.keywords == ("~x86",)
        assert r.version == "0.9"

    def test_multiple_stable_arches(self):
        r = self.assertReport(
            mk_check(), [mk_pkg("0.7", "~x86 ~ppc"), mk_pkg("0.9", "~x86 ppc amd64")]
        )
        assert r.stable == ("amd64", "ppc")
        assert r.keywords == ("~x86",)
        assert r.version == "0.9"

    def test_multiple_potential_arches(self):
        r = self.assertReport(mk_check(), [mk_pkg("0.7", "~x86"), mk_pkg("0.9", "~x86 ~ppc amd64")])
        assert r.stable == ("amd64",)
        assert r.keywords == (
            "~ppc",
            "~x86",
        )
        assert r.version == "0.9"

    def test_multiple_lagging_slots(self):
        r = self.assertReports(
            mk_check(),
            [
                mk_pkg("0.7", slot="0", keywords="x86 ppc"),
                mk_pkg("0.9", slot="0", keywords="~x86 ppc"),
                mk_pkg("1.0", slot="1", keywords="x86 ppc"),
                mk_pkg("1.2", slot="1", keywords="x86 ~ppc"),
            ],
        )
        assert len(r) == 2
        assert isinstance(r[0], imlate.LaggingStable)
        assert r[0].slot == "0"
        assert r[0].stable == ("ppc",)
        assert r[0].keywords == ("~x86",)
        assert r[0].version == "0.9"
        assert isinstance(r[1], imlate.LaggingStable)
        assert r[1].slot == "1"
        assert r[1].stable == ("x86",)
        assert r[1].keywords == ("~ppc",)
        assert r[1].version == "1.2"

    def test_multiple_potential_slots(self):
        r = self.assertReports(
            mk_check(),
            [
                mk_pkg("0.9", slot="0", keywords="x86 ~ppc"),
                mk_pkg("1.2", slot="1", keywords="x86 ~ppc"),
            ],
        )
        assert len(r) == 2
        assert isinstance(r[0], imlate.PotentialStable)
        assert r[0].slot == "0"
        assert r[0].stable == ("x86",)
        assert r[0].keywords == ("~ppc",)
        assert r[0].version == "0.9"
        assert isinstance(r[1], imlate.PotentialStable)
        assert r[1].slot == "1"
        assert r[1].stable == ("x86",)
        assert r[1].keywords == ("~ppc",)
        assert r[1].version == "1.2"

    def test_drop_newer_slot_stables(self):
        selected_arches = ("x86", "amd64")
        all_arches = ("x86", "amd64", "arm64")
        r = self.assertReport(
            mk_check(selected_arches=selected_arches, arches=all_arches),
            [
                mk_pkg("0.7", "amd64 x86 ~arm64"),
                mk_pkg("0.8", "amd64 ~x86 ~arm64"),
                mk_pkg("0.9", "~amd64 ~x86 arm64"),
            ],
        )
        assert isinstance(r, imlate.LaggingStable)
        assert r.stable == ("amd64",)
        assert r.keywords == ("~x86",)
        assert r.version == "0.8"