Changeset View
Changeset View
Standalone View
Standalone View
swh/model/tests/test_model.py
Show First 20 Lines • Show All 1,368 Lines • ▼ Show 20 Lines | |||||
@given(strategies.objects(split_content=True)) | @given(strategies.objects(split_content=True)) | ||||
def test_object_type(objtype_and_obj): | def test_object_type(objtype_and_obj): | ||||
obj_type, obj = objtype_and_obj | obj_type, obj = objtype_and_obj | ||||
assert obj_type == obj.object_type | assert obj_type == obj.object_type | ||||
def test_object_type_is_final(): | def test_object_type_is_final(): | ||||
checked_classes = set() | |||||
object_types = set() | object_types = set() | ||||
def check_final(cls): | def check_final(cls): | ||||
if cls in checked_classes: | |||||
return | |||||
checked_classes.add(cls) | |||||
if hasattr(cls, "object_type"): | if hasattr(cls, "object_type"): | ||||
assert cls.object_type not in object_types | assert cls.object_type not in object_types | ||||
object_types.add(cls.object_type) | object_types.add(cls.object_type) | ||||
if cls.__subclasses__(): | if cls.__subclasses__(): | ||||
assert not hasattr(cls, "object_type") | assert not hasattr(cls, "object_type") | ||||
for subcls in cls.__subclasses__(): | for subcls in cls.__subclasses__(): | ||||
check_final(subcls) | check_final(subcls) | ||||
▲ Show 20 Lines • Show All 399 Lines • Show Last 20 Lines |