Skip to content

Commit

Permalink
self-review
Browse files Browse the repository at this point in the history
Fix a few things during self-reviewing the code
  • Loading branch information
mdabrowski1990 committed Oct 20, 2023
1 parent 3d0bc39 commit 457425f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 11 deletions.
1 change: 1 addition & 0 deletions tests/software_tests/can/test_addressing_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ def test_get_ai_data_bytes_number(self, mock_ai_mapping, addressing_format):
mock_ai_mapping.__getitem__.assert_called_once_with(addressing_format)


@pytest.mark.integration
class TestCanAddressingInformationIntegration:
"""Integration tests for `CanAddressingInformation` class."""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,7 @@ async def test_async_receive_packet(self, timeout):
transmission_time=self.mock_datetime.fromtimestamp.return_value)


@pytest.mark.integration
class TestPyCanTransportInterfaceIntegration:
"""Integration tests for `PyCanTransportInterface` class."""

Expand All @@ -980,13 +981,35 @@ class TestPyCanTransportInterfaceIntegration:
rx_physical={"can_id": 0x641},
tx_physical={"can_id": 0x642},
rx_functional={"can_id": 0x6FE},
tx_functional={"can_id": 0x6FF},
),
}
tx_functional={"can_id": 0x6FF}),
},
{
"can_bus_manager": Mock(spec=BusABC),
"addressing_information": CanAddressingInformation(
addressing_format=CanAddressingFormat.MIXED_29BIT_ADDRESSING,
tx_physical={"target_address": 0x1B, "source_address": 0xFF, "address_extension": 0x87},
rx_physical={"target_address": 0xFF, "source_address": 0x1B, "address_extension": 0x87},
tx_functional={"target_address": 0xAC, "source_address": 0xFE, "address_extension": 0xFF},
rx_functional={"target_address": 0xFE, "source_address": 0xAC, "address_extension": 0xFF}),
"n_as_timeout": 0.1,
"n_ar_timeout": 987,
"n_bs_timeout": 43,
"n_br": 5.3,
"n_cs": 0.92,
"n_cr_timeout": 98.32,
},
])
def test_init(self, init_kwargs):
py_can_ti = PyCanTransportInterface(**init_kwargs)
assert py_can_ti.bus_manager == init_kwargs["can_bus_manager"]
assert py_can_ti.addressing_information == init_kwargs["addressing_information"]
assert py_can_ti.n_as_measured is None
assert py_can_ti.n_ar_measured is None
assert py_can_ti.n_bs_measured is None
assert py_can_ti.n_cr_measured is None
assert py_can_ti.n_as_timeout == init_kwargs.get("n_as_timeout", AbstractCanTransportInterface.N_AS_TIMEOUT)
assert py_can_ti.n_ar_timeout == init_kwargs.get("n_ar_timeout", AbstractCanTransportInterface.N_AR_TIMEOUT)
assert py_can_ti.n_bs_timeout == init_kwargs.get("n_bs_timeout", AbstractCanTransportInterface.N_BS_TIMEOUT)
assert py_can_ti.n_br == init_kwargs.get("n_br", AbstractCanTransportInterface.DEFAULT_N_BR)
assert py_can_ti.n_cs == init_kwargs.get("n_cs", AbstractCanTransportInterface.DEFAULT_N_CS)
assert py_can_ti.n_cr_timeout == init_kwargs.get("n_cr_timeout", AbstractCanTransportInterface.N_CR_TIMEOUT)
6 changes: 3 additions & 3 deletions uds/segmentation/can_segmenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


class CanSegmenter(AbstractSegmenter):
"""Segmenter class that provides utilities for segmentation and desegmentation on CAN bus."""
"""Segmenter class that provides utilities for segmentation and desegmentation specific for CAN bus."""

