improve python code readability with comments and logging statements
diff --git a/plc4py/plc4py/PlcDriverManager.py b/plc4py/plc4py/PlcDriverManager.py
index e5e6c08..c2bcb26 100644
--- a/plc4py/plc4py/PlcDriverManager.py
+++ b/plc4py/plc4py/PlcDriverManager.py
@@ -45,9 +45,7 @@
defined in the "plc4py.drivers" namespace.
"""
# Log the class loader used
- logging.info(
- f"Instantiating new PLC Driver Manager with class loader {self.class_loader}"
- )
+ logging.info("Instantiating new PLC Driver Manager with class loader %s", self.class_loader)
# Add the PlcDriverClassLoader hookspecs to the class loader
self.class_loader.add_hookspecs(PlcDriverClassLoader)
@@ -73,7 +71,7 @@
# Log the successful registration of each driver
for driver in self._driver_map:
- logging.info(f"... {driver} .. OK")
+ logging.info("... %s .. OK", driver)
# Check for any pending plugins
self.class_loader.check_pending()
diff --git a/plc4py/plc4py/api/messages/PlcMessage.py b/plc4py/plc4py/api/messages/PlcMessage.py
index 6ac3e59..dc0427e 100644
--- a/plc4py/plc4py/api/messages/PlcMessage.py
+++ b/plc4py/plc4py/api/messages/PlcMessage.py
@@ -20,4 +20,9 @@
class PlcMessage(Serializable):
+ """
+ A class representing a PLC message.
+
+ Add more details about the class and its functionality here.
+ """
pass
diff --git a/plc4py/plc4py/api/messages/PlcResponse.py b/plc4py/plc4py/api/messages/PlcResponse.py
index 33d726a..9cafeea 100644
--- a/plc4py/plc4py/api/messages/PlcResponse.py
+++ b/plc4py/plc4py/api/messages/PlcResponse.py
@@ -2,7 +2,7 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
+# regarding copyright ownership. The ASF licenses this filehttps://www.twitch.tv/
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
diff --git a/plc4py/tests/test_plc4py.py b/plc4py/tests/test_plc4py.py
index 554a9db..eb99fe5 100644
--- a/plc4py/tests/test_plc4py.py
+++ b/plc4py/tests/test_plc4py.py
@@ -40,15 +40,6 @@
:return: None
"""
- """
- This test verifies the version of the package.
-
- The version is a string that is expected to match the version specified in the
- `__version__` constant at the top of the file. If the versions do not match,
- the test will fail.
-
- :return: None
- """
assert __version__ == "0.1.0"
@@ -60,15 +51,6 @@
:return: None
"""
- """
- This test verifies that the PlcDriverManager class is able to create a connection
- successfully.
-
- The test creates a PlcDriverManager object and then uses the connection method
- to get a connection to a mock PLC. The connection should be an instance of
- the PlcConnection class.
-
- """
driver_manager = PlcDriverManager()
async with driver_manager.connection("mock:tcp://127.0.0.1:502") as connection:
assert isinstance(connection, PlcConnection)
diff --git a/plc4py/tests/unit/plc4py/drivers/modbus/test_modbus_codegen.py b/plc4py/tests/unit/plc4py/drivers/modbus/test_modbus_codegen.py
index 3b881b3..5d94783 100644
--- a/plc4py/tests/unit/plc4py/drivers/modbus/test_modbus_codegen.py
+++ b/plc4py/tests/unit/plc4py/drivers/modbus/test_modbus_codegen.py
@@ -28,13 +28,23 @@
@pytest.mark.asyncio
-async def test_modbus_discrete_inputs_request():
- request = ModbusPDUReadDiscreteInputsRequestBuilder(0, 10).build()
- assert request is not None
+async def test_modbus_discrete_inputs_request_standardized():
+ """
+ Test case for Modbus PDU Read Discrete Inputs Request
+ """
+ # Create a Modbus PDU Read Discrete Inputs Request with address 0 and quantity 10
+ discrete_inputs_request = ModbusPDUReadDiscreteInputsRequestBuilder(0, 10).build()
+
+ # Ensure the request object is not None
+ assert discrete_inputs_request is not None
@pytest.mark.asyncio
async def test_modbus_discrete_inputs_request_serialize():
+ """
+ Test case for serializing Modbus PDU Read Discrete Inputs Request
+ """
+ # Create a Modbus PDU Read Discrete Inputs Request
request = ModbusPDUReadDiscreteInputsRequestBuilder(5, 2).build()
size = request.length_in_bytes()
write_buffer = WriteBufferByteBased(size, ByteOrder.BIG_ENDIAN)
@@ -49,11 +59,25 @@
@pytest.mark.asyncio
async def test_modbus_ModbusTcpADUBuilder_serialize():
+ """
+ Test case for serializing Modbus TCP ADU
+ """
+ # Create a Modbus PDU Read Discrete Inputs
pdu = ModbusPDUReadDiscreteInputsRequestBuilder(5, 2).build()
+
+ # Build Modbus TCP ADU
request = ModbusTcpADUBuilder(10, 5, pdu).build(False)
+
+ # Get the size of the request
size = request.length_in_bytes()
+
+ # Create a write buffer
write_buffer = WriteBufferByteBased(size, ByteOrder.BIG_ENDIAN)
+
+ # Serialize the request
serialize = request.serialize(write_buffer)
+
+ # Get the serialized bytes
bytes_array = write_buffer.get_bytes().tobytes()
assert request is not None
diff --git a/plc4py/tests/unit/plc4py/drivers/modbus/test_modbus_connection.py b/plc4py/tests/unit/plc4py/drivers/modbus/test_modbus_connection.py
index fddd86c..6feaf0c 100644
--- a/plc4py/tests/unit/plc4py/drivers/modbus/test_modbus_connection.py
+++ b/plc4py/tests/unit/plc4py/drivers/modbus/test_modbus_connection.py
@@ -29,27 +29,43 @@
@pytest.mark.asyncio
async def manual_test_plc_driver_modbus_connect():
+ """
+ Test the connection to a Modbus PLC using PlcDriverManager.
+ """
+ # Initialize the PlcDriverManager
driver_manager = PlcDriverManager()
+
+ # Establish a connection to the Modbus PLC
async with driver_manager.connection("modbus://1") as connection:
+ # Check if the connection is successful
assert connection.is_connected()
+
+ # Ensure the connection is closed after exiting the context manager
assert not connection.is_connected()
@pytest.mark.asyncio
@pytest.mark.xfail
async def test_plc_driver_modbus_read():
+ """
+ Test reading data from a Modbus PLC.
+ """
log = logging.getLogger(__name__)
+ # Initialize the PlcDriverManager
driver_manager = PlcDriverManager()
+
+ # Establish a connection to the Modbus PLC
async with driver_manager.connection("modbus://127.0.0.1:5020") as connection:
with connection.read_request_builder() as builder:
builder.add_item("Random Tag", "4x00001[10]")
request = builder.build()
+ # Execute the read request
future = connection.execute(request)
await future
response = future.result()
value = response.tags["Random Tag"].value
- log.error(f"Read tag 4x00001[10] - {value}")
+ log.error("Read tag 4x00001[10] - %s", value)
pass