mirror of
https://github.com/logos-storage/bittorrent-benchmarks.git
synced 2026-01-04 05:53:12 +00:00
fix: logging for adapted entries should include superclasses
This commit is contained in:
parent
9563a96373
commit
1ab2112542
@ -53,9 +53,11 @@ class LogEntry(SnakeCaseModel):
|
||||
def recover_instance(self):
|
||||
return model.model_validate(self.model_dump())
|
||||
|
||||
parents = [base for base in model.__bases__ if issubclass(base, BaseModel)]
|
||||
|
||||
adapted = type(
|
||||
f"{model.__name__}LogEntry",
|
||||
(LogEntry,),
|
||||
tuple([LogEntry] + parents),
|
||||
{
|
||||
"__annotations__": model.__annotations__,
|
||||
"adapt_instance": classmethod(adapt_instance),
|
||||
|
||||
@ -2,6 +2,8 @@ import datetime
|
||||
from collections import defaultdict
|
||||
from io import StringIO
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from benchmarks.logging.logging import (
|
||||
LogEntry,
|
||||
LogParser,
|
||||
@ -236,3 +238,21 @@ def test_should_store_split_logs_as_jsonl_for_requested_types():
|
||||
{"name":"start2","timestamp":"2021-01-01T00:00:00Z"}
|
||||
""")
|
||||
)
|
||||
|
||||
|
||||
class AModel(BaseModel):
|
||||
a: int
|
||||
|
||||
|
||||
class BModel(AModel):
|
||||
b: int
|
||||
|
||||
|
||||
def test_should_log_attributes_for_superclasses_in_adapted_entries():
|
||||
BModelLogEntry = LogEntry.adapt(BModel)
|
||||
instance = BModel(a=1, b=2)
|
||||
|
||||
assert (
|
||||
str(BModelLogEntry.adapt_instance(instance))
|
||||
== '>>{"a":1,"b":2,"entry_type":"b_model_log_entry"}'
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user