def __init__(self, *,
addressing_information: AbstractCanAddressingInformation,
Expand All @@ -26,7 +26,7 @@ def __init__(self, *,
"""
Configure CAN Segmenter.
:param addressing_information: Addressing Information configuration of a CAN entity.
:param addressing_information: Addressing Information configuration of a CAN node.
:param dlc: Base CAN DLC value to use for creating CAN Packets.
:param use_data_optimization: Information whether to use CAN Frame Data Optimization in created CAN Packets
during segmentation.
Expand Down Expand Up @@ -75,7 +75,7 @@ def tx_packets_functional_ai(self) -> PacketAIParamsAlias:

@property
def addressing_information(self) -> AbstractCanAddressingInformation:
"""Addressing Information configuration of a CAN entity."""
"""Addressing Information configuration of a CAN node."""
return self.__addressing_information

@addressing_information.setter
Expand Down
5 changes: 3 additions & 2 deletions uds/transport_interface/abstract_transport_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async def async_send_packet(self,
Transmit UDS packet asynchronously.
:param packet: A packet to send.
:param loop: An asyncio event loop used for observing messages.
:param loop: An asyncio event loop to use for scheduling this task.
:return: Record with historic information about transmitted UDS packet.
"""
Expand All @@ -103,9 +103,10 @@ async def async_receive_packet(self,
Receive UDS packet asynchronously.
:param timeout: Maximal time (in milliseconds) to wait.
:param loop: An asyncio event loop used for observing messages.
:param loop: An asyncio event loop to use for scheduling this task.
:raise TimeoutError: Timeout was reached.
:raise asyncio.TimeoutError: Timeout was reached.
:return: Record with historic information about received UDS packet.
"""
8 changes: 5 additions & 3 deletions uds/transport_interface/can_transport_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class AbstractCanTransportInterface(AbstractTransportInterface):
DEFAULT_N_BR: TimeMilliseconds = 0
"""Default value of :ref:`N_Br <knowledge-base-can-n-br>` time parameter."""
DEFAULT_N_CS: Optional[TimeMilliseconds] = None
"""Default value of :ref:`N_Cs <knowledge-base-can-n-br>` time parameter."""
"""Default value of :ref:`N_Cs <knowledge-base-can-n-cs>` time parameter."""

def __init__(self,
can_bus_manager: Any,
Expand Down Expand Up @@ -70,9 +70,9 @@ def __init__(self,
self.n_as_timeout = kwargs.pop("n_as_timeout", self.N_AS_TIMEOUT)
self.n_ar_timeout = kwargs.pop("n_ar_timeout", self.N_AR_TIMEOUT)
self.n_bs_timeout = kwargs.pop("n_bs_timeout", self.N_BS_TIMEOUT)
self.n_cr_timeout = kwargs.pop("n_cr_timeout", self.N_CR_TIMEOUT)
self.n_br = kwargs.pop("n_br", self.DEFAULT_N_BR)
self.n_cs = kwargs.pop("n_cs", self.DEFAULT_N_CS)
self.n_cr_timeout = kwargs.pop("n_cr_timeout", self.N_CR_TIMEOUT)
self.__segmenter = CanSegmenter(addressing_information=addressing_information, **kwargs)

@property
Expand Down Expand Up @@ -236,6 +236,8 @@ def n_cs(self, value: Optional[TimeMilliseconds]):
Set the value of N_Cs time parameter to use.
:param value: The value to set.
- None - use timing compatible with STmin value received in a preceding Flow Control packet
- int/float type - timing value to be used regardless of a received STmin value
:raise TypeError: Provided value is not int or float.
:raise ValueError: Provided value is out of range.
Expand Down Expand Up @@ -453,7 +455,7 @@ def _teardown_notifier(self, suppress_warning: bool = False) -> None:
"`PyCanTransportInterface.receive_packet methods`) shall not be used together.",
category=UserWarning)

def _teardown_async_notifier(self, suppress_warning: bool = False):
def _teardown_async_notifier(self, suppress_warning: bool = False) -> None:
"""
Stop and remove CAN frame notifier for asynchronous communication.
Expand Down

0 comments on commit 457425f

Please sign in to comment.