def __init_subclass__(cls): try: slug = cls.model_slug except AttributeError: slug = re.sub('([A-Z])', r'-\1', cls.__name__).lower().lstrip('-') cls.model_slug = slug models[slug] = cls if not hasattr(cls, '_naucse__converter'): converter = ModelConverter( cls, load_arg_names=cls.init_arg_names, slug=slug, extra_fields=[ Field( URLConverter(), name='_url', data_key='url', input=False, optional=True, doc="URL for a user-facing page on naucse", ) ], ) converter.get_schema_url = _get_schema_url register_model(cls, converter)
class TestModel: versioned_field = VersionField({ # (Versions are out of order to test that VersionField sorts them) (0, 1): Field(str, optional=True, doc='Introducing new field'), (1, 0): Field(int, optional=True, doc="Let's make it an int"), (0, 5): Field(bool, optional=True, doc="Actually it's a bool"), (2, 0): Field(int, doc='No longer optional'), }) register_model(TestModel) get_converter(TestModel).get_schema_url = lambda *a, **ka: "" TEST_DATA = { (0, 1): "a", (0, 2): "b", (0, 5): True, (0, 6): False, (1, 0): 123, (2, 1): 456, } @pytest.mark.parametrize( 'version', ((0, 0), (0, 1), (0, 2), (0, 5), (0, 6), (1, 0)),