Skip to content

Commit 522579a

Browse files
committed
tests: add ebuild pkg Keyword tests
1 parent a965cab commit 522579a

2 files changed

Lines changed: 79 additions & 0 deletions

File tree

tests/pkg/ebuild/__init__.py

Whitespace-only changes.

tests/pkg/ebuild/test_keyword.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import re
2+
3+
import pytest
4+
5+
from pkgcraft.error import PkgcraftError
6+
from pkgcraft.pkg import *
7+
8+
9+
class TestKeyword:
10+
def test_creation(self):
11+
# valid
12+
for s, arch, status in (
13+
("arch", "arch", KeywordStatus.Stable),
14+
("-arch", "arch", KeywordStatus.Disabled),
15+
("~arch", "arch", KeywordStatus.Unstable),
16+
("-*", "*", KeywordStatus.Disabled),
17+
("_", "_", KeywordStatus.Stable),
18+
("-_", "_", KeywordStatus.Disabled),
19+
("~_", "_", KeywordStatus.Unstable),
20+
):
21+
kw = Keyword(s)
22+
assert kw.arch == arch
23+
assert kw.status == status
24+
assert str(kw) == s
25+
assert s in repr(kw)
26+
27+
# invalid
28+
for s in ("", "-", "-@", "--arch", "-~arch", "~-arch"):
29+
with pytest.raises(PkgcraftError, match=f"invalid keyword: {re.escape(s)}"):
30+
Keyword(s)
31+
32+
def test_cmp(self):
33+
for s1, s2 in (
34+
("-arch", "~arch"),
35+
("~arch", "arch"),
36+
("arch1-plat1", "arch2-plat2"),
37+
("arch2-plat1", "arch1-plat2"),
38+
("zarch", "arch-linux"),
39+
):
40+
kw1 = Keyword(s1)
41+
kw2 = Keyword(s2)
42+
obj = object()
43+
44+
assert kw1 < kw2
45+
with pytest.raises(TypeError):
46+
assert kw1 < obj
47+
48+
assert kw1 <= kw2
49+
assert kw2 <= kw2
50+
with pytest.raises(TypeError):
51+
assert kw1 <= obj
52+
53+
assert kw1 == kw1
54+
assert not kw1 == obj
55+
56+
assert kw1 != kw2
57+
assert kw1 != obj
58+
59+
assert kw2 >= kw1
60+
assert kw2 >= kw2
61+
with pytest.raises(TypeError):
62+
assert kw2 >= obj
63+
64+
assert kw2 > kw1
65+
with pytest.raises(TypeError):
66+
assert kw2 > obj
67+
68+
def test_eq_and_hash(self):
69+
# not equal
70+
kw1 = Keyword("~arch")
71+
kw2 = Keyword("arch")
72+
assert kw1 != kw2
73+
assert len({kw1, kw2}) == 2
74+
75+
# equal
76+
kw1 = Keyword("-arch")
77+
kw2 = Keyword("-arch")
78+
assert kw1 == kw2
79+
assert len({kw1, kw2}) == 1

0 commit comments

Comments
 (0)