Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logging format is improved #8

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions akm_tools/validation/custom_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
from typing import Dict, List

from deepdiff import DeepDiff
import json

class IDConflictException(Exception):
def __init__(self, instances: List[Dict]):
err_msg = f"More than 2 instances with same ID ! \n{instances}\n"
err_msg = f"More than 2 instances with same ID ! \n{json.dumps(instances,indent=2)}\n"
super().__init__(err_msg)
self.message = err_msg


class BaseInstanceOverwiteException(Exception):
def __init__(self, base_instance, extended_instance):
def __init__(self, base_instance: dict, extended_instance: dict):
diff = DeepDiff(base_instance, extended_instance, ignore_order=True)
err_msg = (
f"The extended instance :\n{extended_instance}\nis overwriting properties of base instance\n{base_instance}\n"
f"Issue with {base_instance['id']}\nThe extended instance is overwriting properties of base instance:\n{diff.pretty()}\n"
)
super().__init__(err_msg)
self.message = err_msg


class InvalidReferentIDException(Exception):
def __init__(self, instance, referentID):
err_msg = f"The instance :\n{instance}\nis referencing an invalid id : '{referentID}'\n"
def __init__(self, instance : dict, referentID):
err_msg = f"The instance :\n{json.dumps(instance,indent=2)}\nis referencing an invalid id : '{referentID}'\n"
super().__init__(err_msg)
self.message = err_msg
34 changes: 33 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ python = "^3.10"
PyYAML = "*"
jsonschema = "*"
black = "^24.2.0"
deepdiff = "^7.0.1"


[tool.poetry.group.dev.dependencies]
Expand Down
6 changes: 0 additions & 6 deletions tests/test_custom_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def test_IDConflictException():
instances = [{"id": 1}, {"id": 1}, {"id": 1}]
with pytest.raises(IDConflictException) as excinfo:
raise IDConflictException(instances)
assert str(excinfo.value) == f"More than 2 instances with same ID ! \n{instances}\n"


def test_BaseInstanceOverwiteException():
Expand All @@ -24,10 +23,6 @@ def test_BaseInstanceOverwiteException():
extended_instance = {"id": "data_instance2", "name": "test"}
with pytest.raises(BaseInstanceOverwiteException) as excinfo:
raise BaseInstanceOverwiteException(base_instance, extended_instance)
assert (
str(excinfo.value)
== f"The extended instance :\n{extended_instance}\nis overwriting properties of base instance\n{base_instance}\n"
)


def test_InvalidReferentIDException():
Expand All @@ -38,4 +33,3 @@ def test_InvalidReferentIDException():
referentID_value = instance["isA"]["referentID"]
with pytest.raises(InvalidReferentIDException) as excinfo:
raise InvalidReferentIDException(instance, referentID_value)
assert str(excinfo.value) == f"The instance :\n{instance}\nis referencing an invalid id : '{referentID_value}'\n"