Repository: bo4e/BO4E-python (language: python)

Issue:
Implement COM Kriteriumwert
https://www.bo4e.de/dokumentation/komponenten/com-kriteriumwert
requires
- #137 


Discussion / hints:

Fix patch:
diff --git a/src/bo4e/com/kriteriumwert.py b/src/bo4e/com/kriteriumwert.py
new file mode 100644
index 000000000..58a9e2108
--- /dev/null
+++ b/src/bo4e/com/kriteriumwert.py
@@ -0,0 +1,42 @@
+"""
+Contains KriteriumWert class
+and corresponding marshmallow schema for de-/serialization
+"""
+
+import attr
+from marshmallow import fields, post_load
+from marshmallow_enum import EnumField  # type:ignore[import]
+
+from bo4e.com.com import COM, COMSchema
+
+# pylint: disable=too-few-public-methods
+from bo4e.enum.tarifregionskriterium import Tarifregionskriterium
+
+
+@attr.s(auto_attribs=True, kw_only=True)
+class KriteriumWert(COM):
+    """
+    Mit dieser Komponente können Kriterien und deren Werte definiert werden
+    """
+
+    # required attributes
+    #: Hier steht, für welches Kriterium der Wert gilt. Z.B. Postleitzahlen
+    kriterium: Tarifregionskriterium = attr.ib(validator=attr.validators.instance_of(Tarifregionskriterium))
+    #: Ein Wert, passend zum Kriterium. Z.B. eine Postleitzahl.
+    wert: str = attr.ib(validator=attr.validators.instance_of(str))
+
+
+class KriteriumWertSchema(COMSchema):
+    """
+    Schema for de-/serialization of KriteriumWert.
+    """
+
+    # required attributes
+    kriterium = EnumField(Tarifregionskriterium)
+    wert = fields.Str()
+
+    # pylint: disable=no-self-use, unused-argument
+    @post_load
+    def deserialize(self, data, **kwargs) -> KriteriumWert:
+        """Deserialize JSON to KriteriumWert object"""
+        return KriteriumWert(**data)


Test patch:
diff --git a/tests/test_kriteriumswert.py b/tests/test_kriteriumswert.py
new file mode 100644
index 000000000..508b61bbe
--- /dev/null
+++ b/tests/test_kriteriumswert.py
@@ -0,0 +1,30 @@
+import pytest  # type:ignore[import]
+
+from bo4e.com.kriteriumwert import KriteriumWert, KriteriumWertSchema
+from bo4e.enum.tarifregionskriterium import Tarifregionskriterium
+from tests.serialization_helper import assert_serialization_roundtrip  # type:ignore[import]
+
+
+class TestKriteriumWert:
+    @pytest.mark.parametrize(
+        "kriteriumwert, expected_json_dict",
+        [
+            pytest.param(
+                KriteriumWert(
+                    kriterium=Tarifregionskriterium.ORT,
+                    wert="Grünwald",
+                ),
+                {"kriterium": "ORT", "wert": "Grünwald"},
+            ),
+        ],
+    )
+    def test_kriteriumwert_serialization_roundtrip(self, kriteriumwert: KriteriumWert, expected_json_dict: dict):
+        """
+        Test de-/serialisation of KriteriumWert with minimal attributes.
+        """
+        assert_serialization_roundtrip(kriteriumwert, KriteriumWertSchema(), expected_json_dict)
+
+    def test_kriteriumwert_missing_required_attribute(self):
+        with pytest.raises(TypeError) as excinfo:
+            _ = KriteriumWert()
+        assert "missing 2 required" in str(excinfo.value)