Exemplo n.º 1
0
def test_init():
    c = FrozenCounter({1: 2})
    assert isinstance(c, FrozenCounter)
Exemplo n.º 2
0
def test_inplace_operation():
    c = FrozenCounter({1: 2})
    d = c
    c += FrozenCounter({2: 3})
    assert c == FrozenCounter({1: 2, 2: 3})
    assert d == FrozenCounter({1: 2})
Exemplo n.º 3
0
def test_setitem():
    c = FrozenCounter({1: 2})
    with pytest.raises(FrozenInstanceError):
        c[2] = 3
    with pytest.raises(FrozenInstanceError):
        c[1] = 3
Exemplo n.º 4
0
def test_hash():
    c = FrozenCounter({1: 2})
    d = FrozenCounter({1: 2})
    assert hash(c) == hash(d)
    assert hash(frozenset((1, 2))) != hash(c)
Exemplo n.º 5
0
def test_copy():
    c = FrozenCounter({1: 2})
    d = c.copy()
    assert c == d
    assert c is not d
Exemplo n.º 6
0
def test_missing_key():
    c = FrozenCounter({1: 2})
    c[1]
    c[0]
Exemplo n.º 7
0
def test_setter():
    c = FrozenCounter({1: 2})
    with pytest.raises(FrozenInstanceError):
        c[1] += 2
Exemplo n.º 8
0
 def __init__(self, *args):
     return FrozenCounter.__init__(self, (Particle(p) for p in args))