Skip to content

Commit

Permalink
✔ Add test case for missing cross reference support (FV2310 E_0462) (
Browse files Browse the repository at this point in the history
  • Loading branch information
hf-kklein authored Jul 19, 2023
1 parent e537a72 commit d7b8add
Show file tree
Hide file tree
Showing 4 changed files with 408 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ebdtable2graph/graph_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
ToNoEdge,
ToYesEdge,
)
from ebdtable2graph.models.errors import EbdCrossReferenceNotSupportedError, OutcomeNodeCreationError


def _convert_sub_row_to_outcome_node(sub_row: EbdTableSubRow) -> Optional[OutcomeNode]:
Expand Down Expand Up @@ -90,7 +91,10 @@ def get_all_edges(table: EbdTable) -> List[EbdGraphEdge]:
)
else:
outcome_node: Optional[OutcomeNode] = _convert_sub_row_to_outcome_node(sub_row)
assert outcome_node is not None
if outcome_node is None:
if all(sr.result_code is None for sr in row.sub_rows):
raise EbdCrossReferenceNotSupportedError(row=row, decision_node=decision_node)
raise OutcomeNodeCreationError(decision_node=decision_node, sub_row=sub_row)
edge = _yes_no_edge(
sub_row.check_result.result,
source=decision_node,
Expand Down
34 changes: 34 additions & 0 deletions src/ebdtable2graph/models/errors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
Specific error classes for errors that may occur in the data.
Using these exceptions allows to catch/filter more fine-grained.
"""
from typing import Optional

from ebdtable2graph.models import DecisionNode, EbdTableRow, EbdTableSubRow


class NotExactlyTwoOutgoingEdgesError(NotImplementedError):
Expand Down Expand Up @@ -63,3 +66,34 @@ def __init__(
):
self.message = message
super().__init__(self.message)


class EbdCrossReferenceNotSupportedError(NotImplementedError):
"""
Raised when there is no outcome for a given sub row but a reference to another EBD key instead.
See https://github.com/Hochfrequenz/ebdtable2graph/issues/105 for an example / a discussion.
"""

def __init__(self, decision_node: DecisionNode, row: EbdTableRow):
cross_reference: Optional[str] = None
for sub_row in row.sub_rows:
if sub_row.note is not None and sub_row.note.startswith("EBD "):
cross_reference = sub_row.note.split(" ")[1]
break
super().__init__(
f"A cross reference from row {row} to {cross_reference} has been detected but is not supported"
)
self.row = row
self.cross_reference = cross_reference
self.decision_node = decision_node


class OutcomeNodeCreationError(ValueError):
"""
raised when the outcome node cannot be created from a sub row
"""

def __init__(self, decision_node: DecisionNode, sub_row: EbdTableSubRow):
super().__init__(f"Cannot create outcome node from sub row {sub_row} for DecisionNode {decision_node}.")
self.sub_row = sub_row
self.decision_node = decision_node
Loading

0 comments on commit d7b8add

Please sign in to comment.