Beispiel #1
0
    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')))
Beispiel #2
0
    def test_get_state_enumerates_state(self):
        a = Tracker(states)
        a.set_state('foo', sentinel_a)
        a.set_state('foo', sentinel_b)

        l = list(a.get_state('foo'))
        self.assertEqual(
            {(sentinel_a, None), (sentinel_b, None)},
            set(l)
        )
Beispiel #3
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')))
Beispiel #4
0
 def test_clear_removes_from_all(self):
     a = Tracker(states)
     a.set_state('foo', sentinel_a)
     a.set_state('bar', sentinel_b)
     a.set_state('baz', sentinel_b)
     a.clear_state('foo', sentinel_a)
     a.clear_state('baz', sentinel_b)
     self.assertEqual({sentinel_b}, set(a.all))
Beispiel #5
0
    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)
Beispiel #6
0
 def test_state_check(self):
     a = Tracker(states)
     a.set_state('foo', sentinel_a, 'F')
     a.set_state('bar', sentinel_b)
     ast = a.about(sentinel_a)
     bst = a.about(sentinel_b)
     self.assertTrue(ast.foo)
     self.assertFalse(bst.foo)
Beispiel #7
0
    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))
Beispiel #8
0
 def test_get_invalid(self):
     a = Tracker(states)
     with self.assertRaises(UnknownState):
         a.get_state('flurb', sentinel_a)
Beispiel #9
0
 def test_state_set(self):
     a = Tracker(states)
     ast = a.about(sentinel_a)
     ast.foo = True
     self.assertTrue(a.in_state('foo', sentinel_a))
Beispiel #10
0
 def test_none_is_not_in_state(self):
     a = Tracker(states)
     a.set_state('foo', sentinel_a)
     self.assertFalse(a.in_state('foo', None))
Beispiel #11
0
 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')))
Beispiel #12
0
 def test_state_updates(self):
     a = Tracker(states)
     ast = a.about(sentinel_a)
     self.assertFalse(ast.bar)
     a.set_state('bar', sentinel_a)
     self.assertTrue(ast.bar)
Beispiel #13
0
 def test_pop_removes_from_all(self):
     a = Tracker(states)
     a.set_state('foo', sentinel_a)
     a.set_state('foo', sentinel_b)
     a.pop_state('foo', sentinel_a)
     self.assertEqual({sentinel_b}, set(a.all))
Beispiel #14
0
 def test_set_pop_value(self):
     data = object()
     a = Tracker(states)
     a.set_state('foo', sentinel_a, data)
     v = a.pop_state('foo', sentinel_a)
     self.assertIs(data, v)
Beispiel #15
0
 def test_set_states_adds_to_all(self):
     a = Tracker(states)
     a.set_state('foo', sentinel_a)
     a.set_state('bar', sentinel_b)
     a.set_state('baz', sentinel_b)
     self.assertEqual({sentinel_a, sentinel_b}, set(a.all))
Beispiel #16
0
 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))
Beispiel #17
0
 def test_pop_raises(self):
     a = Tracker(states)
     with self.assertRaises(KeyError):
         a.pop_state('foo', sentinel_a)