MCPcopy
hub / github.com/python-attrs/attrs / assert_proper_col_class

Method assert_proper_col_class

tests/test_funcs.py:350–375  ·  tests/test_funcs.py::TestAsTuple.assert_proper_col_class
(obj, obj_tuple)

Source from the content-addressed store, hash-verified

348 )
349
350 def assert_proper_col_class(obj, obj_tuple):
351 class="cm"># Iterate over all attributes, and if they are lists or mappings
352 class="cm"># in the original, assert they are the same class in the dumped.
353 for index, field in enumerate(fields(obj.__class__)):
354 field_val = getattr(obj, field.name)
355 if has(field_val.__class__):
356 class="cm"># This field holds a class, recurse the assertions.
357 assert_proper_col_class(field_val, obj_tuple[index])
358 elif isinstance(field_val, (list, tuple)):
359 class="cm"># This field holds a sequence of something.
360 expected_type = type(obj_tuple[index])
361 assert type(field_val) is expected_type
362 for obj_e, obj_tuple_e in zip(field_val, obj_tuple[index]):
363 if has(obj_e.__class__):
364 assert_proper_col_class(obj_e, obj_tuple_e)
365 elif isinstance(field_val, dict):
366 orig = field_val
367 tupled = obj_tuple[index]
368 assert type(orig) is type(tupled)
369 for obj_e, obj_tuple_e in zip(
370 orig.items(), tupled.items()
371 ):
372 if has(obj_e[0].__class__): class="cm"># Dict key
373 assert_proper_col_class(obj_e[0], obj_tuple_e[0])
374 if has(obj_e[1].__class__): class="cm"># Dict value
375 assert_proper_col_class(obj_e[1], obj_tuple_e[1])
376
377 assert_proper_col_class(obj, obj_tuple)
378

Callers

nothing calls this directly

Calls 2

fieldsFunction · 0.90
hasFunction · 0.90

Tested by

no test coverage detected