Increase coverage
This commit is contained in:
parent
73125b99b0
commit
d3eb68fa50
|
@ -1,12 +1,17 @@
|
||||||
import random
|
import random
|
||||||
import multiaddr
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
import multiaddr
|
||||||
|
|
||||||
from libp2p.peer.peerinfo import PeerInfo, info_from_p2p_addr, InvalidAddrError
|
from libp2p.peer.peerinfo import PeerInfo, info_from_p2p_addr, InvalidAddrError
|
||||||
from libp2p.peer.peerdata import PeerData
|
from libp2p.peer.peerdata import PeerData
|
||||||
from libp2p.peer.id import ID
|
from libp2p.peer.id import ID
|
||||||
|
|
||||||
|
|
||||||
ALPHABETS = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
|
ALPHABETS = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
|
||||||
|
|
||||||
|
|
||||||
def test_init_():
|
def test_init_():
|
||||||
peer_data = PeerData()
|
peer_data = PeerData()
|
||||||
random_addrs = [random.randint(0, 255) for r in range(4)]
|
random_addrs = [random.randint(0, 255) for r in range(4)]
|
||||||
|
@ -20,22 +25,27 @@ def test_init_():
|
||||||
assert peer_info.peer_id == peer_id
|
assert peer_info.peer_id == peer_id
|
||||||
assert peer_info.addrs == random_addrs
|
assert peer_info.addrs == random_addrs
|
||||||
|
|
||||||
|
|
||||||
def test_init_no_value():
|
def test_init_no_value():
|
||||||
with pytest.raises(Exception) as _:
|
with pytest.raises(Exception) as _:
|
||||||
# pylint: disable=no-value-for-parameter
|
# pylint: disable=no-value-for-parameter
|
||||||
PeerInfo()
|
PeerInfo()
|
||||||
|
|
||||||
def test_invalid_addr_1():
|
|
||||||
with pytest.raises(InvalidAddrError):
|
|
||||||
info_from_p2p_addr(None)
|
|
||||||
|
|
||||||
def test_invalid_addr_2(monkeypatch):
|
@pytest.mark.parametrize(
|
||||||
random_addr = random.randint(0, 255)
|
'addr',
|
||||||
monkeypatch.setattr("multiaddr.Multiaddr.split", lambda x: None)
|
(
|
||||||
|
None,
|
||||||
|
random.randint(0, 255),
|
||||||
|
multiaddr.Multiaddr('/'),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
def test_info_from_p2p_addr_invalid(addr):
|
||||||
with pytest.raises(InvalidAddrError):
|
with pytest.raises(InvalidAddrError):
|
||||||
info_from_p2p_addr(random_addr)
|
info_from_p2p_addr(addr)
|
||||||
|
|
||||||
def test_info_from_p2p_addr():
|
|
||||||
|
def test_info_from_p2p_addr_valid():
|
||||||
# pylint: disable=line-too-long
|
# pylint: disable=line-too-long
|
||||||
m_addr = multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/8000/p2p/3YgLAeMKSAPcGqZkAt8mREqhQXmJT8SN8VCMN4T6ih4GNX9wvK8mWJnWZ1qA2mLdCQ')
|
m_addr = multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/8000/p2p/3YgLAeMKSAPcGqZkAt8mREqhQXmJT8SN8VCMN4T6ih4GNX9wvK8mWJnWZ1qA2mLdCQ')
|
||||||
info = info_from_p2p_addr(m_addr)
|
info = info_from_p2p_addr(m_addr)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user