Skip to content

Commit aa121e4

Browse files
authored
Test coverage global 100%. (#2764)
1 parent 38421f3 commit aa121e4

File tree

3 files changed

+61
-6
lines changed

3 files changed

+61
-6
lines changed

test/global/test_exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33

44
from pymodbus.exceptions import (
55
ConnectionException,
6+
MessageRegisterException,
67
ModbusException,
78
ModbusIOException,
9+
NoSuchIdException,
810
NotImplementedException,
911
ParameterException,
1012
)
@@ -19,6 +21,8 @@ class TestExceptions: # pylint: disable=too-few-public-methods
1921
ParameterException("bad parameter"),
2022
NotImplementedException("bad function"),
2123
ConnectionException("bad connection"),
24+
NoSuchIdException("no id"),
25+
MessageRegisterException("Wrong message"),
2226
]
2327

2428
def test_exceptions(self):

test/global/test_logging.py

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55
import pytest
66

7-
from pymodbus.logging import Log, pymodbus_apply_logging_config
7+
from pymodbus.logging import (
8+
Log,
9+
pymodbus_apply_logging_config,
10+
pymodbus_get_last_frames,
11+
)
812

913

1014
class TestLogging:
@@ -47,31 +51,73 @@ def test_apply_logging(self):
4751
pymodbus_apply_logging_config("info")
4852
pymodbus_apply_logging_config(logging.NOTSET)
4953
Log.debug("test 1no")
54+
pymodbus_apply_logging_config(logging.CRITICAL)
55+
Log.debug("test 1no")
5056
pymodbus_apply_logging_config("debug")
5157
Log.debug("test 1")
5258
Log.debug("test 1")
5359
Log.debug("test 1")
54-
pymodbus_apply_logging_config(logging.NOTSET)
60+
Log.error("get frames")
61+
Log.critical("get frames")
62+
pymodbus_apply_logging_config(logging.CRITICAL)
5563
Log.warning("test 2no")
5664
pymodbus_apply_logging_config("warning")
5765
Log.warning("test 2")
5866
Log.warning("test 2")
5967
Log.warning("test 2")
60-
pymodbus_apply_logging_config(logging.NOTSET)
68+
pymodbus_apply_logging_config(logging.CRITICAL)
6169
Log.critical("test 3no")
6270
pymodbus_apply_logging_config("critical")
6371
Log.critical("test 3")
6472
Log.critical("test 3")
6573
Log.critical("test 3")
66-
pymodbus_apply_logging_config(logging.NOTSET)
74+
pymodbus_apply_logging_config(logging.CRITICAL)
6775
Log.error("test 4no")
6876
pymodbus_apply_logging_config("error")
6977
Log.error("test 4")
7078
Log.error("test 4")
7179
Log.error("test 4")
72-
pymodbus_apply_logging_config(logging.NOTSET)
80+
pymodbus_apply_logging_config(logging.CRITICAL)
7381
Log.info("test 5no")
7482
pymodbus_apply_logging_config("info")
7583
Log.info("test 5")
7684
Log.info("test 5")
7785
Log.info("test 5")
86+
87+
def test_apply_build_no(self):
88+
"""Test pymodbus_apply_logging_config."""
89+
with mock.patch("pymodbus.logging.Log.build_msg") as build:
90+
build.return_value = None
91+
Log.critical("test 0")
92+
pymodbus_apply_logging_config("debug")
93+
Log.debug("test 1")
94+
pymodbus_apply_logging_config("warning")
95+
Log.warning("test 2")
96+
pymodbus_apply_logging_config("critical")
97+
pymodbus_apply_logging_config("error")
98+
Log.error("test 4")
99+
pymodbus_apply_logging_config("info")
100+
Log.info("test 5")
101+
102+
def test_log_get_frames(self):
103+
"""Test get_frames."""
104+
pymodbus_get_last_frames()
105+
for _ in range(100):
106+
Log.transport_dump(Log.SEND_DATA, b'678', b'9')
107+
pymodbus_get_last_frames()
108+
109+
def test_transport_dump(self):
110+
"""Test transport_dump."""
111+
pymodbus_apply_logging_config("error")
112+
Log.transport_dump(Log.SEND_DATA, b'123', b'4')
113+
for _ in range(100):
114+
Log.transport_dump(Log.SEND_DATA, b'678', b'9')
115+
pymodbus_apply_logging_config("debug")
116+
Log.transport_dump(Log.SEND_DATA, b'123', b'4')
117+
118+
def test_build_frame_log_line(self):
119+
"""Test build_frame_log_line."""
120+
Log.build_frame_log_line(Log.SEND_DATA, b'123', b'4')
121+
Log.build_frame_log_line(Log.RECV_DATA, b'123', b'4')
122+
Log.build_frame_log_line("Unknown", b'123', b'4')
123+

test/global/test_utilities.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Test utilities."""
22
import struct
33

4-
from pymodbus.utilities import dict_property
4+
from pymodbus.utilities import dict_property, hexlify_packets
55

66

77
_test_master = {4: "d"}
@@ -58,3 +58,8 @@ def test_dict_property(self):
5858
assert result.s_1 == "x"
5959
assert result.s_2 == "x"
6060
assert result.g_1 == "x"
61+
62+
def test_hexlify_packets(self):
63+
"""Test hexlify_packets."""
64+
assert hexlify_packets(b'123') == "0x31 0x32 0x33"
65+
assert hexlify_packets(None) == ""

0 commit comments

Comments
 (0)