Skip to content

Commit

Permalink
add more tests for Module
Browse files Browse the repository at this point in the history
  • Loading branch information
zariiii9003 committed Oct 26, 2023
1 parent e1286e4 commit 35607b8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/pycanape/module.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-FileCopyrightText: 2022-present Artur Drogunow <[email protected]>
#
# SPDX-License-Identifier: MIT

import copy
import ctypes
import fnmatch
import os.path
Expand Down Expand Up @@ -187,10 +187,12 @@ def get_database_objects(self) -> List[str]:
TAsap3DBOType.DBTYPE_ALL,
)
self._objects_cache = (
buffer.value.strip(b";").decode(RC["ENCODING"]).split(";")
buffer.value.strip(b";")[: max_size.value]
.decode(RC["ENCODING"])
.split(";")
)

return self._objects_cache
return copy.copy(self._objects_cache)

def get_ecu_tasks(self) -> Dict[str, EcuTask]:
"""Get available data acquisition tasks.
Expand Down Expand Up @@ -224,13 +226,14 @@ def get_task_instance(task_info: TTaskInfo2) -> EcuTask:
def get_network_name(self) -> str:
"""Receives the name of the used network."""
c_name = ctypes.create_string_buffer(256)
size = ctypes.c_uint()
self._dll.Asap3GetNetworkName(
self.asap3_handle,
self.module_handle,
ctypes.cast(ctypes.byref(c_name), ctypes.c_char_p),
ctypes.byref(ctypes.c_uint()),
ctypes.byref(size),
)
return c_name.value.decode(RC["ENCODING"])
return c_name.value[: size.value].decode(RC["ENCODING"])

def get_ecu_driver_type(self) -> DriverType:
"""Retrieves the drivertype of an ECU.
Expand Down
31 changes: 30 additions & 1 deletion tests/test_canape.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def test_get_module(empty_canape):


@pytest.mark.skipif(not XCPSIM_FOUND, reason="CANape example project not found")
def test_get_database_info(empty_canape):
def test_module_methods(empty_canape):
canape = empty_canape
module = canape.create_module(
module_name="XCPsim",
Expand All @@ -178,6 +178,35 @@ def test_get_database_info(empty_canape):
database_objects = module.get_database_objects()
assert len(database_objects) > 1000

assert module.is_module_active()
module.module_activation(False)
assert not module.is_module_active()
module.module_activation(True)
assert module.is_module_active()

assert module.is_ecu_online()
module.switch_ecu_on_offline(False)
assert not module.is_ecu_online()
module.switch_ecu_on_offline(True)
assert module.is_ecu_online()

assert module.get_communication_type() == "XCP"
ecu_tasks = module.get_ecu_tasks()
assert isinstance(ecu_tasks, dict)
assert len(ecu_tasks) == 7
assert all(isinstance(x, pycanape.EcuTask) for x in ecu_tasks.values())

assert module.get_network_name() == "CAN_Network"
assert module.has_resume_mode()

module.reset_data_acquisition_channels_by_module()
assert module.get_measurement_list_entries() == {}

script = module.execute_script_ex(script_file=False, script='printf("Hello");')
assert isinstance(script, pycanape.Script)

module.release_module()


@pytest.mark.skipif(not XCPSIM_FOUND, reason="CANape example project not found")
def test_get_calibration_object(empty_canape):
Expand Down

0 comments on commit 35607b8

Please sign in to comment.