Skip to content

Commit

Permalink
fix mypy and unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Lauser <andreas.lauser@mbition.io>
Signed-off-by: Alexander Walz <alexander.walz@mbition.io>
  • Loading branch information
andlaus committed Dec 1, 2022
1 parent c36a2b1 commit f1bf503
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 30 deletions.
3 changes: 2 additions & 1 deletion odxtools/admindata.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _resolve_references(self, odxlinks: OdxLinkDatabase):
@dataclass()
class AdminData:
language: Optional[str] = None
company_doc_infos: List[CompanyDocInfo] = None
company_doc_infos: List[CompanyDocInfo] = field(default_factory=list)
doc_revisions: Optional[List[DocRevision]] = None

def _build_odxlinks(self) -> Dict[OdxLinkId, Any]:
Expand Down Expand Up @@ -120,6 +120,7 @@ def read_admin_data_from_odx(et_element: Optional[ElementTree.Element],
revision_label = dr.findtext("REVISION-LABEL")
state = dr.findtext("STATE")
date = dr.findtext("DATE")
assert date is not None
tool = dr.findtext("TOOL")

modlist = None
Expand Down
4 changes: 2 additions & 2 deletions odxtools/endofpdufield.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ def convert_bytes_to_physical(self, decode_state: DecodeState, bit_position: int

return value, next_byte_position

def _resolve_references(self,
def _resolve_references(self, # type: ignore[override]
parent_dl: "DiagLayer",
odxlinks: OdxLinkDatabase) \
-> None:
-> None:
"""Recursively resolve any references (odxlinks or sn-refs)
"""
if self.structure_ref is not None:
Expand Down
12 changes: 8 additions & 4 deletions odxtools/envdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (c) 2022 MBition GmbH

from dataclasses import dataclass
from typing import Optional, Any, Dict, List
from typing import TYPE_CHECKING, Optional, Any, Dict, List

from .parameters import read_parameter_from_odx
from .utils import read_description_from_odx
Expand All @@ -11,6 +11,9 @@
from .parameters.parameterbase import Parameter
from .globals import logger

if TYPE_CHECKING:
from .diaglayer import DiagLayer

@dataclass
class EnvironmentData(BasicStructure):
"""This class represents Environment Data that describes the circumstances in which the error occurred."""
Expand All @@ -36,10 +39,11 @@ def _build_odxlinks(self) -> Dict[OdxLinkId, Any]:

return odxlinks

def _resolve_references(self,
def _resolve_references(self, # type: ignore[override]
parent_dl: "DiagLayer",
odxlinks: OdxLinkDatabase) -> None:
odxlinks = super()._resolve_references(parent_dl, odxlinks)
odxlinks: OdxLinkDatabase) \
-> None:
super()._resolve_references(parent_dl, odxlinks)

def __repr__(self) -> str:
return (
Expand Down
27 changes: 12 additions & 15 deletions odxtools/specialdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _resolve_references(self, odxlinks: OdxLinkDatabase) -> None:
@staticmethod
def from_et(et_element: ElementTree.Element,
doc_frags: List[OdxDocFragment]) \
-> SpecialDataGroupCaption:
-> "SpecialData":
semantic_info = et_element.get("SI")
text_identifier = et_element.get("TI")
value = et_element.text or ""
Expand All @@ -67,16 +67,15 @@ def from_et(et_element: ElementTree.Element,

@dataclass
class SpecialDataGroup:
_local_sdg_caption: Optional[SpecialDataGroupCaption]
_sdg_caption_ref: Optional[OdxLinkRef]

sdg_caption: Optional[SpecialDataGroupCaption]
sdg_caption_ref: Optional[OdxLinkRef]
semantic_info: Optional[str] # the "SI" attribute
values: List[Union["SpecialDataGroup", SpecialData]]

@staticmethod
def from_et(et_element: ElementTree.Element,
doc_frags: List[OdxDocFragment]) \
-> SpecialDataGroupCaption:
-> "SpecialDataGroup":
sdg_caption = None
if caption_elem := et_element.find("SDG-CAPTION"):
sdg_caption = SpecialDataGroupCaption.from_et(caption_elem, doc_frags)
Expand All @@ -87,9 +86,9 @@ def from_et(et_element: ElementTree.Element,

semantic_info = et_element.get("SI")

values = []
values: List[Union[SpecialData, SpecialDataGroup]] = []
for value_elem in et_element:
next_entry = None
next_entry: Optional[Union[SpecialData, SpecialDataGroup]] = None
if value_elem.tag == "SDG":
next_entry = SpecialDataGroup.from_et(value_elem, doc_frags)
elif value_elem.tag == "SD":
Expand All @@ -98,29 +97,27 @@ def from_et(et_element: ElementTree.Element,
if next_entry is not None:
values.append(next_entry)

return SpecialDataGroup(_local_sdg_caption=sdg_caption,
_sdg_caption_ref=sdg_caption_ref,
return SpecialDataGroup(sdg_caption=sdg_caption,
sdg_caption_ref=sdg_caption_ref,
semantic_info=semantic_info,
values=values)

def _build_odxlinks(self) -> Dict[OdxLinkId, Any]:
result = {}

if self._local_sdg_caption is not None:
result.update(self._local_sdg_caption._build_odxlinks())
if self.sdg_caption is not None:
result.update(self.sdg_caption._build_odxlinks())

for val in self.values:
result.update(val._build_odxlinks())

return result

def _resolve_references(self, odxlinks: OdxLinkDatabase) -> None:
if self._sdg_caption_ref is not None:
caption = odxlinks.resolve(self._sdg_caption_ref)
if self.sdg_caption_ref is not None:
caption = odxlinks.resolve(self.sdg_caption_ref)
assert isinstance(caption, SpecialDataGroupCaption)
self.sdg_caption = caption
else:
self.sdg_caption = self._local_sdg_caption

for val in self.values:
val._resolve_references(odxlinks)
Expand Down
5 changes: 3 additions & 2 deletions odxtools/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,10 @@ def _build_odxlinks(self):

return result

def _resolve_references(self,
def _resolve_references(self, # type: ignore[override]
parent_dl: "DiagLayer",
odxlinks: OdxLinkDatabase):
odxlinks: OdxLinkDatabase) \
-> None:
"""Recursively resolve any references (odxlinks or sn-refs)
"""
super()._resolve_references(odxlinks)
Expand Down
1 change: 0 additions & 1 deletion odxtools/templates/macros/printSingleEcuJob.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
{%- endif %}
{%- endfilter -%}
>

{{ peid.printElementID(job)|indent(1) }}
{{- psd.printSpecialDataGroups(job.sdgs)|indent(1, first=True) }}
{%- if job.functional_class_refs %}
Expand Down
9 changes: 4 additions & 5 deletions odxtools/templates/macros/printSpecialData.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@
SI="{{sdg.semantic_info}}"
{%- endif %}
{#- -#}>
{%- if sdg._local_sdg_caption %}
{{- printSdgCaption(sdg._local_sdg_caption) | indent(1, first=True) }}
{%- endif %}
{%- if sdg._sdg_caption_ref %}
<SDG-CAPTION-REF ID-REF="{{sdg._sdg_caption_ref.ref_id}}" />
{%- if sdg.sdg_caption_ref %}
<SDG-CAPTION-REF ID-REF="{{sdg.sdg_caption_ref.ref_id}}" />
{%- elif sdg.sdg_caption %}
{{- printSdgCaption(sdg.sdg_caption) | indent(1, first=True) }}
{%- endif %}
{%- for sd in sdg.values %}
{%- if hasattr(sd, "values") %}
Expand Down

0 comments on commit f1bf503

Please sign in to comment.