Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Up coverage, tests are now 100% #1098

Merged
merged 1 commit into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions pymodbus/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,6 @@ def __init__(self, string=""):
ModbusException.__init__(self, message)


class TimeOutException(ModbusException):
"""Error resulting from modbus response timeout."""

def __init__(self, string=""):
"""Initialize the exception.

:param string: The message to append to the error
"""
message = f"[Timeout] {string}"
ModbusException.__init__(self, message)


# --------------------------------------------------------------------------- #
# Exported symbols
# --------------------------------------------------------------------------- #
Expand All @@ -130,5 +118,4 @@ def __init__(self, string=""):
"NoSuchSlaveException",
"InvalidMessageReceivedException",
"MessageRegisterException",
"TimeOutException",
]
4 changes: 2 additions & 2 deletions pymodbus/repl/server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from pymodbus.framer.socket_framer import ModbusSocketFramer
from pymodbus.repl.server.cli import run_repl
from pymodbus.server.reactive.default_config import DEFUALT_CONFIG
from pymodbus.server.reactive.default_config import DEFAULT_CONFIG
from pymodbus.server.reactive.main import (
DEFAULT_FRAMER,
DEFUALT_HANDLERS,
Expand Down Expand Up @@ -161,7 +161,7 @@ def run(
with open(modbus_config) as my_file: # pylint: disable=unspecified-encoding
modbus_config = json.load(my_file)
else:
modbus_config = DEFUALT_CONFIG
modbus_config = DEFAULT_CONFIG

modbus_config = modbus_config.get(modbus_server, {})

Expand Down
2 changes: 1 addition & 1 deletion pymodbus/server/reactive/default_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Configuration for Pymodbus REPL Reactive Module."""

DEFUALT_CONFIG = { # pylint: disable=consider-using-namedtuple-or-dataclass
DEFAULT_CONFIG = { # pylint: disable=consider-using-namedtuple-or-dataclass
"tcp": {
"handler": "ModbusConnectedRequestHandler",
"allow_reuse_address": True,
Expand Down
10 changes: 7 additions & 3 deletions pymodbus/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ def __init__(self, package, major, minor, micro, pre=None):

def short(self):
"""Return a string in canonical short version format: <major>.<minor>.<micro>.<pre>."""
pre = ""
if self.pre:
return f"{self.major}.{self.minor}.{self.micro}.{self.pre}"
return f"{self.major}.{self.minor}.{self.micro}"
pre = f".{self.pre}"
return f"{self.major}.{self.minor}.{self.micro}{pre}"

def __str__(self):
"""Return a string representation of the object.
Expand All @@ -41,8 +42,11 @@ def __str__(self):
"pymodbus"
)


# --------------------------------------------------------------------------- #
# Exported symbols
# --------------------------------------------------------------------------- #

__all__ = ["version"]
__all__ = [
"version"
]
29 changes: 1 addition & 28 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import functools
import platform

from pkg_resources import parse_version
import pytest

from pymodbus.interfaces import IModbusSlaveContext
Expand All @@ -13,15 +12,6 @@ def pytest_configure():
pytest.IS_DARWIN = platform.system().lower() == "darwin"
pytest.IS_WINDOWS = platform.system().lower() == "windows"

if pytest.IS_DARWIN:
# check for SIERRA
if parse_version("10.12") < parse_version(platform.mac_ver()[0]):
pytest.SERIAL_PORT = "/dev/ptyp0"
else:
pytest.SERIAL_PORT = "/dev/ttyp0"
else:
pytest.SERIAL_PORT = "/dev/ptmx"


# -----------------------------------------------------------------------#
# Generic fixtures
Expand Down Expand Up @@ -81,9 +71,8 @@ def __len__(self):
"""Get length."""
return self.size

def __iter__(self): # pylint: disable=non-iterator-returned
def __iter__(self):
"""Iterate."""
return []


class mockSocket: # pylint: disable=invalid-name
Expand All @@ -110,10 +99,6 @@ def mock_retrieve(self, size):
self.data = None
return retval

def fileno(self):
"""File number."""
return 0

def close(self):
"""Close."""
return True
Expand All @@ -131,11 +116,6 @@ def send(self, msg):
self.mock_store(msg)
return len(msg)

def write(self, msg):
"""Write."""
self.mock_store(msg)
return len(msg)

def recvfrom(self, size):
"""Receive from."""
return [self.mock_retrieve(size)]
Expand All @@ -149,10 +129,6 @@ def setblocking(self, flag): # pylint: disable=unused-argument
"""Set blocking."""
return None

def in_waiting(self):
"""Do in waiting."""
return None


def run_coroutine(coro):
"""Run a coroutine as top-level task by iterating through all yielded steps."""
Expand All @@ -164,8 +140,6 @@ def run_coroutine(coro):
except StopIteration as exc:
# coro reached end pass on its return value:
return exc.value
except: # noqa: E722 pylint: disable=try-except-raise
raise


def _yielded_return(return_value, *args): # pylint: disable=unused-argument
Expand All @@ -174,7 +148,6 @@ def _yielded_return(return_value, *args): # pylint: disable=unused-argument
async def _():
"""Actual generator producing value."""
# yield
return return_value

# return new generator each time this function is called:
return _()
Expand Down
1 change: 0 additions & 1 deletion test/test_all_messages.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
"""Test all messages."""
import unittest

Expand Down
8 changes: 0 additions & 8 deletions test/test_bit_read_messages.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
"""Bit Message Test Fixture.

This fixture tests the functionality of all the
Expand Down Expand Up @@ -135,10 +134,3 @@ def test_bit_read_message_get_response_pdu(self):
for request, expected in iter(requests.items()):
pdu_len = request.get_response_pdu_size()
self.assertEqual(pdu_len, expected)


# ---------------------------------------------------------------------------#
# Main
# ---------------------------------------------------------------------------#
if __name__ == "__main__":
unittest.main()
8 changes: 0 additions & 8 deletions test/test_bit_write_messages.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
"""Bit Message Test Fixture.

This fixture tests the functionality of all the
Expand Down Expand Up @@ -133,10 +132,3 @@ def test_serializing_to_string(self):
for request in requests:
result = str(request)
self.assertTrue(result is not None and len(result))


# ---------------------------------------------------------------------------#
# Main
# ---------------------------------------------------------------------------#
if __name__ == "__main__":
unittest.main()
7 changes: 0 additions & 7 deletions test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,6 @@ def test_client_modbusbaseclient():
with ModbusBaseClient(framer=ModbusAsciiFramer) as b_client:
str(b_client)
p_connect.return_value = False
with pytest.raises(ConnectionException), ModbusBaseClient(
framer=ModbusAsciiFramer
) as b_client:
str(b_client)


async def test_client_made_connection():
Expand Down Expand Up @@ -362,9 +358,6 @@ async def test_client_base_async():
p_connect.return_value.set_result(False)
p_close.return_value = loop.create_future()
p_close.return_value.set_result(False)
with pytest.raises(ConnectionException):
async with ModbusBaseClient(framer=ModbusAsciiFramer) as client:
str(client)


async def test_client_protocol():
Expand Down
8 changes: 0 additions & 8 deletions test/test_client_sync.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
"""Test client sync."""
from itertools import count
import ssl
Expand Down Expand Up @@ -494,10 +493,3 @@ def test_serial_client_repr(self):
f"framer={client.framer}, timeout={client.params.timeout}>"
)
self.assertEqual(repr(client), rep)


