Skip to content

Commit 7eccdfa

Browse files
committed
atom: implement __eq__() for Blocker and SlotOperator
Allow equivalency test for string arguments, falling back to identity test for enum args.
1 parent 3147fcc commit 7eccdfa

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/pkgcraft/atom/base.pyx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ class Blocker(IntEnum):
213213
C.pkgcraft_str_free(c_str)
214214
return s
215215

216+
def __eq__(self, object other):
217+
if isinstance(other, str):
218+
return str(self) == other
219+
return self is other
220+
216221

217222
class SlotOperator(IntEnum):
218223
Equal = C.SLOT_OPERATOR_EQUAL
@@ -231,6 +236,11 @@ class SlotOperator(IntEnum):
231236
C.pkgcraft_str_free(c_str)
232237
return s
233238

239+
def __eq__(self, object other):
240+
if isinstance(other, str):
241+
return str(self) == other
242+
return self is other
243+
234244

235245
@cython.final
236246
cdef class Atom(Cpv):

tests/atom/test_base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,11 @@ def test_init(self):
8484
assert a.category == "cat"
8585
assert a.package == "pkg"
8686
assert a.blocker is Blocker.Strong
87+
assert a.blocker == "!!"
8788
assert a.slot == "0"
8889
assert a.subslot == "2"
8990
assert a.slot_op is SlotOperator.Equal
91+
assert a.slot_op == "="
9092
assert a.use == ("a", "b", "c")
9193
assert a.repo == "repo"
9294
assert a.version == VersionWithOp("=1-r2")

0 commit comments

Comments
 (0)