Пример #1
0
def test_data_class():
    field = DataModelFieldBase(
        name='a', data_types=[DataType(type='str')], required=True
    )

    data_class = DataClass(name='test_model', fields=[field])

    assert data_class.name == 'test_model'
    assert data_class.fields == [field]
    assert data_class.decorators == []
    assert data_class.render() == '@dataclass\n' 'class test_model:\n' '    a: str'
Пример #2
0
def test_data_class_optional():
    field = DataModelField(name='a',
                           data_types=[DataType(type='str')],
                           default="'abc'",
                           required=True)

    data_class = DataClass(name='test_model', fields=[field])

    assert data_class.name == 'test_model'
    assert data_class.fields == [field]
    assert data_class.decorators == []
    assert (data_class.render() == '@dataclass\n'
            'class test_model:\n'
            '    a: str = \'abc\'')
Пример #3
0
def test_data_class_base_class():
    field = DataModelFieldBase(name='a', data_type=DataType(type='str'), required=True)

    data_class = DataClass(
        fields=[field],
        base_classes=[Reference(name='Base', original_name='Base', path='Base')],
        reference=Reference(name='test_model', path='test_model'),
    )

    assert data_class.name == 'test_model'
    assert data_class.fields == [field]
    assert data_class.decorators == []
    assert (
        data_class.render() == '@dataclass\n' 'class test_model(Base):\n' '    a: str'
    )
Пример #4
0
def test_data_class_get_data_type():
    assert DataClass.get_data_type(Types.integer) == DataType(type='int')