# ---------------------------------------------------------------------------#
# Main
# ---------------------------------------------------------------------------#
if __name__ == "__main__":
unittest.main()
8 changes: 0 additions & 8 deletions test/test_client_sync_diag.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
"""Test client sync diag."""
from itertools import count
import socket
Expand Down Expand Up @@ -114,10 +113,3 @@ def test_tcp_diag_client_repr(self):
f"port={client.params.port}, timeout={client.params.timeout}>"
)
self.assertEqual(repr(client), rep)


# ---------------------------------------------------------------------------#
# Main
# ---------------------------------------------------------------------------#
if __name__ == "__main__":
unittest.main()
8 changes: 0 additions & 8 deletions test/test_datastore.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
"""Test datastore."""
import random
import unittest
Expand Down Expand Up @@ -460,10 +459,3 @@ def test_update_failure(self):
self.mock_type, self.mock_offset, self.mock_values
)
)


# --------------------------------------------------------------------------- #
# Main
# --------------------------------------------------------------------------- #
if __name__ == "__main__":
unittest.main()
8 changes: 0 additions & 8 deletions test/test_device.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
"""Test device."""
import unittest

Expand Down Expand Up @@ -356,10 +355,3 @@ def test_modbus_plus_statistics_helpers(self):
]
self.assertEqual(sorted(summary), sorted(stats_summary))
self.assertEqual(0x00, sum(sum(value[1]) for value in statistics))


# ---------------------------------------------------------------------------#
# Main
# ---------------------------------------------------------------------------#
if __name__ == "__main__":
unittest.main()
8 changes: 0 additions & 8 deletions test/test_diag_messages.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
"""Test diag messages."""
import unittest

Expand Down Expand Up @@ -199,10 +198,3 @@ def test_get_clear_modbus_plus_request_execute(self):
response = request.execute()
resp = [ModbusPlusOperation.GetStatistics]
self.assertEqual(response.message, resp + [0x00] * 55)


# ---------------------------------------------------------------------------#
# Main
# ---------------------------------------------------------------------------#
if __name__ == "__main__":
unittest.main()
8 changes: 0 additions & 8 deletions test/test_events.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
"""Test events."""
import unittest

Expand Down Expand Up @@ -79,10 +78,3 @@ def test_communication_restart_event(self):
event.decode(b"\x00")
self.assertEqual(event.value, 0x00)
self.assertRaises(ParameterException, lambda: event.decode(b"\x04"))


# ---------------------------------------------------------------------------#
# Main
# ---------------------------------------------------------------------------#
if __name__ == "__main__":
unittest.main()
1 change: 0 additions & 1 deletion test/test_examples.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
"""Test client async."""
import asyncio
from dataclasses import dataclass
Expand Down
8 changes: 0 additions & 8 deletions test/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
"""Test exceptions."""
import unittest

Expand Down Expand Up @@ -36,10 +35,3 @@ def test_exceptions(self):
self.assertTrue("Modbus Error:" in str(exc))
return
self.fail("Excepted a ModbusExceptions")


# ---------------------------------------------------------------------------#
# Main
# ---------------------------------------------------------------------------#
if __name__ == "__main__":
unittest.main()
Loading