run black w/ extended line length

This commit is contained in:
Alex Stokes
2019-08-03 11:25:25 -07:00
committed by Kevin Mai-Husan Chia
parent 905dfa9a8d
commit 7477b29508
33 changed files with 71 additions and 229 deletions

View File

@ -114,9 +114,7 @@ async def test_multiple_streams():
response_a = (await stream_a.read()).decode()
response_b = (await stream_b.read()).decode()
assert response_a == ("ack_b:" + a_message) and response_b == (
"ack_a:" + b_message
)
assert response_a == ("ack_b:" + a_message) and response_b == ("ack_a:" + b_message)
# Success, terminate pending tasks.
await cleanup()

View File

@ -15,11 +15,7 @@ import pytest
from libp2p import initialize_default_swarm, new_node
from libp2p.host.basic_host import BasicHost
from libp2p.network.notifee_interface import INotifee
from tests.utils import (
cleanup,
echo_stream_handler,
perform_two_host_set_up_custom_handler,
)
from tests.utils import cleanup, echo_stream_handler, perform_two_host_set_up_custom_handler
class MyNotifee(INotifee):
@ -130,10 +126,7 @@ async def test_one_notifier_on_two_nodes():
# Ensure the connected and opened_stream events were hit in Notifee obj
# and that the stream passed into opened_stream matches the stream created on
# node_b
assert events_b == [
["connectedb", stream.mplex_conn],
["opened_streamb", stream],
]
assert events_b == [["connectedb", stream.mplex_conn], ["opened_streamb", stream]]
while True:
read_string = (await stream.read()).decode()

View File

@ -37,8 +37,7 @@ def test_init_no_value():
pytest.param(random.randint(0, 255), id="random integer"),
pytest.param(multiaddr.Multiaddr("/"), id="empty multiaddr"),
pytest.param(
multiaddr.Multiaddr("/ip4/127.0.0.1"),
id="multiaddr without peer_id(p2p protocol)",
multiaddr.Multiaddr("/ip4/127.0.0.1"), id="multiaddr without peer_id(p2p protocol)"
),
),
)

View File

