def test_has_refs():
    cid = py_cid.make_cid('QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4')
    e = WantListEntry(cid)
    assert e.has_refs()
    e.dec_ref_count()
    assert not (e.has_refs())
    e.dec_ref_count()
    assert not (e.has_refs())
def test_init():
    cid = py_cid.make_cid('QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4')
    e = WantListEntry(cid)
    assert e.cid == cid
    assert e._ref_count == 1
    assert e.priority == 1
    e = WantListEntry(cid, 5)
    assert e.cid == cid
    assert e._ref_count == 1
    assert e.priority == 5
    with pytest.raises(ValueError):
        WantListEntry('df')
def test_init_cid_priority():
    cid = py_cid.make_cid('QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4')
    m = MessageEntry(cid, False)
    assert m.entry == WantListEntry(cid)
    assert m.cid == cid
    assert m.cancel == False
    assert m.priority == 1
    m = MessageEntry(cid, True, 5)
    assert m.entry == WantListEntry(cid, 5)
    assert m.cid == cid
    assert m.cancel == True
    assert m.priority == 5
    with pytest.raises(ValueError):
        MessageEntry('df', True)
Beispiel #4
0
 def __init__(self,
              cid: Union[py_cid.CIDv0, py_cid.CIDv1],
              cancel: bool,
              priority: int = 1):
     if not py_cid.is_cid(str(cid)):
         raise ValueError(f"{cid} is not a valid cid")
     self.entry = WantListEntry(cid, priority)
     self.cancel = bool(cancel)
def test_dec():
    cid = py_cid.make_cid('QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4')
    e = WantListEntry(cid)
    assert e._ref_count == 1
    e.dec_ref_count()
    assert e._ref_count == 0
    e.dec_ref_count()
    assert e._ref_count == 0
def test_eq():
    cid = py_cid.make_cid('QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4')
    e = WantListEntry(cid, 5)
    e2 = WantListEntry(cid, 5)
    assert e.equals(e2)
    assert e == e2
    e2.inc_ref_count()
    assert not (e.equals(e2))  # different _ref_count
    assert not (e == e2)  # different _ref_count
    e2 = WantListEntry(cid, 3)
    assert not (e.equals(e2))  # different priority
    assert not (e == e2)  # different priority
    cid2 = py_cid.make_cid('QmaozNR7DZHQK1ZcU9p7QdrshMvXqW71ZcU9p7QdrshMpa')
    e2 = WantListEntry(cid2, 5)
    assert not (e.equals(e2))  # different cid
    assert not (e == e2)  # different cid
def test_str():
    cid = py_cid.make_cid('QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4')
    e = WantListEntry(cid, 5)
    expected = f'WantListEntry (cid={str(cid)}, priority=5) refs=1'
    assert expected, str(e)