diff --git a/scripts/intersept_not_valid.py b/scripts/intersept_not_valid.py index db0b41f..458ab14 100644 --- a/scripts/intersept_not_valid.py +++ b/scripts/intersept_not_valid.py @@ -4,7 +4,7 @@ import pandas as pd from pydantic import BaseModel, ValidationError -class Interseptor: +class ValidationInterseptor: def __init__(self, model: BaseModel): self.model = model self.not_valid_rows = [] @@ -18,8 +18,10 @@ class Interseptor: try: self.model(**r) except ValidationError: - r["InterseptorOrigin"] = func.__name__ - r["InterseptorIndex"] = i + r["ValidationInterseptorFunc"] = func.__name__ + r["ValidationInterseptorArgs"] = args + r["ValidationInterseptorKwrds"] = kwrds + r["ValidationInterseptorIndex"] = i self.not_valid_rows.append(r) else: valid_rows.append(r) diff --git a/tests/test_intersept_not_valid.py b/tests/test_intersept_not_valid.py index d91098c..d0e0613 100644 --- a/tests/test_intersept_not_valid.py +++ b/tests/test_intersept_not_valid.py @@ -4,7 +4,7 @@ import pandas as pd import pytest from pydantic import BaseModel -from scripts.intersept_not_valid import Interseptor +from scripts.intersept_not_valid import ValidationInterseptor class FakeModel(BaseModel): @@ -13,7 +13,7 @@ class FakeModel(BaseModel): def test_init_composed(): - interceptor = Interseptor(FakeModel) + interceptor = ValidationInterseptor(FakeModel) def df_generator(nrows=3): records = [{"name": "plop", "age": random.randint(1, 50)} for _ in range(nrows)] @@ -27,7 +27,7 @@ def test_init_composed(): def test_init_decorator(): - interceptor = Interseptor(FakeModel) + interceptor = ValidationInterseptor(FakeModel) @interceptor def df_generator(nrows=3): @@ -40,7 +40,7 @@ def test_init_decorator(): def test_intersept_not_valid(): - interceptor = Interseptor(FakeModel) + interceptor = ValidationInterseptor(FakeModel) @interceptor def df_generator(): @@ -57,7 +57,9 @@ def test_intersept_not_valid(): { "name": "hop", "age": "ui", - "InterseptorOrigin": "df_generator", - "InterseptorIndex": 1, + "ValidationInterseptorFunc": "df_generator", + "ValidationInterseptorArgs": (), + "ValidationInterseptorKwrds": {}, + "ValidationInterseptorIndex": 1, } ]