Skip to content

Commit

Permalink
flow.Filter gets representation, equality and unequality operators.
Browse files Browse the repository at this point in the history
  • Loading branch information
ynikitenko committed Jul 27, 2023
1 parent 79f3f93 commit 13105b0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lena/flow/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,14 @@ def run(self, flow):
# for val in flow:
# if self._selector(val):
# yield event

def __eq__(self, other):
if isinstance(other, Filter):
return self._selector == other._selector
return NotImplemented

def __ne__(self, other):
return not (self == other)

def __repr__(self):
return "Filter({})".format(repr(self._selector))
8 changes: 8 additions & 0 deletions tests/flow/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,11 @@ def test_filter():
data3 = [histogram([1, 2])]
f3 = Filter(histogram)
assert list(f3.run(data3)) == data3

# representation works
assert repr(f3) == "Filter(Selector(histogram))"

# equality works
f4 = Filter(fun)
assert f4 == f2
assert f3 != f4

0 comments on commit 13105b0

Please sign in to comment.