Ejemplo n.º 1
0
def test_iter():
    wl = WantList()
    cids = [
        py_cid.make_cid('QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4'),
        py_cid.make_cid('QmaozNR7DZddK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdTPdT')
    ]
    wl.add(cids[0])
    wl.add(cids[1])
    assert len(wl) == 2
    for i in wl:
        assert i in [str(cid) for cid in cids]
Ejemplo n.º 2
0
def test_force_remove():
    wl = WantList()
    cid = py_cid.make_cid('QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4')
    wl.add(cid)
    wl.add(cid)
    wl.force_remove(cid)
    assert not (str(cid) in wl.entries)
Ejemplo n.º 3
0
def test_len():
    wl = WantList()
    cid = py_cid.make_cid('QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4')
    assert 0 == len(wl)
    wl.add(cid)
    wl.add(cid)
    assert 1 == len(wl)
    wl.add(py_cid.make_cid('QmaozNR7DZddK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdTPdT'))
    assert 2 == len(wl)
Ejemplo n.º 4
0
def test_add():
    wl = WantList()
    cid = py_cid.make_cid('QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4')
    wl.add(cid)
    assert str(cid) in wl.entries
    assert 1 == wl.entries[str(cid)].priority
    wl.add(cid, 3)
    assert str(cid) in wl.entries
    assert 3 == wl.entries[str(cid)].priority
    assert 2 == wl.entries[str(cid)]._ref_count
Ejemplo n.º 5
0
def test_contains():
    wl = WantList()
    cids = [
        py_cid.make_cid('QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4'),
        py_cid.make_cid('QmaozNR7DZddK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdTPdT')
    ]
    wl.add(cids[0])
    assert cids[0] in wl
    assert not (cids[1] in wl)
    wl.add(cids[1])
    assert cids[1] in wl
Ejemplo n.º 6
0
def test_str():
    wl = WantList()
    wl.add(py_cid.make_cid('QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4'))
    wl.add(py_cid.make_cid('QmaozNR7DZddK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdTPdT'))
    expected = 'WantList, number_of_entries=2'
    assert expected == str(wl)
Ejemplo n.º 7
0
def test_sorted_entries():
    wl = WantList()
    with pytest.raises(NotImplementedError):
        wl.sorted_entries()
Ejemplo n.º 8
0
def test_remove():
    wl = WantList()
    cid = py_cid.make_cid('QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4')
    wl.remove(cid)
    assert not (str(cid) in wl.entries)
    wl.add(cid)
    wl.remove(cid)
    assert not (str(cid) in wl.entries)
    wl.add(cid)
    wl.add(cid)
    wl.add(cid)
    wl.remove(cid)
    assert str(cid) in wl.entries
    assert 2 == wl.entries[str(cid)]._ref_count
    wl.remove(cid)
    assert str(cid) in wl.entries
    assert 1 == wl.entries[str(cid)]._ref_count
    wl.remove(cid)
    assert not (str(cid) in wl.entries)