diff options
Diffstat (limited to 'tests/ebuild/test_atom.py')
-rw-r--r-- | tests/ebuild/test_atom.py | 572 |
1 files changed, 340 insertions, 232 deletions
diff --git a/tests/ebuild/test_atom.py b/tests/ebuild/test_atom.py index 0893b817..d13efa83 100644 --- a/tests/ebuild/test_atom.py +++ b/tests/ebuild/test_atom.py @@ -20,6 +20,7 @@ def assert_equal_bidirectional(o1, o2): assert o2 == o1 assert cmp(o2, o1) == 0 + def assert_not_equal_bidirectional(o1, o2): # is why we test the comparison *both* ways. assert o1 != o2 @@ -27,8 +28,8 @@ def assert_not_equal_bidirectional(o1, o2): assert o2 != o1 assert cmp(o2, o1) != 0 -class TestAtom(TestRestriction): +class TestAtom(TestRestriction): class kls(atom.atom): __inst_caching__ = True __slots__ = () @@ -52,37 +53,48 @@ class TestAtom(TestRestriction): assert d.dnf_solutions(True) == bd.dnf_solutions() assert d.cnf_solutions(True) == bd.cnf_solutions() - @pytest.mark.parametrize("atom", ( - "dev-util/diffball", "=dev-util/diffball-0.7.1", - ">foon/bar-1:2[-4,3]", "=foon/bar-2*", "~foon/bar-2.3", - "cat/pkg:0", "cat/pkg:5", "cat/pkg:0/5", "cat/pkg:5/5", - "cat/pkg:=", "cat/pkg:0=", "cat/pkg:*", - "!dev-util/diffball", "!=dev-util/diffball-0.7*", - "foon/bar::gentoo", ">=foon/bar-10_alpha1:1::gentoo[-not,use]", - "!!dev-util/diffball[use]", - )) + @pytest.mark.parametrize( + "atom", + ( + "dev-util/diffball", + "=dev-util/diffball-0.7.1", + ">foon/bar-1:2[-4,3]", + "=foon/bar-2*", + "~foon/bar-2.3", + "cat/pkg:0", + "cat/pkg:5", + "cat/pkg:0/5", + "cat/pkg:5/5", + "cat/pkg:=", + "cat/pkg:0=", + "cat/pkg:*", + "!dev-util/diffball", + "!=dev-util/diffball-0.7*", + "foon/bar::gentoo", + ">=foon/bar-10_alpha1:1::gentoo[-not,use]", + "!!dev-util/diffball[use]", + ), + ) def test_str_hash(self, atom): assert str(self.kls(atom)) == atom - assert hash(self.kls(atom, disable_inst_caching=True)) == hash(self.kls(atom, disable_inst_caching=True)) + assert hash(self.kls(atom, disable_inst_caching=True)) == hash( + self.kls(atom, disable_inst_caching=True) + ) def test_blockers(self): - pytest.raises(errors.MalformedAtom, self.kls, - "!!dev-util/diffball", eapi='0') - pytest.raises(errors.MalformedAtom, self.kls, - "!!dev-util/diffball", eapi='1') - pytest.raises(errors.MalformedAtom, self.kls, - "!!!dev-util/diffball", eapi='2') + pytest.raises(errors.MalformedAtom, self.kls, "!!dev-util/diffball", eapi="0") + pytest.raises(errors.MalformedAtom, self.kls, "!!dev-util/diffball", eapi="1") + pytest.raises(errors.MalformedAtom, self.kls, "!!!dev-util/diffball", eapi="2") for x in range(0, 2): obj = self.kls("!dev-util/diffball", eapi=str(x)) assert obj.blocks assert obj.blocks_temp_ignorable assert not obj.blocks_strongly - obj = self.kls("!!dev-util/diffball", eapi='2') + obj = self.kls("!!dev-util/diffball", eapi="2") assert obj.blocks assert not obj.blocks_temp_ignorable assert obj.blocks_strongly - def test_iter(self): d = self.kls("!>=dev-util/diffball-0.7:1::gentoo[use,x]") assert list(d) == list(d.restrictions) @@ -94,14 +106,10 @@ class TestAtom(TestRestriction): assert a == loads(dumps(a)) def test_glob(self): - pytest.raises(errors.MalformedAtom, self.kls, - "dev-util/diffball-1*") - pytest.raises(errors.MalformedAtom, self.kls, - "dev-util/diffball-1.*") - pytest.raises(errors.MalformedAtom, self.kls, - "~dev-util/diffball-1*") - pytest.raises(errors.MalformedAtom, self.kls, - "~dev-util/diffball-1.*") + pytest.raises(errors.MalformedAtom, self.kls, "dev-util/diffball-1*") + pytest.raises(errors.MalformedAtom, self.kls, "dev-util/diffball-1.*") + pytest.raises(errors.MalformedAtom, self.kls, "~dev-util/diffball-1*") + pytest.raises(errors.MalformedAtom, self.kls, "~dev-util/diffball-1.*") a = self.kls("=dev-util/diffball-1.2*") self.assertMatch(a, FakePkg("dev-util/diffball-1.2")) @@ -134,8 +142,13 @@ class TestAtom(TestRestriction): # <, =, > ops = (-1, 0, 1) - for ops, ver in ((-1, "1.0"), (-1, "1.1"), - (0, "1.1-r2"), (1, "1.1-r3"), (1, "1.2")): + for ops, ver in ( + (-1, "1.0"), + (-1, "1.1"), + (0, "1.1-r2"), + (1, "1.1-r3"), + (1, "1.2"), + ): if not isinstance(ops, (list, tuple)): ops = (ops,) a = self.make_atom(astr, ops, ver) @@ -166,10 +179,18 @@ class TestAtom(TestRestriction): # with ~ pytest.raises(errors.MalformedAtom, self.kls, f"~{astr}-1-r0") - @pytest.mark.parametrize(("eapi", "defaults"), ( - (2, False), (3, False), - (4, True), (5, True), (6, True), (7, True), (8, True), - )) + @pytest.mark.parametrize( + ("eapi", "defaults"), + ( + (2, False), + (3, False), + (4, True), + (5, True), + (6, True), + (7, True), + (8, True), + ), + ) def test_eapi_use(self, eapi, defaults): astr = "dev-util/bsdiff" c = FakePkg(f"{astr}-1", use=("debug",), iuse=("debug", "foon"), slot=1) @@ -178,18 +199,26 @@ class TestAtom(TestRestriction): # Valid chars: [a-zA-Z0-9_@+-] for use_text in ( - '[zZaA09]', '[x@y]', '[x+y]', '[x-y]', '[x_y]', - '[-x_y]', '[x?]', '[!x?]', '[x=]', '[!x=]', + "[zZaA09]", + "[x@y]", + "[x+y]", + "[x-y]", + "[x_y]", + "[-x_y]", + "[x?]", + "[!x?]", + "[x=]", + "[!x=]", ): - kls(f'{astr}{use_text}') + kls(f"{astr}{use_text}") if defaults: - kls(f'{astr}[x(+)]') - kls(f'{astr}[x(-)]') + kls(f"{astr}[x(+)]") + kls(f"{astr}[x(-)]") with pytest.raises(errors.MalformedAtom): - kls(f'{astr}[x(+-)]') + kls(f"{astr}[x(+-)]") with pytest.raises(errors.MalformedAtom): - kls(f'{astr}[x(@)]') + kls(f"{astr}[x(@)]") self.assertMatch(kls(f"{astr}[debug(+)]"), c) self.assertMatch(kls(f"{astr}[debug(-)]"), c) self.assertMatch(kls(f"{astr}[missing(+)]"), c) @@ -203,15 +232,21 @@ class TestAtom(TestRestriction): self.assertMatch(kls(f"{astr}[missing(+),debug(+)]"), c) else: with pytest.raises(errors.MalformedAtom): - kls(f'{astr}[x(+)]') + kls(f"{astr}[x(+)]") with pytest.raises(errors.MalformedAtom): - kls(f'{astr}[x(-)]') + kls(f"{astr}[x(-)]") for use_text in ( # '.' not a valid char in use deps "[x.y]", # Use deps start with an alphanumeric char (non-transitive) - "[@x]", "[_x]", "[+x]", "[-@x]", "[-_x]", "[-+x]", "[--x]", + "[@x]", + "[_x]", + "[+x]", + "[-@x]", + "[-_x]", + "[-+x]", + "[--x]", ): with pytest.raises(errors.MalformedAtom): kls(f"{astr}{use_text}") @@ -251,54 +286,66 @@ class TestAtom(TestRestriction): self.assertNotMatch(self.kls(f"{astr}:2"), c) # note the above isn't compliant with eapi2/3; thus this test with pytest.raises(errors.MalformedAtom): - self.kls("dev-util/foo:0", eapi='0') + self.kls("dev-util/foo:0", eapi="0") # shouldn't puke, but has, thus checking" self.kls("sys-libs/db:4.4") self.kls(f"{astr}:azAZ.-+_09") - self.kls(f"{astr}:_bar") # According to PMS, underscore and plus-sign are - self.kls(f"{astr}:+bar") # not invalid first chars in a slot dep - - @pytest.mark.parametrize("atom", ( - "dev-util/foo:", - "dev-util/foo:1,,0", - "dev-util/foo:1:", - "dev-util/foo:-1", - "dev-util/foo:.1", - "dev-util/foo:1@2", - "dev-util/foo[bar]:1", - )) + self.kls(f"{astr}:_bar") # According to PMS, underscore and plus-sign are + self.kls(f"{astr}:+bar") # not invalid first chars in a slot dep + + @pytest.mark.parametrize( + "atom", + ( + "dev-util/foo:", + "dev-util/foo:1,,0", + "dev-util/foo:1:", + "dev-util/foo:-1", + "dev-util/foo:.1", + "dev-util/foo:1@2", + "dev-util/foo[bar]:1", + ), + ) def test_slot_malformed_atom(self, atom): with pytest.raises(errors.MalformedAtom): self.kls(atom) def test_slot_operators_and_subslots(self): - pytest.raises(errors.MalformedAtom, self.kls, "sys-libs/db:*", eapi='4') - self.kls("sys-libs/db:*", eapi='5') - pytest.raises(errors.MalformedAtom, self.kls, "sys-libs/db:=", eapi='4') - self.kls("sys-libs/db:=", eapi='5') - pytest.raises(errors.MalformedAtom, self.kls, "sys-libs/db:==", eapi='5') - pytest.raises(errors.MalformedAtom, self.kls, "sys-libs/db:1=", eapi='4') - pytest.raises(errors.MalformedAtom, self.kls, "sys-libs/db:2/3.0=", eapi='4') - pytest.raises(errors.MalformedAtom, self.kls, "sys-libs/db:2/3.0", eapi='1') - pytest.raises(errors.MalformedAtom, self.kls, "sys-libs/db:/=", eapi='5') - pytest.raises(errors.MalformedAtom, self.kls, "sys-libs/db:/1=", eapi='5') - pytest.raises(errors.MalformedAtom, self.kls, "sys-libs/db:1/=", eapi='5') - pytest.raises(errors.MalformedAtom, self.kls, "sys-libs/db:*1/=", eapi='5') + pytest.raises(errors.MalformedAtom, self.kls, "sys-libs/db:*", eapi="4") + self.kls("sys-libs/db:*", eapi="5") + pytest.raises(errors.MalformedAtom, self.kls, "sys-libs/db:=", eapi="4") + self.kls("sys-libs/db:=", eapi="5") + pytest.raises(errors.MalformedAtom, self.kls, "sys-libs/db:==", eapi="5") + pytest.raises(errors.MalformedAtom, self.kls, "sys-libs/db:1=", eapi="4") + pytest.raises(errors.MalformedAtom, self.kls, "sys-libs/db:2/3.0=", eapi="4") + pytest.raises(errors.MalformedAtom, self.kls, "sys-libs/db:2/3.0", eapi="1") + pytest.raises(errors.MalformedAtom, self.kls, "sys-libs/db:/=", eapi="5") + pytest.raises(errors.MalformedAtom, self.kls, "sys-libs/db:/1=", eapi="5") + pytest.raises(errors.MalformedAtom, self.kls, "sys-libs/db:1/=", eapi="5") + pytest.raises(errors.MalformedAtom, self.kls, "sys-libs/db:*1/=", eapi="5") for subslot in ("/1.0", ""): - pytest.raises(errors.MalformedAtom, self.kls, f"sys-libs/db:*4{subslot}", eapi='5') - pytest.raises(errors.MalformedAtom, self.kls, f"sys-libs/db:4{subslot}*", eapi='5') - pytest.raises(errors.MalformedAtom, self.kls, f"sys-libs/db:=4{subslot}", eapi='5') - self.kls(f"sys-libs/db:4{subslot}=", eapi='5') - self.kls(f"sys-libs/db:3.2{subslot}=", eapi='5') - pytest.raises(errors.MalformedAtom, self.kls, f"sys-libs/db:4{subslot}==", eapi='5') + pytest.raises( + errors.MalformedAtom, self.kls, f"sys-libs/db:*4{subslot}", eapi="5" + ) + pytest.raises( + errors.MalformedAtom, self.kls, f"sys-libs/db:4{subslot}*", eapi="5" + ) + pytest.raises( + errors.MalformedAtom, self.kls, f"sys-libs/db:=4{subslot}", eapi="5" + ) + self.kls(f"sys-libs/db:4{subslot}=", eapi="5") + self.kls(f"sys-libs/db:3.2{subslot}=", eapi="5") + pytest.raises( + errors.MalformedAtom, self.kls, f"sys-libs/db:4{subslot}==", eapi="5" + ) def check_it(text, slot, subslot, operator): obj = self.kls(f"sys-libs/db{text}") assert obj.slot == slot assert obj.subslot == subslot assert obj.slot_operator == operator + check_it(":4", "4", None, None) check_it(":=", None, None, "=") check_it(":4=", "4", None, "=") @@ -306,16 +353,22 @@ class TestAtom(TestRestriction): check_it(":*", None, None, "*") # Verify restrictions. - self.assertMatch(self.kls("sys-libs/db:1="), - FakePkg("sys-libs/db-1", slot="1")) - self.assertMatch(self.kls("sys-libs/db:1/2="), - FakePkg("sys-libs/db-1", slot="1", subslot="2")) - self.assertNotMatch(self.kls("sys-libs/db:1/2.3="), - FakePkg("sys-libs/db-1", slot="1", subslot="2")) - self.assertNotMatch(self.kls("sys-libs/db:1/2.3="), - FakePkg("sys-libs/db-1", slot="1")) - self.assertMatch(self.kls("sys-libs/db:1a.2/2.3"), - FakePkg("sys-libs/db-1", slot="1a.2", subslot="2.3")) + self.assertMatch(self.kls("sys-libs/db:1="), FakePkg("sys-libs/db-1", slot="1")) + self.assertMatch( + self.kls("sys-libs/db:1/2="), + FakePkg("sys-libs/db-1", slot="1", subslot="2"), + ) + self.assertNotMatch( + self.kls("sys-libs/db:1/2.3="), + FakePkg("sys-libs/db-1", slot="1", subslot="2"), + ) + self.assertNotMatch( + self.kls("sys-libs/db:1/2.3="), FakePkg("sys-libs/db-1", slot="1") + ) + self.assertMatch( + self.kls("sys-libs/db:1a.2/2.3"), + FakePkg("sys-libs/db-1", slot="1a.2", subslot="2.3"), + ) def test_getattr(self): # assert it explodes for bad attr access. @@ -327,15 +380,17 @@ class TestAtom(TestRestriction): def assertAttr(attr): assert restrictions[pos].attr == attr, ( f"expected attr {attr!r} at {pos} for ver({ver}), repo({repo}) use({use}), " - f"slot({slot}): got {restrictions[pos].attr!r} from {restrictions!r}") + f"slot({slot}): got {restrictions[pos].attr!r} from {restrictions!r}" + ) return pos + 1 - slot = '' + slot = "" + def f(): - for pref, ver in (('', ''), ('=', '-0.1')): - for repo in ('', '::gentoo'): - for slot in ('', ':1'): - for use in ('', '[x]'): + for pref, ver in (("", ""), ("=", "-0.1")): + for repo in ("", "::gentoo"): + for slot in ("", ":1"): + for use in ("", "[x]"): yield pref, ver, repo, slot, use for pref, ver, repo, slot, use in f(): @@ -348,46 +403,66 @@ class TestAtom(TestRestriction): restrictions = o.restrictions assert len(restrictions) == count - assert [getattr(x, 'type', None) for x in restrictions] == ['package'] * count + assert [getattr(x, "type", None) for x in restrictions] == [ + "package" + ] * count if repo: - pos = assertAttr('repo.repo_id') - pos = assertAttr('package') - pos = assertAttr('category') + pos = assertAttr("repo.repo_id") + pos = assertAttr("package") + pos = assertAttr("category") if ver: assert isinstance(restrictions[pos], restricts.VersionMatch) pos += 1 if slot: - pos = assertAttr('slot') + pos = assertAttr("slot") if use: - pos = assertAttr('use') + pos = assertAttr("use") def test_eapi0(self): - for postfix in (':1', ':1,2', ':asdf', '::asdf', '::asdf-x86', '[x]', - '[x,y]', ':1[x,y]', '[x,y]:1', ':1::repo'): + for postfix in ( + ":1", + ":1,2", + ":asdf", + "::asdf", + "::asdf-x86", + "[x]", + "[x,y]", + ":1[x,y]", + "[x,y]:1", + ":1::repo", + ): with pytest.raises(errors.MalformedAtom): # "dev-util/foon{postfix} must be invalid in EAPI 0", - self.kls(f"dev-util/foon{postfix}", eapi='0') + self.kls(f"dev-util/foon{postfix}", eapi="0") def test_eapi1(self): - for postfix in (':1,2', '::asdf', '::asdf-x86', '[x]', - '[x,y]', ':1[x,y]', '[x,y]:1', ':1:repo'): + for postfix in ( + ":1,2", + "::asdf", + "::asdf-x86", + "[x]", + "[x,y]", + ":1[x,y]", + "[x,y]:1", + ":1:repo", + ): with pytest.raises(errors.MalformedAtom): # "dev-util/foon{postfix} must be invalid in EAPI 1" - self.kls(f"dev-util/foon{postfix}", eapi='1') - self.kls("dev-util/foon:1", eapi='1') - self.kls("dev-util/foon:12", eapi='1') + self.kls(f"dev-util/foon{postfix}", eapi="1") + self.kls("dev-util/foon:1", eapi="1") + self.kls("dev-util/foon:12", eapi="1") with pytest.raises(errors.MalformedAtom): # "dev-util/foon[dar] must be invalid in EAPI 1" - self.kls("dev-util/foon:1,2", eapi='1') + self.kls("dev-util/foon:1,2", eapi="1") def test_eapi3(self): - self.kls("dev-util/foon:1", eapi='3') - self.kls("dev-util/foon:2", eapi='3') - self.kls("!dev-util/foon:1", eapi='3') - self.kls("dev-util/foon:1[x]", eapi='3') - self.kls("dev-util/foon:1[x?]", eapi='3') + self.kls("dev-util/foon:1", eapi="3") + self.kls("dev-util/foon:2", eapi="3") + self.kls("!dev-util/foon:1", eapi="3") + self.kls("dev-util/foon:1[x]", eapi="3") + self.kls("dev-util/foon:1[x?]", eapi="3") with pytest.raises(errors.MalformedAtom): - self.kls("dev-util/foon:1::dar", eapi='3') + self.kls("dev-util/foon:1::dar", eapi="3") def test_repo_id(self): astr = "dev-util/bsdiff" @@ -408,115 +483,140 @@ class TestAtom(TestRestriction): with pytest.raises(errors.MalformedAtom): self.kls("dev-util/foon::gentoo-x86", eapi=str(x)) - @pytest.mark.parametrize("atom", ( - '~dev-util/spork', '>dev-util/spork', 'dev-util/spork-3', 'spork' - )) + @pytest.mark.parametrize( + "atom", ("~dev-util/spork", ">dev-util/spork", "dev-util/spork-3", "spork") + ) def test_invalid_atom(self, atom): with pytest.raises(errors.MalformedAtom): self.kls(atom) - @pytest.mark.parametrize(("this", "that", "result"), ( - ('cat/pkg', 'pkg/cat', False), - ('cat/pkg', 'cat/pkg', True), - ('cat/pkg:1', 'cat/pkg:2', False), - ('cat/pkg:1', 'cat/pkg:1', True), - ('cat/pkg:1', 'cat/pkg[foo]', True), - ('cat/pkg:0/0', 'cat/pkg:0/1', False), - ('cat/pkg:0/0', 'cat/pkg:0/0', True), - ('cat/pkg:0/0', 'cat/pkg:0', True), - ('cat/pkg:0/0', 'cat/pkg', True), - ('cat/pkg[foo]', 'cat/pkg[-bar]', True), - ('cat/pkg[foo]', 'cat/pkg[-foo]', False), - ('>cat/pkg-3', '>cat/pkg-1', True), - ('>cat/pkg-3', '<cat/pkg-3', False), - ('>=cat/pkg-3', '<cat/pkg-3', False), - ('>cat/pkg-2', '=cat/pkg-2*', True), - ('<cat/pkg-2_alpha1', '=cat/pkg-2*', True), - ('=cat/pkg-2', '=cat/pkg-2', True), - ('=cat/pkg-3', '=cat/pkg-2', False), - ('=cat/pkg-2', '>cat/pkg-2', False), - ('=cat/pkg-2', '>=cat/pkg-2', True), - ('~cat/pkg-2', '~cat/pkg-2', True), - ('~cat/pkg-2', '~cat/pkg-2.1', False), - ('=cat/pkg-2*', '=cat/pkg-2.3*', True), - ('>cat/pkg-2.4', '=cat/pkg-2*', True), - ('<cat/pkg-2.4', '=cat/pkg-2*', True), - ('<cat/pkg-1', '=cat/pkg-2*', False), - ('~cat/pkg-2', '>cat/pkg-2-r1', True), - ('~cat/pkg-2', '<=cat/pkg-2', True), - ('=cat/pkg-2-r2*', '<=cat/pkg-2-r20', True), - ('=cat/pkg-2-r2*', '<cat/pkg-2-r20', True), - ('=cat/pkg-2-r2*', '<=cat/pkg-2-r2', True), - ('~cat/pkg-2', '<cat/pkg-2', False), - ('=cat/pkg-1-r10*', '~cat/pkg-1', True), - ('=cat/pkg-1-r1*', '<cat/pkg-1-r1', False), - ('=cat/pkg-1*', '>cat/pkg-2', False), - ('>=cat/pkg-8.4', '=cat/pkg-8.3.4*', False), - ('cat/pkg::gentoo', 'cat/pkg', True), - ('cat/pkg::gentoo', 'cat/pkg::foo', False), - # known to cause an assplosion, thus redundant test. - ('=sys-devel/gcc-4.1.1-r3', '=sys-devel/gcc-3.3*', False), - ('=sys-libs/db-4*', '~sys-libs/db-4.3.29', True), - )) + @pytest.mark.parametrize( + ("this", "that", "result"), + ( + ("cat/pkg", "pkg/cat", False), + ("cat/pkg", "cat/pkg", True), + ("cat/pkg:1", "cat/pkg:2", False), + ("cat/pkg:1", "cat/pkg:1", True), + ("cat/pkg:1", "cat/pkg[foo]", True), + ("cat/pkg:0/0", "cat/pkg:0/1", False), + ("cat/pkg:0/0", "cat/pkg:0/0", True), + ("cat/pkg:0/0", "cat/pkg:0", True), + ("cat/pkg:0/0", "cat/pkg", True), + ("cat/pkg[foo]", "cat/pkg[-bar]", True), + ("cat/pkg[foo]", "cat/pkg[-foo]", False), + (">cat/pkg-3", ">cat/pkg-1", True), + (">cat/pkg-3", "<cat/pkg-3", False), + (">=cat/pkg-3", "<cat/pkg-3", False), + (">cat/pkg-2", "=cat/pkg-2*", True), + ("<cat/pkg-2_alpha1", "=cat/pkg-2*", True), + ("=cat/pkg-2", "=cat/pkg-2", True), + ("=cat/pkg-3", "=cat/pkg-2", False), + ("=cat/pkg-2", ">cat/pkg-2", False), + ("=cat/pkg-2", ">=cat/pkg-2", True), + ("~cat/pkg-2", "~cat/pkg-2", True), + ("~cat/pkg-2", "~cat/pkg-2.1", False), + ("=cat/pkg-2*", "=cat/pkg-2.3*", True), + (">cat/pkg-2.4", "=cat/pkg-2*", True), + ("<cat/pkg-2.4", "=cat/pkg-2*", True), + ("<cat/pkg-1", "=cat/pkg-2*", False), + ("~cat/pkg-2", ">cat/pkg-2-r1", True), + ("~cat/pkg-2", "<=cat/pkg-2", True), + ("=cat/pkg-2-r2*", "<=cat/pkg-2-r20", True), + ("=cat/pkg-2-r2*", "<cat/pkg-2-r20", True), + ("=cat/pkg-2-r2*", "<=cat/pkg-2-r2", True), + ("~cat/pkg-2", "<cat/pkg-2", False), + ("=cat/pkg-1-r10*", "~cat/pkg-1", True), + ("=cat/pkg-1-r1*", "<cat/pkg-1-r1", False), + ("=cat/pkg-1*", ">cat/pkg-2", False), + (">=cat/pkg-8.4", "=cat/pkg-8.3.4*", False), + ("cat/pkg::gentoo", "cat/pkg", True), + ("cat/pkg::gentoo", "cat/pkg::foo", False), + # known to cause an assplosion, thus redundant test. + ("=sys-devel/gcc-4.1.1-r3", "=sys-devel/gcc-3.3*", False), + ("=sys-libs/db-4*", "~sys-libs/db-4.3.29", True), + ), + ) def test_intersects(self, this, that, result): this_atom = self.kls(this) that_atom = self.kls(that) - assert result == this_atom.intersects(that_atom), f'{this} intersecting {that} should be {result}' - assert result == that_atom.intersects(this_atom), f'{that} intersecting {this} should be {result}' - + assert result == this_atom.intersects( + that_atom + ), f"{this} intersecting {that} should be {result}" + assert result == that_atom.intersects( + this_atom + ), f"{that} intersecting {this} should be {result}" def test_comparison(self): - assert_equal_bidirectional(self.kls('cat/pkg'), self.kls('cat/pkg')) - assert_not_equal_bidirectional(self.kls('cat/pkg'), self.kls('cat/pkgb')) - assert_not_equal_bidirectional(self.kls('cata/pkg'), self.kls('cat/pkg')) - assert_not_equal_bidirectional(self.kls('cat/pkg'), self.kls('!cat/pkg')) - assert_equal_bidirectional(self.kls('!cat/pkg'), self.kls('!cat/pkg')) - assert_not_equal_bidirectional(self.kls('=cat/pkg-0.1:0'), self.kls('=cat/pkg-0.1')) - assert_not_equal_bidirectional(self.kls('=cat/pkg-1[foon]'), self.kls('=cat/pkg-1')) - assert_equal_bidirectional(self.kls('=cat/pkg-0'), self.kls('=cat/pkg-0')) - assert_not_equal_bidirectional(self.kls('<cat/pkg-2'), self.kls('>cat/pkg-2')) - assert_not_equal_bidirectional(self.kls('=cat/pkg-2*'), self.kls('=cat/pkg-2')) - assert_not_equal_bidirectional(self.kls('=cat/pkg-2', True), self.kls('=cat/pkg-2')) + assert_equal_bidirectional(self.kls("cat/pkg"), self.kls("cat/pkg")) + assert_not_equal_bidirectional(self.kls("cat/pkg"), self.kls("cat/pkgb")) + assert_not_equal_bidirectional(self.kls("cata/pkg"), self.kls("cat/pkg")) + assert_not_equal_bidirectional(self.kls("cat/pkg"), self.kls("!cat/pkg")) + assert_equal_bidirectional(self.kls("!cat/pkg"), self.kls("!cat/pkg")) + assert_not_equal_bidirectional( + self.kls("=cat/pkg-0.1:0"), self.kls("=cat/pkg-0.1") + ) + assert_not_equal_bidirectional( + self.kls("=cat/pkg-1[foon]"), self.kls("=cat/pkg-1") + ) + assert_equal_bidirectional(self.kls("=cat/pkg-0"), self.kls("=cat/pkg-0")) + assert_not_equal_bidirectional(self.kls("<cat/pkg-2"), self.kls(">cat/pkg-2")) + assert_not_equal_bidirectional(self.kls("=cat/pkg-2*"), self.kls("=cat/pkg-2")) + assert_not_equal_bidirectional( + self.kls("=cat/pkg-2", True), self.kls("=cat/pkg-2") + ) # use... - assert_not_equal_bidirectional(self.kls('cat/pkg[foo]'), self.kls('cat/pkg')) - assert_not_equal_bidirectional(self.kls('cat/pkg[foo]'), self.kls('cat/pkg[-foo]')) - assert_equal_bidirectional(self.kls('cat/pkg[foo,-bar]'), self.kls('cat/pkg[-bar,foo]')) + assert_not_equal_bidirectional(self.kls("cat/pkg[foo]"), self.kls("cat/pkg")) + assert_not_equal_bidirectional( + self.kls("cat/pkg[foo]"), self.kls("cat/pkg[-foo]") + ) + assert_equal_bidirectional( + self.kls("cat/pkg[foo,-bar]"), self.kls("cat/pkg[-bar,foo]") + ) # repo_id - assert_equal_bidirectional(self.kls('cat/pkg::a'), self.kls('cat/pkg::a')) - assert_not_equal_bidirectional(self.kls('cat/pkg::a'), self.kls('cat/pkg::b')) - assert_not_equal_bidirectional(self.kls('cat/pkg::a'), self.kls('cat/pkg')) + assert_equal_bidirectional(self.kls("cat/pkg::a"), self.kls("cat/pkg::a")) + assert_not_equal_bidirectional(self.kls("cat/pkg::a"), self.kls("cat/pkg::b")) + assert_not_equal_bidirectional(self.kls("cat/pkg::a"), self.kls("cat/pkg")) # slots. - assert_not_equal_bidirectional(self.kls('cat/pkg:1'), self.kls('cat/pkg')) - assert_equal_bidirectional(self.kls('cat/pkg:2'), self.kls('cat/pkg:2')) - for lesser, greater in (('0.1', '1'), ('1', '1-r1'), ('1.1', '1.2')): - assert self.kls(f'=d/b-{lesser}') < self.kls(f'=d/b-{greater}'), \ - f"d/b-{lesser} < d/b-{greater}" - assert not (self.kls(f'=d/b-{lesser}') > self.kls(f'=d/b-{greater}')), \ - f"!: d/b-{lesser} < d/b-{greater}" - assert self.kls(f'=d/b-{greater}') > self.kls(f'=d/b-{lesser}'), \ - f"d/b-{greater} > d/b-{lesser}" - assert not (self.kls(f'=d/b-{greater}') < self.kls(f'=d/b-{lesser}')), \ - f"!: d/b-{greater} > d/b-{lesser}" - - assert self.kls("!!=d/b-1", eapi='2') > self.kls("!=d/b-1") + assert_not_equal_bidirectional(self.kls("cat/pkg:1"), self.kls("cat/pkg")) + assert_equal_bidirectional(self.kls("cat/pkg:2"), self.kls("cat/pkg:2")) + for lesser, greater in (("0.1", "1"), ("1", "1-r1"), ("1.1", "1.2")): + assert self.kls(f"=d/b-{lesser}") < self.kls( + f"=d/b-{greater}" + ), f"d/b-{lesser} < d/b-{greater}" + assert not ( + self.kls(f"=d/b-{lesser}") > self.kls(f"=d/b-{greater}") + ), f"!: d/b-{lesser} < d/b-{greater}" + assert self.kls(f"=d/b-{greater}") > self.kls( + f"=d/b-{lesser}" + ), f"d/b-{greater} > d/b-{lesser}" + assert not ( + self.kls(f"=d/b-{greater}") < self.kls(f"=d/b-{lesser}") + ), f"!: d/b-{greater} > d/b-{lesser}" + + assert self.kls("!!=d/b-1", eapi="2") > self.kls("!=d/b-1") assert self.kls("!=d/b-1") < self.kls("!!=d/b-1") assert self.kls("!=d/b-1") == self.kls("!=d/b-1") def test_compatibility(self): - self.assertNotMatch(self.kls('=dev-util/diffball-0.7'), - FakePkg('dev-util/diffball-0.7.0')) + self.assertNotMatch( + self.kls("=dev-util/diffball-0.7"), FakePkg("dev-util/diffball-0.7.0") + ) # see bug http://bugs.gentoo.org/152127 - self.assertNotMatch(self.kls('>=sys-apps/portage-2.1.0_pre3-r5'), - FakePkg('sys-apps/portage-2.1_pre3-r5')) + self.assertNotMatch( + self.kls(">=sys-apps/portage-2.1.0_pre3-r5"), + FakePkg("sys-apps/portage-2.1_pre3-r5"), + ) def test_combined(self): - p = FakePkg('dev-util/diffball-0.7', repo=FakeRepo(repo_id='gentoo')) - self.assertMatch(self.kls('=dev-util/diffball-0.7::gentoo'), p) - self.assertMatch(self.kls('dev-util/diffball::gentoo'), p) - self.assertNotMatch(self.kls('=dev-util/diffball-0.7:1::gentoo'), - FakePkg('dev-util/diffball-0.7', slot='2')) + p = FakePkg("dev-util/diffball-0.7", repo=FakeRepo(repo_id="gentoo")) + self.assertMatch(self.kls("=dev-util/diffball-0.7::gentoo"), p) + self.assertMatch(self.kls("dev-util/diffball::gentoo"), p) + self.assertNotMatch( + self.kls("=dev-util/diffball-0.7:1::gentoo"), + FakePkg("dev-util/diffball-0.7", slot="2"), + ) def test_unversioned(self): assert self.kls("dev-util/diffball").is_simple @@ -529,42 +629,50 @@ class TestAtom(TestRestriction): assert not self.kls("dev-util/diffball[x]").is_simple assert not self.kls("dev-util/diffball[x?]").is_simple - @pytest.mark.parametrize(("original", "wanted"), ( - ("<dev-util/diffball-2", "<dev-util/diffball-2"), - ("<dev-util/diffball-2[debug=,test=]", "<dev-util/diffball-2"), - ("=dev-util/diffball-2", "=dev-util/diffball-2"), - ("=dev-util/diffball-2[debug=,test=]", "=dev-util/diffball-2"), - ("=dev-util/diffball-2*", "=dev-util/diffball-2*"), - ("=dev-util/diffball-2*[debug=,test=]", "=dev-util/diffball-2*"), - ("dev-util/diffball:0", "dev-util/diffball:0"), - ("dev-util/diffball:0[debug=,test=]", "dev-util/diffball:0"), - ("dev-util/diffball:0/1.12", "dev-util/diffball:0/1.12"), - ("dev-util/diffball:0/1.12[debug=,test=]", "dev-util/diffball:0/1.12"), - ("!dev-util/diffball", "!dev-util/diffball"), - ("!dev-util/diffball[debug=,test=]", "!dev-util/diffball"), - ("!!dev-util/diffball", "!!dev-util/diffball"), - ("!!dev-util/diffball[debug=,test=]", "!!dev-util/diffball"), - )) + @pytest.mark.parametrize( + ("original", "wanted"), + ( + ("<dev-util/diffball-2", "<dev-util/diffball-2"), + ("<dev-util/diffball-2[debug=,test=]", "<dev-util/diffball-2"), + ("=dev-util/diffball-2", "=dev-util/diffball-2"), + ("=dev-util/diffball-2[debug=,test=]", "=dev-util/diffball-2"), + ("=dev-util/diffball-2*", "=dev-util/diffball-2*"), + ("=dev-util/diffball-2*[debug=,test=]", "=dev-util/diffball-2*"), + ("dev-util/diffball:0", "dev-util/diffball:0"), + ("dev-util/diffball:0[debug=,test=]", "dev-util/diffball:0"), + ("dev-util/diffball:0/1.12", "dev-util/diffball:0/1.12"), + ("dev-util/diffball:0/1.12[debug=,test=]", "dev-util/diffball:0/1.12"), + ("!dev-util/diffball", "!dev-util/diffball"), + ("!dev-util/diffball[debug=,test=]", "!dev-util/diffball"), + ("!!dev-util/diffball", "!!dev-util/diffball"), + ("!!dev-util/diffball[debug=,test=]", "!!dev-util/diffball"), + ), + ) def test_get_atom_without_use_deps(self, original, wanted): orig_atom = self.kls(original) assert str(orig_atom.get_atom_without_use_deps) == wanted - @pytest.mark.parametrize(('dep', 'iuse', 'use', 'wanted', 'eapi'), ( - ("x(-)", {'x'}, {'x'}, True, '5'), - ("x(-)", {'x'}, (), False, '5'), - ("x(+)", (), (), True, '5'), - ("x(-)", (), (), False, '5'), - ("x(-),y(-)", (), (), False, '5'), - ("x(-),y(-)", {'x', 'y'}, ("x", "y"), True, '5'), - ("x(+),y(-)", (), (), False, '5'), - ("x(+),y(-)", {"y"}, (), False, '5'), - ("x(+),y(-)", {'y'}, {"y"}, True, '5'), - # verify that it's not sensitive to iuse defaults - ("x(-)", {"+x"}, {"x"}, True, '5'), - ("x(+)", {"-x"}, {"x"}, True, '5'), - )) + @pytest.mark.parametrize( + ("dep", "iuse", "use", "wanted", "eapi"), + ( + ("x(-)", {"x"}, {"x"}, True, "5"), + ("x(-)", {"x"}, (), False, "5"), + ("x(+)", (), (), True, "5"), + ("x(-)", (), (), False, "5"), + ("x(-),y(-)", (), (), False, "5"), + ("x(-),y(-)", {"x", "y"}, ("x", "y"), True, "5"), + ("x(+),y(-)", (), (), False, "5"), + ("x(+),y(-)", {"y"}, (), False, "5"), + ("x(+),y(-)", {"y"}, {"y"}, True, "5"), + # verify that it's not sensitive to iuse defaults + ("x(-)", {"+x"}, {"x"}, True, "5"), + ("x(+)", {"-x"}, {"x"}, True, "5"), + ), + ) def test_use_dep_defaults(self, dep, iuse, use, wanted, eapi): - pkg = FakePkg("dev-util/diffball-1", eapi=eapi, iuse=frozenset(iuse), use=frozenset(use)) - a = self.kls(f'dev-util/diffball[{dep}]') - #import pdb;pdb.set_trace() + pkg = FakePkg( + "dev-util/diffball-1", eapi=eapi, iuse=frozenset(iuse), use=frozenset(use) + ) + a = self.kls(f"dev-util/diffball[{dep}]") + # import pdb;pdb.set_trace() assert a.match(pkg) == wanted |