Skip to content
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
2 changes: 1 addition & 1 deletion examples/client_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def run_sync_client(client, modbus_calls=None):
"""Run sync client."""
_logger.info("### Client starting")
client.connect()
if modbus_calls:
if modbus_calls: # pragma: no cover
modbus_calls(client)
client.close()
_logger.info("### End of Program")
Expand Down
6 changes: 3 additions & 3 deletions examples/custom_msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def encode(self):
:returns: The encoded packet message
"""
res = struct.pack(">B", len(self.values) * 2)
for register in self.values:
for register in self.values: # pragma: no cover
res += struct.pack(">H", register)
return res

Expand All @@ -65,7 +65,7 @@ def decode(self, data):
"""
byte_count = int(data[0])
self.values = []
for i in range(1, byte_count + 1, 2):
for i in range(1, byte_count + 1, 2): # pragma: no cover
self.values.append(struct.unpack(">H", data[i : i + 2])[0])


Expand Down Expand Up @@ -144,7 +144,7 @@ async def main(host="localhost", port=5020):
request1 = CustomRequest(32, device_id=device_id)
try:
result = await client.execute(False, request1)
except ModbusIOException:
except ModbusIOException: # pragma: no cover
print("Server do not support CustomRequest.")
else:
print(result)
Expand Down
4 changes: 2 additions & 2 deletions examples/datastore_simulator_share.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ def get_commandline(cmdline=None):

def setup_simulator(setup=None, actions=None, cmdline=None):
"""Run server setup."""
if not setup:
if not setup: # pragma: no cover
setup=demo_config
if not actions:
if not actions: # pragma: no cover
actions=demo_actions
args = get_commandline(cmdline=cmdline)
pymodbus_apply_logging_config(args.log.upper())
Expand Down
10 changes: 5 additions & 5 deletions examples/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def get_commandline(server: bool = False, description: str | None = None, extras
default=10,
type=float,
)
if extras:
if extras: # pragma: no cover
for extra in extras:
parser.add_argument(extra[0], **extra[1])
args = parser.parse_args(cmdline)
Expand Down Expand Up @@ -120,13 +120,13 @@ def get_certificate(suffix: str):
"""Get example certificate."""
delimiter = "\\" if os.name == "nt" else "/"
cwd = os.getcwd().split(delimiter)[-1]
if cwd == "examples":
if cwd == "examples": # pragma: no cover
path = "."
elif cwd == "sub_examples":
elif cwd == "sub_examples": # pragma: no cover
path = "../../examples"
elif cwd == "test":
elif cwd == "test": # pragma: no cover
path = "../examples"
elif cwd == "pymodbus":
elif cwd == "pymodbus": # pragma: no cover
path = "examples"
else:
raise RuntimeError(f"**Error** Cannot find certificate path={cwd}")
Expand Down
4 changes: 2 additions & 2 deletions examples/message_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def report(self, message):
f"{'name':.15s} = {message.__class__.__name__}"
)
for k_dict, v_dict in message.__dict__.items():
if isinstance(v_dict, dict):
if isinstance(v_dict, dict): # pragma: no cover
print(f"{k_dict:.15s} =")
for k_item, v_item in v_dict.items():
print(f" {k_item:.12s} => {v_item}"
Expand All @@ -121,7 +121,7 @@ def parse_messages(cmdline=None):
args = get_commandline(cmdline=cmdline)
pymodbus_apply_logging_config(args.log.upper())
_logger.setLevel(args.log.upper())
if not args.message:
if not args.message: # pragma: no cover
_logger.error("Missing --message.")
return

Expand Down
12 changes: 6 additions & 6 deletions examples/server_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,19 @@ def setup_server(description=None, context=None, cmdline=None):
# If you initialize a DataBlock to addresses of 0x00 to 0xFF, a request to
# 0x100 will respond with an invalid address exception.
# This is because many devices exhibit this kind of behavior (but not all)
if args.store == "sequential":
if args.store == "sequential": # pragma: no cover
# Continuing, use a sequential block without gaps.
datablock = lambda : ModbusSequentialDataBlock(0x00, [17] * 100) # pylint: disable=unnecessary-lambda-assignment
elif args.store == "sparse":
elif args.store == "sparse": # pragma: no cover
# Continuing, or use a sparse DataBlock which can have gaps
datablock = lambda : ModbusSparseDataBlock({0x00: 0, 0x05: 1}) # pylint: disable=unnecessary-lambda-assignment
elif args.store == "factory":
elif args.store == "factory": # pragma: no cover
# Alternately, use the factory methods to initialize the DataBlocks
# or simply do not pass them to have them initialized to 0x00 on the
# full address range::
datablock = lambda : ModbusSequentialDataBlock.create() # pylint: disable=unnecessary-lambda-assignment,unnecessary-lambda

if args.device_ids > 1:
if args.device_ids > 1: # pragma: no cover
# The server then makes use of a server context that allows the server
# to respond with different device contexts for different device ids.
# By default it will return the same context for every device id supplied
Expand Down Expand Up @@ -185,7 +185,7 @@ async def run_async_server(args) -> None:
# ignore_missing_devices=True, # ignore request to a missing device
# broadcast_enable=False, # treat device_id 0 as broadcast address,
)
elif args.comm == "tls":
elif args.comm == "tls": # pragma: no cover
address = (args.host if args.host else "", args.port if args.port else None)
await StartAsyncTlsServer(
context=args.context, # Data storage
Expand All @@ -208,7 +208,7 @@ async def run_async_server(args) -> None:
)


