Skip to content

Commit dcfcd6d

Browse files
committed
tests: merge Cpv tests with base module
Matching the layout of the python modules.
1 parent 390020e commit dcfcd6d

2 files changed

Lines changed: 34 additions & 41 deletions

File tree

tests/atom/test_base.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,47 @@
55

66
import pytest
77

8-
from pkgcraft.atom import Atom, Blocker, Cpv, SlotOperator, VersionWithOp
8+
from pkgcraft.atom import Atom, Blocker, Cpv, SlotOperator, Version, VersionWithOp
99
from pkgcraft.eapi import EAPIS, Eapi
1010
from pkgcraft.error import InvalidAtom, InvalidCpv
1111
from pkgcraft.restrict import Restrict
1212

1313
from ..misc import OperatorIterMap
1414

1515

16+
class TestCpv:
17+
def test_init(self):
18+
a = Cpv("cat/pkg-1-r2")
19+
assert a.category == "cat"
20+
assert a.package == "pkg"
21+
assert a.version == Version("1-r2")
22+
assert a.revision == "2"
23+
assert a.cpn == "cat/pkg"
24+
assert str(a) == "cat/pkg-1-r2"
25+
assert repr(a).startswith("<Cpv 'cat/pkg-1-r2' at 0x")
26+
27+
def test_matches(self):
28+
a = Cpv("cat/pkg-1")
29+
r = Restrict(a)
30+
assert a.matches(r)
31+
assert not a.matches(~r)
32+
33+
def test_invalid(self):
34+
for s in ("invalid", "cat-1", "cat/pkg", "=cat/pkg-1"):
35+
with pytest.raises(InvalidCpv, match=f"invalid cpv: {s}"):
36+
Cpv(s)
37+
38+
def test_invalid_arg_type(self):
39+
for obj in (object(), None):
40+
with pytest.raises(TypeError):
41+
Cpv(obj)
42+
43+
def test_pickle(self):
44+
a = Cpv("cat/pkg-1-r2")
45+
b = pickle.loads(pickle.dumps(a))
46+
assert a == b
47+
48+
1649
class TestBlocker:
1750
def test_from_str(self):
1851
for s in ("", "!!!", "a"):

tests/atom/test_cpv.py

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)