Skip to content

Commit

Permalink
fallout from flake8 change. (#1523)
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen authored Apr 25, 2023
1 parent b6384d0 commit eff773a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
38 changes: 18 additions & 20 deletions test/test_framers.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_framer_initialization(framer):


@pytest.mark.parametrize("data", [(b"", {}), (b"abcd", {"fcode": 98, "slave": 97})])
def test_decode_data(rtu_framer, data): # pylint: disable=redefined-outer-name
def test_decode_data(rtu_framer, data):
"""Test decode data."""
data, expected = data
decoded = rtu_framer.decode_data(data)
Expand All @@ -99,7 +99,7 @@ def test_decode_data(rtu_framer, data): # pylint: disable=redefined-outer-name
(b"\x11\x03\x06\xAE\x41\x56\x52\x43\x40\x49\xAC", False), # invalid frame CRC
],
)
def test_check_frame(rtu_framer, data): # pylint: disable=redefined-outer-name
def test_check_frame(rtu_framer, data):
"""Test check frame."""
data, expected = data
rtu_framer._buffer = data # pylint: disable=protected-access
Expand All @@ -118,7 +118,7 @@ def test_check_frame(rtu_framer, data): # pylint: disable=redefined-outer-name
),
],
)
def test_rtu_advance_framer(rtu_framer, data): # pylint: disable=redefined-outer-name
def test_rtu_advance_framer(rtu_framer, data):
"""Test rtu advance framer."""
before_buf, before_header, after_buf = data

Expand All @@ -134,7 +134,7 @@ def test_rtu_advance_framer(rtu_framer, data): # pylint: disable=redefined-oute


@pytest.mark.parametrize("data", [b"", b"abcd"])
def test_rtu_reset_framer(rtu_framer, data): # pylint: disable=redefined-outer-name
def test_rtu_reset_framer(rtu_framer, data):
"""Test rtu reset framer."""
rtu_framer._buffer = data # pylint: disable=protected-access
rtu_framer.resetFrame()
Expand All @@ -157,7 +157,7 @@ def test_rtu_reset_framer(rtu_framer, data): # pylint: disable=redefined-outer-
(b"\x11\x03\x06\xAE\x41\x56\x52\x43\x40\x49\xAD\xAB\xCD", True),
],
)
def test_is_frame_ready(rtu_framer, data): # pylint: disable=redefined-outer-name
def test_is_frame_ready(rtu_framer, data):
"""Test is frame ready."""
data, expected = data
rtu_framer._buffer = data # pylint: disable=protected-access
Expand All @@ -175,9 +175,7 @@ def test_is_frame_ready(rtu_framer, data): # pylint: disable=redefined-outer-na
b"\x11\x03\x06\xAE\x41\x56\x52\x43\x40\x43",
],
)
def test_rtu_populate_header_fail(
rtu_framer, data
): # pylint: disable=redefined-outer-name
def test_rtu_populate_header_fail(rtu_framer, data):
"""Test rtu populate header fail."""
with pytest.raises(IndexError):
rtu_framer.populateHeader(data)
Expand All @@ -196,28 +194,28 @@ def test_rtu_populate_header_fail(
),
],
)
def test_rtu_populate_header(rtu_framer, data): # pylint: disable=redefined-outer-name
def test_rtu_populate_header(rtu_framer, data):
"""Test rtu populate header."""
buffer, expected = data
rtu_framer.populateHeader(buffer)
assert rtu_framer._header == expected # pylint: disable=protected-access


def test_add_to_frame(rtu_framer): # pylint: disable=redefined-outer-name
def test_add_to_frame(rtu_framer):
"""Test add to frame."""
assert rtu_framer._buffer == b"" # pylint: disable=protected-access
rtu_framer.addToFrame(b"abcd")
assert rtu_framer._buffer == b"abcd" # pylint: disable=protected-access


def test_get_frame(rtu_framer): # pylint: disable=redefined-outer-name
def test_get_frame(rtu_framer):
"""Test get frame."""
rtu_framer.addToFrame(b"\x02\x01\x01\x00Q\xcc")
rtu_framer.populateHeader(b"\x02\x01\x01\x00Q\xcc")
assert rtu_framer.getFrame() == b"\x01\x01\x00"


