From d3eb68fa50aa5894d282e68859b3e5174f942c96 Mon Sep 17 00:00:00 2001 From: mhchia Date: Mon, 8 Jul 2019 17:50:32 +0800 Subject: [PATCH] Increase coverage --- tests/peer/test_peerinfo.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/tests/peer/test_peerinfo.py b/tests/peer/test_peerinfo.py index ea86158..1ad1dc0 100644 --- a/tests/peer/test_peerinfo.py +++ b/tests/peer/test_peerinfo.py @@ -1,12 +1,17 @@ import random -import multiaddr + import pytest + +import multiaddr + from libp2p.peer.peerinfo import PeerInfo, info_from_p2p_addr, InvalidAddrError from libp2p.peer.peerdata import PeerData from libp2p.peer.id import ID + ALPHABETS = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' + def test_init_(): peer_data = PeerData() 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.addrs == random_addrs + def test_init_no_value(): with pytest.raises(Exception) as _: # pylint: disable=no-value-for-parameter PeerInfo() -def test_invalid_addr_1(): - with pytest.raises(InvalidAddrError): - info_from_p2p_addr(None) -def test_invalid_addr_2(monkeypatch): - random_addr = random.randint(0, 255) - monkeypatch.setattr("multiaddr.Multiaddr.split", lambda x: None) +@pytest.mark.parametrize( + 'addr', + ( + None, + random.randint(0, 255), + multiaddr.Multiaddr('/'), + ) +) +def test_info_from_p2p_addr_invalid(addr): 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 m_addr = multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/8000/p2p/3YgLAeMKSAPcGqZkAt8mREqhQXmJT8SN8VCMN4T6ih4GNX9wvK8mWJnWZ1qA2mLdCQ') info = info_from_p2p_addr(m_addr)