Skip to content

Commit

Permalink
Load maus_version default in AhbMetaInformation (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
hf-kklein authored Jan 4, 2023
1 parent 10211e5 commit 52d4240
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
4 changes: 1 addition & 3 deletions src/maus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from itertools import groupby
from typing import List, Sequence

from maus.models.anwendungshandbuch import AhbLine, DeepAnwendungshandbuch, FlatAnwendungshandbuch
from maus.models.anwendungshandbuch import _VERSION, AhbLine, DeepAnwendungshandbuch, FlatAnwendungshandbuch
from maus.models.edifact_components import (
DataElement,
DataElementFreeText,
Expand All @@ -17,8 +17,6 @@
)
from maus.models.message_implementation_guide import SegmentGroupHierarchy

_VERSION = "0.2.4" #: version to be writen into the deep ahb


def merge_lines_with_same_data_element(ahb_lines: Sequence[AhbLine]) -> DataElement:
"""
Expand Down
11 changes: 5 additions & 6 deletions src/maus/models/anwendungshandbuch.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
SegmentGroupSchema,
)

_VERSION = "0.2.8" #: version to be written into the deep ahb


# pylint:disable=too-many-instance-attributes
@attrs.define(auto_attribs=True, kw_only=True)
Expand Down Expand Up @@ -53,7 +55,7 @@ class AhbLine:
""" the data element ID, e.g. '3224' """

value_pool_entry: Optional[str] = attrs.field(
validator=attrs.validators.optional(validator=attrs.validators.instance_of(str))
validator=attrs.validators.optional(attrs.validators.instance_of(str))
)
""" one of (possible multiple) allowed values, e.g. 'E01' or '293' """

Expand Down Expand Up @@ -150,10 +152,7 @@ class AhbMetaInformation:

pruefidentifikator: str #: identifies the message type (within a fixed format version) e.g. "11042" or "13012"
# there's more to come but for now we'll leave it as is, because we're just in a proof of concept phase
maus_version: Optional[str] = attrs.field(
validator=attrs.validators.optional(attrs.validators.optional(_check_that_string_is_not_whitespace_or_empty)),
default=None,
)
maus_version: Optional[str] = attrs.field(validator=attrs.validators.instance_of(str), default=_VERSION)
"""
semantic version of maus used to create this document
"""
Expand All @@ -165,7 +164,7 @@ class AhbMetaInformationSchema(Schema):
"""

pruefidentifikator = fields.String(required=True)
maus_version = fields.String(required=False)
maus_version = fields.String(required=False, allow_none=True, default=_VERSION)

# pylint:disable=unused-argument
@post_load
Expand Down
5 changes: 3 additions & 2 deletions src/maus/reader/flat_ahb_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pathlib import Path
from typing import Dict, List, Literal, Optional, Sequence, Set, TextIO, Tuple, overload

from maus.models.anwendungshandbuch import AhbLine, AhbMetaInformation, FlatAnwendungshandbuch
from maus.models.anwendungshandbuch import _VERSION, AhbLine, AhbMetaInformation, FlatAnwendungshandbuch
from maus.models.edifact_components import gabi_edifact_qualifier_pattern

_pruefi_pattern = re.compile(r"^\d{5}$") #: five digits
Expand Down Expand Up @@ -265,7 +265,8 @@ def to_flat_ahb(self) -> FlatAnwendungshandbuch:
"""
return FlatAnwendungshandbuch(
meta=AhbMetaInformation(
pruefidentifikator=self.pruefidentifikator # type:ignore[arg-type]
pruefidentifikator=self.pruefidentifikator, # type:ignore[arg-type]
maus_version=_VERSION,
),
lines=[row for row in self.rows if row.holds_any_information()],
)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/edifact-templates
2 changes: 1 addition & 1 deletion tests/unit_tests/example_data_11042.py
Original file line number Diff line number Diff line change
Expand Up @@ -29063,6 +29063,6 @@
]

example_flat_ahb_11042 = FlatAnwendungshandbuch(
meta=AhbMetaInformation(pruefidentifikator="11042", maus_version=None),
meta=AhbMetaInformation(pruefidentifikator="11042"),
lines=[x[0] for x in lines_locations_changes_11042],
)
10 changes: 8 additions & 2 deletions tests/unit_tests/test_maus.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
from unit_tests.serialization_test_helper import assert_serialization_roundtrip # type:ignore[import]

from maus import group_lines_by_segment_group, merge_lines_with_same_data_element, to_deep_ahb
from maus.models.anwendungshandbuch import AhbLine, AhbMetaInformation, DeepAnwendungshandbuch, FlatAnwendungshandbuch
from maus.models.anwendungshandbuch import (
_VERSION,
AhbLine,
AhbMetaInformation,
DeepAnwendungshandbuch,
FlatAnwendungshandbuch,
)
from maus.models.edifact_components import (
DataElement,
DataElementFreeText,
Expand Down Expand Up @@ -413,7 +419,7 @@ def test_group_lines_by_segment_group(
],
),
DeepAnwendungshandbuch(
meta=AhbMetaInformation(pruefidentifikator="12345", maus_version="0.2.4"),
meta=AhbMetaInformation(pruefidentifikator="12345", maus_version=_VERSION),
lines=[
SegmentGroup(
discriminator="root",
Expand Down

0 comments on commit 52d4240

Please sign in to comment.