예제 #1
0
def test_simple_conflator_reset_all():
    c = conflateddict.ConflatedDict()
    for i in range(5):
        c[i] = i
    assert c[1] == 1
    c.clear()
    assert not c.data()
예제 #2
0
def test_simple_conflator_delitem():
    c = conflateddict.ConflatedDict()
    for i in range(5):
        c[i] = i

    del c[1]
    assert sorted(c.keys()) == [0, 2, 3, 4]
예제 #3
0
def test_simple_conflator_str():
    c = conflateddict.ConflatedDict()
    assert str(c) == '<ConflatedDict dirty:0 entries:0>'
    for i in range(5):
        c[1] = i
    assert str(c) == '<ConflatedDict dirty:1 entries:1>'
    c.reset()
    assert str(c) == '<ConflatedDict dirty:0 entries:1>'
예제 #4
0
def test_simple_conflator_dirty_check():
    c = conflateddict.ConflatedDict()
    for i in range(5):
        c[i] = i
    for i in range(5):
        assert c.dirty(i)
    c.reset()
    for i in range(5):
        assert not c.dirty(i)
예제 #5
0
def test_lambda_conflator_default_args():
    lc = conflateddict.LambdaConflator()
    dc = conflateddict.ConflatedDict()

    for i in range(10):
        key = i % 3
        lc[key] = i
        dc[key] = i
        assert lc[key] == dc[key]
예제 #6
0
def test_simple_conflator_reset():
    c = conflateddict.ConflatedDict()
    c[1] = 1
    c[2] = 2
    assert c[1] == 1
    c.reset()
    c[1] = 2
    assert c[1] == 2
    with pytest.raises(KeyError):
        c[2]
예제 #7
0
def test_simple_conflator_len():
    c = conflateddict.ConflatedDict()
    for i in range(5):
        c[1] = i
        assert len(c) == 1
    c[2] = 1
    assert len(c) == 2
    c.reset()
    assert len(c) == 0
    c[1] = 4
    assert len(c) == 1
예제 #8
0
def test_simple_conflator_iter():
    c = conflateddict.ConflatedDict()
    for i in range(5):
        c[i] = i
    for i, cc in enumerate(c):
        assert cc == i
예제 #9
0
def test_simple_conflator_data():
    c = conflateddict.ConflatedDict()
    for i in range(5):
        c[i] = i
    data = c.data()
    assert sorted(data.items()) == [(i, i) for i in range(5)]
예제 #10
0
def test_simple_conflator_items():
    c = conflateddict.ConflatedDict()
    for i in range(5):
        c[i] = i
    assert sorted(c.items()) == [(i, i) for i in range(5)]
예제 #11
0
def test_simple_conflator_value():
    c = conflateddict.ConflatedDict()
    c[1] = 1
    c[2] = 2
    c[1] = 2
    assert c[1] == 2
예제 #12
0
def test_simple_conflator_keys():
    c = conflateddict.ConflatedDict()
    for i in range(5):
        c[i] = i
    assert sorted(c.keys()) == list(range(5))
예제 #13
0
def test_simple_conflator_delitem_keyerror():
    c = conflateddict.ConflatedDict()
    for i in range(5):
        c[i] = i
    with pytest.raises(KeyError):
        del c['hello']