Skip to content

Commit 812f2bd

Browse files
authored
Up coverage, tests are 100%. (#1098)
1 parent 4a10fce commit 812f2bd

36 files changed

+61
-367
lines changed

pymodbus/exceptions.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,6 @@ def __init__(self, string=""):
106106
ModbusException.__init__(self, message)
107107

108108

109-
class TimeOutException(ModbusException):
110-
"""Error resulting from modbus response timeout."""
111-
112-
def __init__(self, string=""):
113-
"""Initialize the exception.
114-
115-
:param string: The message to append to the error
116-
"""
117-
message = f"[Timeout] {string}"
118-
ModbusException.__init__(self, message)
119-
120-
121109
# --------------------------------------------------------------------------- #
122110
# Exported symbols
123111
# --------------------------------------------------------------------------- #
@@ -130,5 +118,4 @@ def __init__(self, string=""):
130118
"NoSuchSlaveException",
131119
"InvalidMessageReceivedException",
132120
"MessageRegisterException",
133-
"TimeOutException",
134121
]

pymodbus/repl/server/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from pymodbus.framer.socket_framer import ModbusSocketFramer
1414
from pymodbus.repl.server.cli import run_repl
15-
from pymodbus.server.reactive.default_config import DEFUALT_CONFIG
15+
from pymodbus.server.reactive.default_config import DEFAULT_CONFIG
1616
from pymodbus.server.reactive.main import (
1717
DEFAULT_FRAMER,
1818
DEFUALT_HANDLERS,
@@ -161,7 +161,7 @@ def run(
161161
with open(modbus_config) as my_file: # pylint: disable=unspecified-encoding
162162
modbus_config = json.load(my_file)
163163
else:
164-
modbus_config = DEFUALT_CONFIG
164+
modbus_config = DEFAULT_CONFIG
165165

166166
modbus_config = modbus_config.get(modbus_server, {})
167167

pymodbus/server/reactive/default_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Configuration for Pymodbus REPL Reactive Module."""
22

3-
DEFUALT_CONFIG = { # pylint: disable=consider-using-namedtuple-or-dataclass
3+
DEFAULT_CONFIG = { # pylint: disable=consider-using-namedtuple-or-dataclass
44
"tcp": {
55
"handler": "ModbusConnectedRequestHandler",
66
"allow_reuse_address": True,

pymodbus/version.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ def __init__(self, package, major, minor, micro, pre=None):
2424

2525
def short(self):
2626
"""Return a string in canonical short version format: <major>.<minor>.<micro>.<pre>."""
27+
pre = ""
2728
if self.pre:
28-
return f"{self.major}.{self.minor}.{self.micro}.{self.pre}"
29-
return f"{self.major}.{self.minor}.{self.micro}"
29+
pre = f".{self.pre}"
30+
return f"{self.major}.{self.minor}.{self.micro}{pre}"
3031

3132
def __str__(self):
3233
"""Return a string representation of the object.
@@ -41,8 +42,11 @@ def __str__(self):
4142
"pymodbus"
4243
)
4344

45+
4446
# --------------------------------------------------------------------------- #
4547
# Exported symbols
4648
# --------------------------------------------------------------------------- #
4749

48-
__all__ = ["version"]
50+
__all__ = [
51+
"version"
52+
]

test/conftest.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import functools
33
import platform
44

5-
from pkg_resources import parse_version
65
import pytest
76

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

16-
if pytest.IS_DARWIN:
17-
# check for SIERRA
18-
if parse_version("10.12") < parse_version(platform.mac_ver()[0]):
19-
pytest.SERIAL_PORT = "/dev/ptyp0"
20-
else:
21-
pytest.SERIAL_PORT = "/dev/ttyp0"
22-
else:
23-
pytest.SERIAL_PORT = "/dev/ptmx"
24-
2515

2616
# -----------------------------------------------------------------------#
2717
# Generic fixtures
@@ -81,9 +71,8 @@ def __len__(self):
8171
"""Get length."""
8272
return self.size
8373

84-
def __iter__(self): # pylint: disable=non-iterator-returned
74+
def __iter__(self):
8575
"""Iterate."""
86-
return []
8776

8877

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

113-
def fileno(self):
114-
"""File number."""
115-
return 0
116-
117102
def close(self):
118103
"""Close."""
119104
return True
@@ -131,11 +116,6 @@ def send(self, msg):
131116
self.mock_store(msg)
132117
return len(msg)
133118

134-
def write(self, msg):
135-
"""Write."""
136-
self.mock_store(msg)
137-
return len(msg)
138-
139119
def recvfrom(self, size):
140120
"""Receive from."""
141121
return [self.mock_retrieve(size)]
@@ -149,10 +129,6 @@ def setblocking(self, flag): # pylint: disable=unused-argument
149129
"""Set blocking."""
150130
return None
151131

152-
def in_waiting(self):
153-
"""Do in waiting."""
154-
return None
155-
156132

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

170144

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

179152
# return new generator each time this function is called:
180153
return _()

test/test_all_messages.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python3
21
"""Test all messages."""
32
import unittest
43

test/test_bit_read_messages.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python3
21
"""Bit Message Test Fixture.
32
43
This fixture tests the functionality of all the
@@ -135,10 +134,3 @@ def test_bit_read_message_get_response_pdu(self):
135134
for request, expected in iter(requests.items()):
136135
pdu_len = request.get_response_pdu_size()
137136
self.assertEqual(pdu_len, expected)
138-
139-
140-
# ---------------------------------------------------------------------------#
141-
# Main
142-
# ---------------------------------------------------------------------------#
143-
if __name__ == "__main__":
144-
unittest.main()

test/test_bit_write_messages.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python3
21
"""Bit Message Test Fixture.
32
43
This fixture tests the functionality of all the
@@ -133,10 +132,3 @@ def test_serializing_to_string(self):
133132
for request in requests:
134133
result = str(request)
135134
self.assertTrue(result is not None and len(result))
136-
137-
138-
# ---------------------------------------------------------------------------#
139-
# Main
140-
# ---------------------------------------------------------------------------#
141-
if __name__ == "__main__":
142-
unittest.main()

test/test_client.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,6 @@ def test_client_modbusbaseclient():
292292
with ModbusBaseClient(framer=ModbusAsciiFramer) as b_client:
293293
str(b_client)
294294
p_connect.return_value = False
295-
with pytest.raises(ConnectionException), ModbusBaseClient(
296-
framer=ModbusAsciiFramer
297-
) as b_client:
298-
str(b_client)
299295

300296

301297
async def test_client_made_connection():
@@ -362,9 +358,6 @@ async def test_client_base_async():
362358
p_connect.return_value.set_result(False)
363359
p_close.return_value = loop.create_future()
364360
p_close.return_value.set_result(False)
365-
with pytest.raises(ConnectionException):
366-
async with ModbusBaseClient(framer=ModbusAsciiFramer) as client:
367-
str(client)
368361

369362

370363
async def test_client_protocol():

test/test_client_sync.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python3
21
"""Test client sync."""
32
from itertools import count
43
import ssl
@@ -494,10 +493,3 @@ def test_serial_client_repr(self):
494493
f"framer={client.framer}, timeout={client.params.timeout}>"
495494
)
496495
self.assertEqual(repr(client), rep)
497-
498-
499-
# ---------------------------------------------------------------------------#
500-
# Main
501-
# ---------------------------------------------------------------------------#
502-
if __name__ == "__main__":
503-
unittest.main()

0 commit comments

Comments
 (0)