예제 #1
0
    def test_in(self):
        from _collections import identity_dict
        d = identity_dict()
        d[None] = 1

        assert None in d
        assert [] not in d
예제 #2
0
    def test_in(self):
        from _collections import identity_dict
        d = identity_dict()
        d[None] = 1

        assert None in d
        assert [] not in d
예제 #3
0
    def test_keys(self):
        from _collections import identity_dict
        d = identity_dict()
        d[[]] = 1
        d[[]] = 2
        d[[]] = 3

        assert d.keys() == [[], [], []]
        assert sorted(d.values()) == [1, 2, 3]
예제 #4
0
    def test_get(self):
        from _collections import identity_dict
        d = identity_dict()
        d[None] = 1

        assert d.get(None, 42) == 1
        assert d.get(None) == 1
        assert d.get(1) is None
        assert d.get(1, 42) == 42
예제 #5
0
    def test_keys(self):
        from _collections import identity_dict
        d = identity_dict()
        d[[]] = 1
        d[[]] = 2
        d[[]] = 3

        assert d.keys() == [[], [], []]
        assert sorted(d.values()) == [1, 2, 3]
예제 #6
0
    def test_get(self):
        from _collections import identity_dict
        d = identity_dict()
        d[None] = 1

        assert d.get(None, 42) == 1
        assert d.get(None) == 1
        assert d.get(1) is None
        assert d.get(1, 42) == 42
예제 #7
0
    def test_numbers(self):
        from _collections import identity_dict
        d = identity_dict()
        d[0] = 1
        d[0.0] = 2
        d[long(0)] = 3

        assert d
        assert len(d) == 3
        d.clear()
        assert not d
예제 #8
0
    def test_numbers(self):
        from _collections import identity_dict
        d = identity_dict()
        d[0] = 1
        d[0.0] = 2
        d[long(0)] = 3

        assert d
        assert len(d) == 3
        d.clear()
        assert not d
예제 #9
0
    def test_unhashable(self):
        from _collections import identity_dict

        d = identity_dict()
        d[[]] = 1
        d[[]] = 2
        a = []
        d[a] = 3
        assert len(d) == 3
        d[a] = 4
        assert len(d) == 3
        assert d[a] == 4

        raises(KeyError, d.__getitem__, [])
예제 #10
0
    def test_unhashable(self):
        from _collections import identity_dict

        d = identity_dict()
        d[[]] = 1
        d[[]] = 2
        a = []
        d[a] = 3
        assert len(d) == 3
        d[a] = 4
        assert len(d) == 3
        assert d[a] == 4

        raises(KeyError, d.__getitem__, [])