|
5 | 5 |
|
6 | 6 | import pytest |
7 | 7 |
|
8 | | -from pkgcraft.atom import Atom, Blocker, Cpv, SlotOperator, VersionWithOp |
| 8 | +from pkgcraft.atom import Atom, Blocker, Cpv, SlotOperator, Version, VersionWithOp |
9 | 9 | from pkgcraft.eapi import EAPIS, Eapi |
10 | 10 | from pkgcraft.error import InvalidAtom, InvalidCpv |
11 | 11 | from pkgcraft.restrict import Restrict |
12 | 12 |
|
13 | 13 | from ..misc import OperatorIterMap |
14 | 14 |
|
15 | 15 |
|
| 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 | + |
16 | 49 | class TestBlocker: |
17 | 50 | def test_from_str(self): |
18 | 51 | for s in ("", "!!!", "a"): |
|
0 commit comments