async def async_helper() -> None:
async def async_helper() -> None: # pragma: no cover
"""Combine setup and run."""
_logger.info("Starting...")
run_args = setup_server(description="Run asynchronous server.")
Expand Down
6 changes: 3 additions & 3 deletions examples/server_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def run_sync_server(args) -> None:
# broadcast_enable=False, # treat device_id 0 as broadcast address,
# timeout=1, # waiting time for request to complete
)
elif args.comm == "serial":
elif args.comm == "serial": # pragma: no cover
# socat -d -d PTY,link=/tmp/ptyp0,raw,echo=0,ispeed=9600
# PTY,link=/tmp/ttyp0,raw,echo=0,ospeed=9600
StartSerialServer(
Expand All @@ -108,7 +108,7 @@ def run_sync_server(args) -> None:
# ignore_missing_devices=True, # ignore request to a missing device
# broadcast_enable=False, # treat device_id 0 as broadcast address,
)
elif args.comm == "tls":
elif args.comm == "tls": # pragma: no cover
address = ("", args.port) if args.port else None
StartTlsServer(
context=args.context, # Data storage
Expand All @@ -131,7 +131,7 @@ def run_sync_server(args) -> None:
)


def sync_helper() -> None:
def sync_helper() -> None: # pragma: no cover
"""Combine setup and run."""
run_args = server_async.setup_server(description="Run synchronous server.")
run_sync_server(run_args)
Expand Down
12 changes: 6 additions & 6 deletions examples/simple_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async def run_async_simple_client(comm, host, port, framer=FramerType.SOCKET):
# retries=3,
# source_address=None,
)
elif comm == "serial":
elif comm == "serial": # pragma: no cover
client = ModbusClient.AsyncModbusSerialClient(
port,
framer=framer,
Expand All @@ -56,7 +56,7 @@ async def run_async_simple_client(comm, host, port, framer=FramerType.SOCKET):
stopbits=1,
# handle_local_echo=False,
)
else:
else: # pragma: no cover
print(f"Unknown client {comm} selected")
return

Expand All @@ -69,23 +69,23 @@ async def run_async_simple_client(comm, host, port, framer=FramerType.SOCKET):
try:
# See all calls in client_calls.py
rr = await client.read_coils(1, count=1, device_id=1)
except ModbusException as exc:
except ModbusException as exc: # pragma: no cover
print(f"Received ModbusException({exc}) from library")
client.close()
return
if rr.isError():
if rr.isError(): # pragma: no cover
print(f"Received exception from device ({rr})")
# THIS IS NOT A PYTHON EXCEPTION, but a valid modbus message
client.close()
return
try:
# See all calls in client_calls.py
rr = await client.read_holding_registers(10, count=2, device_id=1)
except ModbusException as exc:
except ModbusException as exc: # pragma: no cover
print(f"Received ModbusException({exc}) from library")
client.close()
return
if rr.isError():
if rr.isError(): # pragma: no cover
print(f"Received exception from device ({rr})")
# THIS IS NOT A PYTHON EXCEPTION, but a valid modbus message
client.close()
Expand Down
12 changes: 6 additions & 6 deletions examples/simple_sync_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def run_sync_simple_client(comm, host, port, framer=FramerType.SOCKET):
# retries=3,
# source_address=None,
)
elif comm == "serial":
elif comm == "serial": # pragma: no cover
client = ModbusClient.ModbusSerialClient(
port,
framer=framer,
Expand All @@ -58,7 +58,7 @@ def run_sync_simple_client(comm, host, port, framer=FramerType.SOCKET):
stopbits=1,
# handle_local_echo=False,
)
else:
else: # pragma: no cover
print(f"Unknown client {comm} selected")
return

Expand All @@ -68,23 +68,23 @@ def run_sync_simple_client(comm, host, port, framer=FramerType.SOCKET):
print("get and verify data")
try:
rr = client.read_coils(1, count=1, device_id=1)
except ModbusException as exc:
except ModbusException as exc: # pragma: no cover
print(f"Received ModbusException({exc}) from library")
client.close()
return
if rr.isError():
if rr.isError(): # pragma: no cover
print(f"Received exception from device ({rr})")
# THIS IS NOT A PYTHON EXCEPTION, but a valid modbus message
client.close()
return
try:
# See all calls in client_calls.py
rr = client.read_holding_registers(10, count=2, device_id=1)
except ModbusException as exc:
except ModbusException as exc: # pragma: no cover
print(f"Received ModbusException({exc}) from library")
client.close()
return
if rr.isError():
if rr.isError(): # pragma: no cover
print(f"Received exception from device ({rr})")
# THIS IS NOT A PYTHON EXCEPTION, but a valid modbus message
client.close()
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ exclude_also = [
"if __name__ == .__main__.:",
]
skip_covered = true
fail_under = 98.5
fail_under = 99.5

[tool.coverage.html]
directory = "build/cov"
Expand Down
2 changes: 1 addition & 1 deletion test/examples/test_client_server_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_server_no_client(self, mock_cls):
ServerStop()

@pytest.mark.skip
def test_server_client_twice(self, mock_cls, mock_clc, use_comm):
def test_server_client_twice(self, mock_cls, mock_clc, use_comm): # pragma: no cover
"""Run async server without client."""
if use_comm == "serial":
# cannot open the usb port multiple times
Expand Down
2 changes: 1 addition & 1 deletion test/server/test_startstop.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_ServerStop(self):
kwargs = {"address": ("127.0.0.1", 9118)}
thread = Thread(target = StartTcpServer, args = args, kwargs=kwargs)
thread.start()
while not ModbusBaseServer.active_server:
while not ModbusBaseServer.active_server: # pragma: no cover
sleep(0.1)
ServerStop()
assert not ModbusBaseServer.active_server
Expand Down