File: test_identitydict.py

package info (click to toggle)
pypy3 7.3.19%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 212,236 kB
  • sloc: python: 2,098,316; ansic: 540,565; sh: 21,462; asm: 14,419; cpp: 4,451; makefile: 4,209; objc: 761; xml: 530; exp: 499; javascript: 314; pascal: 244; lisp: 45; csh: 12; awk: 4
file content (64 lines) | stat: -rw-r--r-- 1,473 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class AppTestIdentityDict:
    spaceconfig = dict(usemodules=['__pypy__'])

    def test_numbers(self):
        from __pypy__ import identity_dict
        d = identity_dict()
        d[0] = 1
        d[0.0] = 2

        assert d
        assert len(d) == 2
        del d[0]
        d.clear()
        assert not d

    def test_get(self):
        from __pypy__ 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

    def test_unhashable(self):
        from __pypy__ 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__, [])

    def test_keys(self):
        from __pypy__ import identity_dict
        d = identity_dict()
        d[[]] = 1
        d[[]] = 2
        d[[]] = 3

        assert d.keys() == [[], [], []]
        assert sorted(d.values()) == [1, 2, 3]

    def test_in(self):
        from __pypy__ import identity_dict
        d = identity_dict()
        d[None] = 1

        assert None in d
        assert [] not in d

    def test_iterate(self):
        from __pypy__ import identity_dict
        d = identity_dict()
        d[None] = 1
        raises(TypeError, iter, d)
        raises(TypeError, list, d)