MCPcopy Index your code
hub / github.com/msgspec/msgspec / test_struct_meta_subclass_inheritance

Function test_struct_meta_subclass_inheritance

tests/unit/test_struct_meta.py:298–332  ·  view source on GitHub ↗

Test multi-level inheritance of StructMeta subclasses.

()

Source from the content-addressed store, hash-verified

296
297
298def test_struct_meta_subclass_inheritance():
299 """Test multi-level inheritance of StructMeta subclasses."""
300
301 # Define the first level custom metaclass
302 class BaseMeta(StructMeta):
303 """Base custom metaclass"""
304
305 # Define the second level custom metaclass
306 class DerivedMeta(BaseMeta):
307 """Derived custom metaclass"""
308
309 # Use the second level custom metaclass to create a struct class
310 class DerivedStruct(metaclass=DerivedMeta):
311 a: int
312 b: str
313
314 # Create an instance
315 obj = DerivedStruct(a=42, b="derived")
316 assert obj.a == 42
317 assert obj.b == "derived"
318
319 # Test various functions
320 # asdict
321 d = asdict(obj)
322 assert d["a"] == 42
323 assert d["b"] == "derived"
324
325 # astuple
326 t = astuple(obj)
327 assert t == (42, "derived")
328
329 # replace
330 obj2 = replace(obj, a=99)
331 assert obj2.a == 99
332 assert obj2.b == "derived"
333
334
335def test_struct_meta_subclass_with_encoder():

Callers

nothing calls this directly

Calls 2

DerivedStructClass · 0.85
replaceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…