Exemple #1
0
    def test_constructor(self):
        s = KeyedSet()
        assert set(s) == set()
        assert s._dict == {}

        s2 = KeyedSet({1, 2, 3}, key=str)
        assert s2._dict == {"1": 1, "2": 2, "3": 3}
Exemple #2
0
    def test_dict_feature(self):
        s = KeyedSet({1, 2, 3}, key=str)

        assert list(s.keys()) == ["1", "2", "3"]
        assert s["1"] == 1
        assert s[1] == 1
        assert s.get("4") is None
        assert list(s.items()) == [("1", 1), ("2", 2), ("3", 3)]
Exemple #3
0
    def test_discard(self):
        s = KeyedSet({1, 2, 3}, key=str)

        s.discard(4)
        assert len(s) == 3

        s.discard(2)
        assert set(s) == {1, 3}

        s.discard("1")
        assert set(s) == {3}
Exemple #4
0
    def test_repr(self):
        s = KeyedSet({1, 2, 3}, key=str)
        assert repr(s) == "KeyedSet({1, 2, 3})"

        s2 = KeyedSet[int, str]({1, 2, 3}, key=str)
        assert repr(s2) == "KeyedSet[int, str]({1, 2, 3})"
Exemple #5
0
 def test_equality(self):
     s = KeyedSet({1, 2, 3}, key=str)
     assert s == {1, 2, 3}
     assert s != KeyedSet({1, 2}, key=str)
     assert s == KeyedSet({1, 2, 3}, key=str)
     assert s != "hi"
Exemple #6
0
 def test_add(self):
     s = KeyedSet({1, 2, 3}, key=str)
     s.add(4)
     assert 4 in s
Exemple #7
0
 def test_len(self):
     assert len(KeyedSet({1, 2, 3}, key=str)) == 3
Exemple #8
0
 def test_iter(self):
     s = KeyedSet({1, 2, 3}, key=str)
     assert set(iter(s)) == {1, 2, 3}
Exemple #9
0
 def test_contains(self):
     s = KeyedSet({1, 2, 3}, key=str)
     assert 1 in s
     assert "1" in s
     assert 4 not in s
     assert "4" not in s