def test_clear_state_resets(self): a = Tracker(states) a.set_state('foo', sentinel_a) a.set_state('foo', sentinel_b) a.clear_state('foo') self.assertEqual(len(a.in_state('foo')), 0)
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_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_in_state_yield_objects_added(self): a = Tracker(states) a.set_state('foo', sentinel_a) a.set_state('bar', sentinel_b) self.assertEqual({sentinel_a}, set(a.in_state('foo')))
def test_state_set(self): a = Tracker(states) ast = a.about(sentinel_a) ast.foo = True self.assertTrue(a.in_state('foo', sentinel_a))
def test_none_is_not_in_state(self): a = Tracker(states) a.set_state('foo', sentinel_a) self.assertFalse(a.in_state('foo', None))
def test_in_state_check(self): a = Tracker(states) a.set_state('foo', sentinel_a) a.set_state('bar', sentinel_b) self.assertFalse(a.in_state('bar', sentinel_a)) self.assertTrue(a.in_state('foo', sentinel_a))