Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_iperf_correctly_parses_singlerun_udp_server_output(buffer_connection):
from moler.cmd.unix import iperf2
buffer_connection.remote_inject_response([iperf2.COMMAND_OUTPUT_singlerun_udp_server])
iperf_cmd = iperf2.Iperf2(connection=buffer_connection.moler_connection,
**iperf2.COMMAND_KWARGS_singlerun_udp_server)
ret = iperf_cmd()
assert ret == iperf2.COMMAND_RESULT_singlerun_udp_server
def test_iperf_correctly_parses_tcp_ipv6_server_output(buffer_connection):
from moler.cmd.unix import iperf2
buffer_connection.remote_inject_response([iperf2.COMMAND_OUTPUT_tcp_ipv6_server])
iperf_cmd = iperf2.Iperf2(connection=buffer_connection.moler_connection,
**iperf2.COMMAND_KWARGS_tcp_ipv6_server)
res = iperf_cmd()
assert res == iperf2.COMMAND_RESULT_tcp_ipv6_server
def test_iperf_correctly_parses_bidirectional_udp_client_output(buffer_connection):
from moler.cmd.unix import iperf2
buffer_connection.remote_inject_response([iperf2.COMMAND_OUTPUT_bidirectional_udp_client])
iperf_cmd = iperf2.Iperf2(connection=buffer_connection.moler_connection,
**iperf2.COMMAND_KWARGS_bidirectional_udp_client)
res = iperf_cmd()
assert res == iperf2.COMMAND_RESULT_bidirectional_udp_client
def test_iperf_raise_error_on_bind_failed(buffer_connection, command_output_and_expected_result_on_bind_failed):
iperf_cmd = Iperf2(connection=buffer_connection.moler_connection, options='-s')
command_output, expected_result = command_output_and_expected_result_on_bind_failed
buffer_connection.remote_inject_response([command_output])
assert 'iperf -s' == iperf_cmd.command_string
with pytest.raises(CommandFailure):
iperf_cmd()
def test_iperf_detecting_dualtest_at_server(buffer_connection):
from moler.cmd.unix import iperf2
buffer_connection.remote_inject_response([iperf2.COMMAND_OUTPUT_bidirectional_udp_server])
iperf_cmd = iperf2.Iperf2(connection=buffer_connection.moler_connection,
**iperf2.COMMAND_KWARGS_bidirectional_udp_server)
iperf_cmd()
assert iperf_cmd.works_in_dualtest is True
buffer_connection.remote_inject_response([iperf2.COMMAND_OUTPUT_multiple_connections_server])
iperf_cmd = iperf2.Iperf2(connection=buffer_connection.moler_connection,
**iperf2.COMMAND_KWARGS_multiple_connections_server)
iperf_cmd()
assert iperf_cmd.works_in_dualtest is False
def test_iperf_raise_error_on_iperf_problem(buffer_connection, command_output_and_expected_result_on_iperf_problem):
iperf_cmd = Iperf2(connection=buffer_connection.moler_connection, options='-i')
command_output, expected_result = command_output_and_expected_result_on_iperf_problem
buffer_connection.remote_inject_response([command_output])
assert 'iperf -i' == iperf_cmd.command_string
with pytest.raises(CommandFailure):
iperf_cmd()
def test_iperf_singlerun_server_doesnt_use_ctrlc_to_stop_server(buffer_connection):
from moler.cmd.unix import iperf2
buffer_connection.remote_inject_response([iperf2.COMMAND_OUTPUT_singlerun_server])
iperf_cmd = iperf2.Iperf2(connection=buffer_connection.moler_connection,
**iperf2.COMMAND_KWARGS_singlerun_server)
with mock.patch.object(iperf_cmd, "break_cmd") as send_ctrlc:
iperf_cmd()
send_ctrlc.assert_not_called()
def _parse_headers(self, line):
if self._regex_helper.search_compiled(Iperf2._re_headers, line):
if self.parallel_client:
# header line is after connections
# so, we can create virtual Summary connection
client, server = list(self._connection_dict.values())[0]
client_host, client_port, server_host, server_port = self._split_connection_name((client, server))
connection_id = '[SUM]'
self._connection_dict[connection_id] = ("{}@{}".format("multiport", client_host), server)
raise ParsingDone
def interval(self):
if self._regex_helper.search_compiled(Iperf2._re_interval, self.options):
return float(self._regex_helper.group('INTERVAL'))
return 0.0
def _parse_connection_name_and_id(self, line):
if self._regex_helper.search_compiled(Iperf2._re_connection_info, line):
connection_id, local_host, local_port, remote_host, remote_port = self._regex_helper.groups()
local = "{}@{}".format(local_port, local_host)
remote = "{}@{}".format(remote_port, remote_host)
if self.port == int(remote_port):
from_client, to_server = local, remote
else:
from_client, to_server = remote, local
connection_dict = {connection_id: (from_client, to_server)}
self._connection_dict.update(connection_dict)
raise ParsingDone