@ -48,9 +48,7 @@ async def perform_simple_test(
@pytest.mark.asyncio
async def test_single_protocol_succeeds():
expected_selected_protocol = "/echo/1.0.0"
await perform_simple_test(
expected_selected_protocol, ["/echo/1.0.0"], ["/echo/1.0.0"]
)
await perform_simple_test(expected_selected_protocol, ["/echo/1.0.0"], ["/echo/1.0.0"])
@pytest.mark.asyncio

View File

@ -16,9 +16,7 @@ def num_hosts():
@pytest.fixture
async def hosts(num_hosts):
_hosts = HostFactory.create_batch(num_hosts)
await asyncio.gather(
*[_host.get_network().listen(LISTEN_MADDR) for _host in _hosts]
)
await asyncio.gather(*[_host.get_network().listen(LISTEN_MADDR) for _host in _hosts])
yield _hosts
# Clean up
listeners = []

View File

@ -102,10 +102,7 @@ FLOODSUB_PROTOCOL_TEST_CASES = [
"3": ["1", "2", "4"],
"4": ["1", "2", "3"],
},
"topic_map": {
"astrophysics": ["1", "2", "3", "4"],
"school": ["1", "2", "3", "4"],
},
"topic_map": {"astrophysics": ["1", "2", "3", "4"], "school": ["1", "2", "3", "4"]},
"messages": [
{"topics": ["astrophysics"], "data": b"e=mc^2", "node_id": "1"},
{"topics": ["school"], "data": b"foobar", "node_id": "2"},
@ -137,8 +134,7 @@ FLOODSUB_PROTOCOL_TEST_CASES = [
]
floodsub_protocol_pytest_params = [
pytest.param(test_case, id=test_case["name"])
for test_case in FLOODSUB_PROTOCOL_TEST_CASES
pytest.param(test_case, id=test_case["name"]) for test_case in FLOODSUB_PROTOCOL_TEST_CASES
]
@ -195,9 +191,7 @@ async def perform_test_from_obj(obj, router_factory):
# Create neighbor if neighbor does not yet exist
if neighbor_id not in node_map:
await add_node(neighbor_id)
tasks_connect.append(
connect(node_map[start_node_id], node_map[neighbor_id])
)
tasks_connect.append(connect(node_map[start_node_id], node_map[neighbor_id]))
# Connect nodes and wait at least for 2 seconds
await asyncio.gather(*tasks_connect, asyncio.sleep(2))

View File

@ -35,9 +35,7 @@ async def perform_test(num_nodes, adjacency_map, action_func, assertion_func):
for source_num in adjacency_map:
target_nums = adjacency_map[source_num]
for target_num in target_nums:
await connect(
dummy_nodes[source_num].libp2p_node, dummy_nodes[target_num].libp2p_node
)
await connect(dummy_nodes[source_num].libp2p_node, dummy_nodes[target_num].libp2p_node)
# Allow time for network creation to take place
await asyncio.sleep(0.25)

View File

@ -10,8 +10,7 @@ from .utils import dense_connect, one_to_all_connect
@pytest.mark.parametrize(
"num_hosts, gossipsub_params",
((4, GossipsubParams(degree=4, degree_low=3, degree_high=5)),),
"num_hosts, gossipsub_params", ((4, GossipsubParams(degree=4, degree_low=3, degree_high=5)),)
)
@pytest.mark.asyncio
async def test_join(num_hosts, hosts, gossipsubs, pubsubs_gsub):
@ -343,11 +342,7 @@ async def test_fanout_maintenance(hosts, pubsubs_gsub):
(
2,
GossipsubParams(
degree=1,
degree_low=0,
degree_high=2,
gossip_window=50,
gossip_history=100,
degree=1, degree_low=0, degree_high=2, gossip_window=50, gossip_history=100
),
),
),

View File

@ -20,7 +20,5 @@ async def test_gossipsub_initialize_with_floodsub_protocol():
async def test_gossipsub_run_with_floodsub_tests(test_case_obj):
await perform_test_from_obj(
test_case_obj,
functools.partial(
GossipsubFactory, degree=3, degree_low=2, degree_high=4, time_to_live=30
),
functools.partial(GossipsubFactory, degree=3, degree_low=2, degree_high=4, time_to_live=30),
)

View File

@ -128,9 +128,7 @@ async def test_continuously_read_stream(pubsubs_fsub, monkeypatch):
event_handle_rpc.set()
monkeypatch.setattr(pubsubs_fsub[0], "push_msg", mock_push_msg)
monkeypatch.setattr(
pubsubs_fsub[0], "handle_subscription", mock_handle_subscription
)
monkeypatch.setattr(pubsubs_fsub[0], "handle_subscription", mock_handle_subscription)
monkeypatch.setattr(pubsubs_fsub[0].router, "handle_rpc", mock_handle_rpc)
async def wait_for_event_occurring(event):
@ -149,9 +147,7 @@ async def test_continuously_read_stream(pubsubs_fsub, monkeypatch):
task = asyncio.ensure_future(pubsubs_fsub[0].continuously_read_stream(stream))
# Test: `push_msg` is called when publishing to a subscribed topic.
publish_subscribed_topic = rpc_pb2.RPC(
publish=[rpc_pb2.Message(topicIDs=[TESTING_TOPIC])]
)
publish_subscribed_topic = rpc_pb2.RPC(publish=[rpc_pb2.Message(topicIDs=[TESTING_TOPIC])])
await stream.write(publish_subscribed_topic.SerializeToString())
await wait_for_event_occurring(event_push_msg)
# Make sure the other events are not emitted.
@ -204,10 +200,7 @@ def test_handle_subscription(pubsubs_fsub):
peer_ids = [ID(b"\x12\x20" + i.to_bytes(32, "big")) for i in range(2)]
# Test: One peer is subscribed
pubsubs_fsub[0].handle_subscription(peer_ids[0], sub_msg_0)
assert (
len(pubsubs_fsub[0].peer_topics) == 1
and TESTING_TOPIC in pubsubs_fsub[0].peer_topics
)
assert len(pubsubs_fsub[0].peer_topics) == 1 and TESTING_TOPIC in pubsubs_fsub[0].peer_topics
assert len(pubsubs_fsub[0].peer_topics[TESTING_TOPIC]) == 1
assert peer_ids[0] in pubsubs_fsub[0].peer_topics[TESTING_TOPIC]
# Test: Another peer is subscribed
@ -233,10 +226,7 @@ def test_handle_subscription(pubsubs_fsub):
async def test_handle_talk(pubsubs_fsub):
sub = await pubsubs_fsub[0].subscribe(TESTING_TOPIC)
msg_0 = make_pubsub_msg(
origin_id=pubsubs_fsub[0].my_id,
topic_ids=[TESTING_TOPIC],
data=b"1234",
seqno=b"\x00" * 8,
origin_id=pubsubs_fsub[0].my_id, topic_ids=[TESTING_TOPIC], data=b"1234", seqno=b"\x00" * 8
)
await pubsubs_fsub[0].handle_talk(msg_0)
msg_1 = make_pubsub_msg(
@ -246,10 +236,7 @@ async def test_handle_talk(pubsubs_fsub):
seqno=b"\x11" * 8,
)
await pubsubs_fsub[0].handle_talk(msg_1)
assert (
len(pubsubs_fsub[0].my_topics) == 1
and sub == pubsubs_fsub[0].my_topics[TESTING_TOPIC]
)
assert len(pubsubs_fsub[0].my_topics) == 1 and sub == pubsubs_fsub[0].my_topics[TESTING_TOPIC]
assert sub.qsize() == 1
assert (await sub.get()) == msg_0
@ -283,9 +270,7 @@ async def test_publish(pubsubs_fsub, monkeypatch):
await pubsubs_fsub[0].publish(TESTING_TOPIC, TESTING_DATA)
assert len(msgs) == 2, "`push_msg` should be called every time `publish` is called"
assert (msg_forwarders[0] == msg_forwarders[1]) and (
msg_forwarders[1] == pubsubs_fsub[0].my_id
)
assert (msg_forwarders[0] == msg_forwarders[1]) and (msg_forwarders[1] == pubsubs_fsub[0].my_id)
assert msgs[0].seqno != msgs[1].seqno, "`seqno` should be different every time"

View File

@ -65,9 +65,7 @@ async def test_single_insecure_security_transport_succeeds():
def assertion_func(details):
assert details["id"] == "foo"
await perform_simple_test(
assertion_func, transports_for_initiator, transports_for_noninitiator
)
await perform_simple_test(assertion_func, transports_for_initiator, transports_for_noninitiator)
@pytest.mark.asyncio
@ -78,9 +76,7 @@ async def test_single_simple_test_security_transport_succeeds():
def assertion_func(details):
assert details["key_phrase"] == "tacos"
await perform_simple_test(
assertion_func, transports_for_initiator, transports_for_noninitiator
)
await perform_simple_test(assertion_func, transports_for_initiator, transports_for_noninitiator)
@pytest.mark.asyncio
@ -94,9 +90,7 @@ async def test_two_simple_test_security_transport_for_initiator_succeeds():
def assertion_func(details):
assert details["key_phrase"] == "shleep"
await perform_simple_test(
assertion_func, transports_for_initiator, transports_for_noninitiator
)
await perform_simple_test(assertion_func, transports_for_initiator, transports_for_noninitiator)
@pytest.mark.asyncio
@ -110,9 +104,7 @@ async def test_two_simple_test_security_transport_for_noninitiator_succeeds():
def assertion_func(details):
assert details["key_phrase"] == "tacos"
await perform_simple_test(
assertion_func, transports_for_initiator, transports_for_noninitiator
)
await perform_simple_test(assertion_func, transports_for_initiator, transports_for_noninitiator)
@pytest.mark.asyncio
@ -129,9 +121,7 @@ async def test_two_simple_test_security_transport_for_both_succeeds():
def assertion_func(details):
assert details["key_phrase"] == "b"
await perform_simple_test(
assertion_func, transports_for_initiator, transports_for_noninitiator
)
await perform_simple_test(assertion_func, transports_for_initiator, transports_for_noninitiator)
@pytest.mark.asyncio
@ -174,6 +164,4 @@ async def test_default_insecure_security():
else:
assert details1 == details2
await perform_simple_test(
assertion_func, transports_for_initiator, transports_for_noninitiator
)
await perform_simple_test(assertion_func, transports_for_initiator, transports_for_noninitiator)