Test multi-level inheritance of StructMeta subclasses.
()
| 296 | |
| 297 | |
| 298 | def 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 | |
| 335 | def test_struct_meta_subclass_with_encoder(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…