コード例 #1
0
 def can_copy():
     fd1 = FrozenDict({1: 2, 3: 4})
     fd2 = fd1.copy()
     assert isinstance(fd2, FrozenDict)
     assert fd2 == fd1
     assert hash(fd2) == hash(fd1)
     assert fd2 is not fd1
     fd3 = copy(fd1)
     assert isinstance(fd3, FrozenDict)
     assert fd3 == fd1
     assert hash(fd3) == hash(fd1)
     assert fd3 is not fd1
コード例 #2
0
 def can_read():
     fd = FrozenDict({1: 2, 3: 4})
     assert fd == {1: 2, 3: 4}
     assert list(i for i in fd) == [1, 3]
     assert fd.copy() == fd
     assert 3 in fd
     assert 2 not in fd
     assert fd[1] == 2
     with raises(KeyError):
         fd[2]
     assert len(fd) == 2
     assert fd.get(1) == 2
     assert fd.get(2, 5) == 5
     assert list(fd.items()) == [(1, 2), (3, 4)]
     assert list(fd.keys()) == [1, 3]
     assert list(fd.values()) == [2, 4]