Beispiel #1
0
    def test_list_toggeling(self):
        toggle_filter = filters.ToggleFilter(self.list_db)
        assert_false(toggle_filter.toggle_item(3))
        assert_equal(toggle_filter._toggle_db, {1, 2, 4, 5})
        assert_true(toggle_filter.toggle_item(3))
        assert_equal(toggle_filter._toggle_db, {1, 2, 3, 4, 5})
        assert_false(toggle_filter.toggle_item(2))
        assert_false(toggle_filter.toggle_item(4))
        self.list_db.extend([6 ,7])
        assert_true(toggle_filter.toggle_item(6))

        assert_equal(toggle_filter.filter_items(), [1, 3 , 5, 6])

        self.list_db.remove(1)
        assert_equal(toggle_filter.filter_items(), [3, 5, 6])
Beispiel #2
0
    def test_dict_toggeling(self):
        toggle_filter = filters.ToggleFilter(self.dict_db)
        assert_false(toggle_filter.toggle_item("3"))
        assert_equal(toggle_filter._toggle_db, {'0', '1', '2', '4'})
        assert_true(toggle_filter.toggle_item("3"))
        assert_equal(toggle_filter._toggle_db, {'0', '1', '2', '3', '4'})
        assert_false(toggle_filter.toggle_item("2"))
        assert_false(toggle_filter.toggle_item("4"))
        self.dict_db.update({'5': 25, '6': 36})
        assert_true(toggle_filter.toggle_item("6"))

        assert_equal(toggle_filter.filter_items(), {'0': 0, '1': 1, '3': 9, '6': 36})

        del self.dict_db['1']
        assert_equal(toggle_filter.filter_items(), {'0': 0, '3': 9, '6': 36})
Beispiel #3
0
 def test_dont_show_after_init(self):
     toggle_filter = filters.ToggleFilter(self.list_db, show_by_default = False)
     assert_equal(toggle_filter._toggle_db, set())
     assert_equal(toggle_filter.filter_items(), [])
Beispiel #4
0
 def test_toggle_multiple_items(self):
     toggle_filter = filters.ToggleFilter(self.list_db)
     assert_false(toggle_filter.toggle_items(1, 3, 5))
     assert_equal(toggle_filter._toggle_db, {2, 4})
     assert_true(toggle_filter.toggle_items(1, 5))
     assert_equal(toggle_filter._toggle_db, {1, 2, 4, 5})
Beispiel #5
0
 def test_list_toggling_negative(self):
     toggle_filter = filters.ToggleFilter(self.list_db)
     assert_raises(KeyError, toggle_filter.toggle_item, 10)
Beispiel #6
0
 def test_dict_toggeling_negative(self):
     toggle_filter = filters.ToggleFilter(self.dict_db)
     assert_raises(KeyError, toggle_filter.toggle_item, "100")
Beispiel #7
0
 def test_init_with_non_iterable(self):
     toggle_filter = filters.ToggleFilter(15)
Beispiel #8
0
 def test_init_with_tuple(self):
     toggle_filter = filters.ToggleFilter(self.tuple_db)
     assert_equal(toggle_filter._toggle_db, set(self.tuple_db))
     assert_equal(toggle_filter.filter_items(), self.tuple_db)
Beispiel #9
0
 def test_init_with_dict(self):
     toggle_filter = filters.ToggleFilter(self.dict_db)
     assert_equal(toggle_filter._toggle_db, set(self.dict_db.keys()))
     assert_equal(toggle_filter.filter_items(), self.dict_db)