def test_populate_result(rtu_framer): # pylint: disable=redefined-outer-name
def test_populate_result(rtu_framer):
"""Test populate result."""
rtu_framer._header["uid"] = 255 # pylint: disable=protected-access
result = mock.Mock()
Expand Down Expand Up @@ -261,7 +259,7 @@ def test_populate_result(rtu_framer): # pylint: disable=redefined-outer-name
# good frame + part of next frame
],
)
def test_rtu_incoming_packet(rtu_framer, data): # pylint: disable=redefined-outer-name
def test_rtu_incoming_packet(rtu_framer, data):
"""Test rtu process incoming packet."""
buffer, slaves, reset_called, process_called = data

Expand All @@ -277,13 +275,13 @@ def test_rtu_incoming_packet(rtu_framer, data): # pylint: disable=redefined-out
assert mock_reset.call_count == (1 if reset_called else 0)


def test_build_packet(rtu_framer): # pylint: disable=redefined-outer-name
def test_build_packet(rtu_framer):
"""Test build packet."""
message = ReadCoilsRequest(1, 10)
assert rtu_framer.buildPacket(message) == TEST_MESSAGE


def test_send_packet(rtu_framer): # pylint: disable=redefined-outer-name
def test_send_packet(rtu_framer):
"""Test send packet."""
message = TEST_MESSAGE
client = ModbusBaseClient(framer=ModbusRtuFramer)
Expand All @@ -299,7 +297,7 @@ def test_send_packet(rtu_framer): # pylint: disable=redefined-outer-name
assert rtu_framer.sendPacket(message) == len(message)


def test_recv_packet(rtu_framer): # pylint: disable=redefined-outer-name
def test_recv_packet(rtu_framer):
"""Test receive packet."""
message = TEST_MESSAGE
client = mock.Mock()
Expand All @@ -308,15 +306,15 @@ def test_recv_packet(rtu_framer): # pylint: disable=redefined-outer-name
assert rtu_framer.recvPacket(len(message)) == message


def test_process(rtu_framer): # pylint: disable=redefined-outer-name
def test_process(rtu_framer):
"""Test process."""

rtu_framer._buffer = TEST_MESSAGE # pylint: disable=protected-access
with pytest.raises(ModbusIOException):
rtu_framer._process(None) # pylint: disable=protected-access


def test_get_raw_frame(rtu_framer): # pylint: disable=redefined-outer-name
def test_get_raw_frame(rtu_framer):
"""Test get raw frame."""
rtu_framer._buffer = TEST_MESSAGE # pylint: disable=protected-access
assert (
Expand All @@ -325,15 +323,15 @@ def test_get_raw_frame(rtu_framer): # pylint: disable=redefined-outer-name
)


def test_validate__slave_id(rtu_framer): # pylint: disable=redefined-outer-name
def test_validate__slave_id(rtu_framer):
"""Test validate slave."""
rtu_framer.populateHeader(TEST_MESSAGE)
assert rtu_framer._validate_slave_id([0], False) # pylint: disable=protected-access
assert rtu_framer._validate_slave_id([1], True) # pylint: disable=protected-access


@pytest.mark.parametrize("data", [b":010100010001FC\r\n", b""])
def test_decode_ascii_data(ascii_framer, data): # pylint: disable=redefined-outer-name
def test_decode_ascii_data(ascii_framer, data):
"""Test decode ascii."""
data = ascii_framer.decode_data(data)
assert isinstance(data, dict)
Expand Down
4 changes: 2 additions & 2 deletions test/test_server_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ async def test_async_task_no_server(comm):
client = run_client(**client_args)
try:
await client.connect()
except Exception as exc: # pylint: disable=broad-except
except Exception as exc:
raise AssertionError(f"unexpected exception: {exc}") from exc
await asyncio.sleep(0.1)
with pytest.raises((asyncio.exceptions.TimeoutError, ConnectionException)):
Expand Down Expand Up @@ -269,7 +269,7 @@ def test_sync_task_no_server(comm):
client = run_client(**client_args)
try:
client.connect()
except Exception as exc: # pylint: disable=broad-except
except Exception as exc:
raise AssertionError(f"unexpected exception: {exc}") from exc
sleep(0.1)
if comm == "udp":
Expand Down

0 comments on commit eff773a

Please sign in to comment.