Skip to content

Commit

Permalink
update system tests
Browse files Browse the repository at this point in the history
- use case scenarios (system tests) tests are reworked and fully working
- add get_other_end method to CanAddressingInformation for convinience
  • Loading branch information
mdabrowski1990 committed Oct 26, 2024
1 parent 91f0fe1 commit b833d34
Show file tree
Hide file tree
Showing 9 changed files with 266 additions and 145 deletions.
7 changes: 1 addition & 6 deletions examples/can/python-can/kvaser/send_and_receive_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ def main():
rx_physical={"can_id": 0x612},
tx_functional={"can_id": 0x6FF},
rx_functional={"can_id": 0x6FE})
ai_send = CanAddressingInformation(
addressing_format=ai_receive.addressing_format,
tx_physical={"can_id": 0x612},
rx_physical={"can_id": 0x611},
tx_functional={"can_id": 0x6FE},
rx_functional={"can_id": 0x6FF})
ai_send = ai_receive.get_other_end()

# create Transport Interface objects for UDS communication
can_ti_1 = PyCanTransportInterface(can_bus_manager=kvaser_interface_1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ async def main():
rx_physical={"can_id": 0x612},
tx_functional={"can_id": 0x6FF},
rx_functional={"can_id": 0x6FE})
ai_send = CanAddressingInformation(
addressing_format=ai_receive.addressing_format,
tx_physical={"can_id": 0x612},
rx_physical={"can_id": 0x611},
tx_functional={"can_id": 0x6FE},
rx_functional={"can_id": 0x6FF})
ai_send = ai_receive.get_other_end()

# create Transport Interface objects for UDS communication
can_ti_1 = PyCanTransportInterface(can_bus_manager=kvaser_interface_1,
Expand Down
7 changes: 1 addition & 6 deletions examples/can/python-can/kvaser/send_and_receive_packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ def main():
rx_physical={"can_id": 0x612},
tx_functional={"can_id": 0x6FF},
rx_functional={"can_id": 0x6FE})
ai_send = CanAddressingInformation(
addressing_format=ai_receive.addressing_format,
tx_physical={"can_id": 0x612},
rx_physical={"can_id": 0x611},
tx_functional={"can_id": 0x6FE},
rx_functional={"can_id": 0x6FF})
ai_send = ai_receive.get_other_end()

# create Transport Interface objects for UDS communication
can_ti_1 = PyCanTransportInterface(can_bus_manager=kvaser_interface_1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ async def main():
rx_physical={"can_id": 0x612},
tx_functional={"can_id": 0x6FF},
rx_functional={"can_id": 0x6FE})
ai_send = CanAddressingInformation(
addressing_format=CanAddressingFormat.NORMAL_ADDRESSING,
tx_physical={"can_id": 0x612},
rx_physical={"can_id": 0x611},
tx_functional={"can_id": 0x6FE},
rx_functional={"can_id": 0x6FF})
ai_send = ai_receive.get_other_end()

# create Transport Interface objects for UDS communication
can_ti_1 = PyCanTransportInterface(can_bus_manager=kvaser_interface_1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,11 @@ def test_tx_packets_functional_ai__set(self, value):
self.mock_addressing_information.validate_packet_ai(addressing_type=AddressingType.FUNCTIONAL, **value)
assert self.mock_addressing_information._AbstractCanAddressingInformation__tx_packets_functional_ai \
== self.mock_addressing_information.validate_packet_ai.return_value

# get_other_end

@patch(f"{'.'.join(SCRIPT_LOCATION.split('.')[:-1])}.addressing_information.CanAddressingInformation")
def test_get_other_end(self, mock_can_addressing_information_class):
assert (AbstractCanAddressingInformation.get_other_end(self.mock_addressing_information)
== mock_can_addressing_information_class.return_value)
mock_can_addressing_information_class.assert_called_once()
7 changes: 6 additions & 1 deletion tests/software_tests/can/test_addressing_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,12 @@ class TestCanAddressingInformationIntegration:
"source_address": 0xFF,
"address_extension": 0xA1}}),
])
def test_new(self, input_params, expected_attributes):
def test_new_and_other_end(self, input_params, expected_attributes):
ai = CanAddressingInformation(**input_params)
for attr_name, attr_value in expected_attributes.items():
assert getattr(ai, attr_name) == attr_value
ai_other_end = ai.get_other_end()
assert ai.rx_packets_physical_ai == ai_other_end.tx_packets_physical_ai
assert ai.tx_packets_physical_ai == ai_other_end.rx_packets_physical_ai
assert ai.rx_packets_functional_ai == ai_other_end.tx_packets_functional_ai
assert ai.tx_packets_functional_ai == ai_other_end.rx_packets_functional_ai
325 changes: 222 additions & 103 deletions tests/system_tests/transport_interface/can/python_can/python_can.py

Large diffs are not rendered by default.

18 changes: 1 addition & 17 deletions tests/system_tests/transport_interface/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,7 @@ def example_addressing_information_2nd_node(example_addressing_information) -> A
Values of example_addressing_information and example_addressing_information_2nd_node are compatible, so
these two CAN nodes can communicate with each other over physical and functional addressing.
"""
tx_physical = example_addressing_information.rx_packets_physical_ai
tx_physical.pop("addressing_format")
tx_physical.pop("addressing_type")
rx_physical = example_addressing_information.tx_packets_physical_ai
rx_physical.pop("addressing_format")
rx_physical.pop("addressing_type")
tx_functional = example_addressing_information.rx_packets_functional_ai
tx_functional.pop("addressing_format")
tx_functional.pop("addressing_type")
rx_functional = example_addressing_information.tx_packets_functional_ai
rx_functional.pop("addressing_format")
rx_functional.pop("addressing_type")
return CanAddressingInformation(addressing_format=example_addressing_information.addressing_format,
tx_physical=tx_physical,
rx_physical=rx_physical,
tx_functional=tx_functional,
rx_functional=rx_functional)
return example_addressing_information.get_other_end()


@fixture(params=[
Expand Down
25 changes: 25 additions & 0 deletions uds/can/abstract_addressing_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,31 @@ def tx_packets_functional_ai(self, value: InputAIParamsAlias):
self.__tx_packets_functional_ai: PacketAIParamsAlias \
= self.validate_packet_ai(**{self.ADDRESSING_TYPE_NAME: AddressingType.FUNCTIONAL}, **value)

def get_other_end(self) -> "AbstractCanAddressingInformation":
"""
Get CAN Addressing Information of CAN Entity on the other end.
:return: CAN Addressing Information of a CAN node that this object communicates with.
"""
from .addressing_information import CanAddressingInformation
rx_physical = self.tx_packets_physical_ai
rx_physical.pop("addressing_format")
rx_physical.pop("addressing_type")
tx_physical = self.rx_packets_physical_ai
tx_physical.pop("addressing_format")
tx_physical.pop("addressing_type")
rx_functional = self.tx_packets_functional_ai
rx_functional.pop("addressing_format")
rx_functional.pop("addressing_type")
tx_functional = self.rx_packets_functional_ai
tx_functional.pop("addressing_format")
tx_functional.pop("addressing_type")
return CanAddressingInformation(addressing_format=self.addressing_format,
rx_physical=rx_physical,
tx_physical=tx_physical,
rx_functional=rx_functional,
tx_functional=tx_functional)

@classmethod
@abstractmethod
def validate_packet_ai(cls,
Expand Down

0 comments on commit b833d34

Please sign in to comment.