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
|
from pydantic import BaseModel, ValidationError
|
||||||
|
|
||||||
|
|
||||||
class Interseptor:
|
class ValidationInterseptor:
|
||||||
def __init__(self, model: BaseModel):
|
def __init__(self, model: BaseModel):
|
||||||
self.model = model
|
self.model = model
|
||||||
self.not_valid_rows = []
|
self.not_valid_rows = []
|
||||||
@ -18,8 +18,10 @@ class Interseptor:
|
|||||||
try:
|
try:
|
||||||
self.model(**r)
|
self.model(**r)
|
||||||
except ValidationError:
|
except ValidationError:
|
||||||
r["InterseptorOrigin"] = func.__name__
|
r["ValidationInterseptorFunc"] = func.__name__
|
||||||
r["InterseptorIndex"] = i
|
r["ValidationInterseptorArgs"] = args
|
||||||
|
r["ValidationInterseptorKwrds"] = kwrds
|
||||||
|
r["ValidationInterseptorIndex"] = i
|
||||||
self.not_valid_rows.append(r)
|
self.not_valid_rows.append(r)
|
||||||
else:
|
else:
|
||||||
valid_rows.append(r)
|
valid_rows.append(r)
|
||||||
|
@ -4,7 +4,7 @@ import pandas as pd
|
|||||||
import pytest
|
import pytest
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
from scripts.intersept_not_valid import Interseptor
|
from scripts.intersept_not_valid import ValidationInterseptor
|
||||||
|
|
||||||
|
|
||||||
class FakeModel(BaseModel):
|
class FakeModel(BaseModel):
|
||||||
@ -13,7 +13,7 @@ class FakeModel(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
def test_init_composed():
|
def test_init_composed():
|
||||||
interceptor = Interseptor(FakeModel)
|
interceptor = ValidationInterseptor(FakeModel)
|
||||||
|
|
||||||
def df_generator(nrows=3):
|
def df_generator(nrows=3):
|
||||||
records = [{"name": "plop", "age": random.randint(1, 50)} for _ in range(nrows)]
|
records = [{"name": "plop", "age": random.randint(1, 50)} for _ in range(nrows)]
|
||||||
@ -27,7 +27,7 @@ def test_init_composed():
|
|||||||
|
|
||||||
|
|
||||||
def test_init_decorator():
|
def test_init_decorator():
|
||||||
interceptor = Interseptor(FakeModel)
|
interceptor = ValidationInterseptor(FakeModel)
|
||||||
|
|
||||||
@interceptor
|
@interceptor
|
||||||
def df_generator(nrows=3):
|
def df_generator(nrows=3):
|
||||||
@ -40,7 +40,7 @@ def test_init_decorator():
|
|||||||
|
|
||||||
|
|
||||||
def test_intersept_not_valid():
|
def test_intersept_not_valid():
|
||||||
interceptor = Interseptor(FakeModel)
|
interceptor = ValidationInterseptor(FakeModel)
|
||||||
|
|
||||||
@interceptor
|
@interceptor
|
||||||
def df_generator():
|
def df_generator():
|
||||||
@ -57,7 +57,9 @@ def test_intersept_not_valid():
|
|||||||
{
|
{
|
||||||
"name": "hop",
|
"name": "hop",
|
||||||
"age": "ui",
|
"age": "ui",
|
||||||
"InterseptorOrigin": "df_generator",
|
"ValidationInterseptorFunc": "df_generator",
|
||||||
"InterseptorIndex": 1,
|
"ValidationInterseptorArgs": (),
|
||||||
|
"ValidationInterseptorKwrds": {},
|
||||||
|
"ValidationInterseptorIndex": 1,
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user