Feat: add ARgs and kwrds when intersepted
This commit is contained in:
parent
2f77206b8f
commit
b62ea3f5ae
@ -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)
|
||||
|
@ -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,
|
||||
}
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user