def test_filter_removes_falsy_value(self): a = Tracker(states) a.set_state('foo', sentinel_a, True) a.set_state('foo', sentinel_b, False) a.set_state('foo', sentinel_c) a.filter_state('foo') self.assertEqual({sentinel_a}, set(a.in_state('foo')))
def test_filter_custom_key(self): a = Tracker(states) a.set_state('foo', sentinel_a, 2) a.set_state('foo', sentinel_b, 3) a.set_state('foo', sentinel_c, 4) a.filter_state('foo', lambda t, v: v > 2) self.assertEqual({sentinel_b, sentinel_c}, set(a.in_state('foo')))
def test_filter_yields_removed(self): a = Tracker(states) a.set_state('foo', sentinel_a) a.set_state('foo', sentinel_b) a.set_state('foo', sentinel_c, True) removed = list(a.filter_state('foo')) self.assertEqual({sentinel_a, sentinel_b}, set(removed))