Skip to content

Commit

Permalink
add more helpers tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lmbsog0 committed Apr 16, 2024
1 parent 41020d6 commit a9a6d5d
Show file tree
Hide file tree
Showing 5 changed files with 301 additions and 109 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
run: |
python -m pip install --upgrade pip
# see https://github.com/pytest-dev/pytest/issues/11868
pip install codecov dictdiffer grpcio-tools mktestdocs mock pytest==7.4.3 pytest-cases pytest-cov
pip install codecov dictdiffer grpcio-tools mktestdocs mock pytest pytest-cases pytest-cov pytest-xdist
wget https://github.com/Sauci/a2l-grpc/releases/download/v0.1.16/a2l_grpc.tar.gz
tar -xf a2l_grpc.tar.gz -C pya2l
- uses: actions/download-artifact@v4
Expand All @@ -49,7 +49,7 @@ jobs:
path: pya2l/protobuf
- name: Test with pytest
run: |
pytest --cov-report html --cov pya2l --verbose
pytest -n 1 --cov-report html --cov pya2l --verbose
codecov
run-pytest-test-windows:
runs-on: windows-2019
Expand All @@ -67,7 +67,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install codecov dictdiffer grpcio-tools mktestdocs mock pytest pytest-cases pytest-cov
pip install codecov dictdiffer grpcio-tools mktestdocs mock pytest pytest-cases pytest-cov pytest-xdist
powershell.exe -Command "Invoke-WebRequest -OutFile ./a2l_grpc.tar.gz https://github.com/Sauci/a2l-grpc/releases/download/v0.1.16/a2l_grpc.tar.gz"
tar -xf a2l_grpc.tar.gz -C pya2l
- uses: actions/download-artifact@v4
Expand All @@ -76,7 +76,7 @@ jobs:
path: pya2l/protobuf
- name: Test with pytest
run: |
pytest --cov-report html --cov pya2l --verbose
pytest -n 1 --cov-report html --cov pya2l --verbose
codecov
build-distribution:
runs-on: ubuntu-22.04
Expand Down
33 changes: 26 additions & 7 deletions pya2l/helpers/axis_descr.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import typing

from pya2l.protobuf.A2L_pb2 import AxisDescrType
from .axis_pts import AxisPts
from .compu_method import CompuMethod, compu_method_factory
Expand All @@ -16,15 +18,17 @@ def axis_pts(self) -> AxisPts:
for axis_pts in self._module.a2l_module.AXIS_PTS:
if axis_pts.Name.Value == axis_pts_ref:
return AxisPts(self._module, axis_pts)
raise ValueError(f'AXIS_PTS {axis_pts_ref} not found in MODULE {self._module.name}')
raise ValueError(f'AXIS_PTS <{axis_pts_ref}> not found in MODULE <{self._module.name}>')

@property
def conversion(self) -> CompuMethod:
def conversion(self) -> typing.Union[CompuMethod, None]:
conversion = self._axis_descr.Conversion.Value
if conversion == 'NO_COMPU_METHOD':
return None
for compu_method in self._module.a2l_module.COMPU_METHOD:
if compu_method.Name.Value == conversion:
return compu_method_factory(self._module, compu_method)
raise ValueError(f'COMPU_METHOD {conversion} not found in MODULE {self._module.name}')
raise ValueError(f'COMPU_METHOD <{conversion}> not found in MODULE <{self._module.name}>')

@property
def xcp_data_size(self) -> int:
Expand All @@ -38,22 +42,37 @@ def xcp_data_size(self) -> int:


class AxisDescrStd(AxisDescr):
pass

@property
def xcp_data_size(self) -> int:
return self._axis_descr.MaxAxisPoints.Value


class AxisDescrFix(AxisDescr):
pass

@property
def xcp_data_size(self) -> int:
if not self._axis_descr.FIX_AXIS_PAR.is_none:
return self._axis_descr.FIX_AXIS_PAR.Numberapo.Value
elif not self._axis_descr.FIX_AXIS_PAR_DIST.is_none:
return self._axis_descr.FIX_AXIS_PAR_DIST.Numberapo.Value
elif not self._axis_descr.FIX_AXIS_PAR_LIST.is_none:
return len(self._axis_descr.FIX_AXIS_PAR_LIST.AxisPtsValue)
raise ValueError(f'AXIS_DESCR malformed')


class AxisDescrCom(AxisDescr):
class AxisDescrCom(AxisDescrStd):

@property
def xcp_data_size(self) -> int:
return self.axis_pts.max_axis_points


class AxisDescrRes(AxisDescr):
pass

@property
def xcp_data_size(self) -> int:
return self.axis_pts.max_axis_points


class AxisDescrCurve(AxisDescr):
Expand Down
10 changes: 10 additions & 0 deletions pya2l/helpers/axis_pts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .module import Module
from .record_layout import RecordLayout
from .referencer import Referencer
from .helpers import *


class AxisPts(Referencer):
Expand Down Expand Up @@ -38,6 +39,15 @@ def get_raw_values(self, data: bytearray) -> typing.Tuple[typing.Any, ...]:
"""
return struct.unpack(self.unpack_format, data)

@property
def protocol_data_size(self) -> int:
"""
Returns the XCP data size in bytes of this AXIS_PTS.
:return: the XCP data size of this AXIS_PTS
"""
return get_byte_size_from_unpack_format(self.unpack_format)

def get_physical_values(self, data: typing.Tuple[typing.Any, ...]) -> typing.Tuple[typing.Any, ...]:
data = [d for i, d in enumerate(data) if
self.record_layout.get_meta_data_indexes(self.max_axis_points)[i] == 'n']
Expand Down
17 changes: 14 additions & 3 deletions pya2l/helpers/characteristic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .compu_method import CompuMethod, compu_method_factory
from .record_layout import *
from .referencer import Referencer
from .helpers import *


class Characteristic(Referencer):
Expand All @@ -17,11 +18,11 @@ def __init__(self, module: Module, name: str):
@property
def _a2l_characteristic(self) -> CharacteristicType:
if self._characteristic is None:
self._characteristic = self.get_a2l_characteristic_from_module(self._module, self._name)
self._characteristic = self.get_ast_characteristic_from_module(self._module, self._name)
return self._characteristic

@staticmethod
def get_a2l_characteristic_from_module(module: Module, name: str) -> CharacteristicType:
def get_ast_characteristic_from_module(module: Module, name: str) -> CharacteristicType:
"""
Returns the CHARACTERISTIC with the specified name, in the scope of the specified module.
Expand Down Expand Up @@ -88,6 +89,16 @@ def data_size(self) -> int:
"""
raise NotImplementedError

@property
def protocol_data_size(self) -> int:
"""
Returns the XCP data size in bytes of this CHARACTERISTIC. This value includes elements such as NO_AXIS_PTS_X/Y/
Z.
:return: the XCP data size of this CHARACTERISTIC
"""
return get_byte_size_from_unpack_format(self.unpack_format)

@property
def unpack_format(self) -> str:
"""
Expand Down Expand Up @@ -167,7 +178,7 @@ class CharacteristicAscii(Characteristic):


def characteristic_factory(module: Module, name: str) -> Characteristic:
characteristic = Characteristic.get_a2l_characteristic_from_module(module, name)
characteristic = Characteristic.get_ast_characteristic_from_module(module, name)
return dict(VALUE=CharacteristicValue,
CURVE=CharacteristicCurve,
MAP=CharacteristicMap,
Expand Down
Loading

0 comments on commit a9a6d5d

Please sign in to comment.