示例#1
0
def test_map_invalid_key(value):
    with pytest.raises(
            ValueError,
            match=
            r'The key \[.*\], value \[(.|\s)*\] is not from the type StringType'
    ):
        assert MapType(values=StringType()).validate(value)
示例#2
0
def test_record_type_optional_key_not_in_value(value):
    assert RecordType({
        'name':
        RecordTypeField('name', StringType()),
        'age':
        RecordTypeField('age', UnionType([NullType(), IntType()]))
    }).validate(value) is True
示例#3
0
def test_record_type_missing_key_in_value(value):
    regex = r'The fields from value \[.*\] differs from the fields of the record type \[.*\]'
    with pytest.raises(ValueError, match=regex):
        RecordType({
            'name': RecordTypeField('name', StringType()),
            'age': RecordTypeField('age', IntType())
        }).validate(value)
示例#4
0
def test_invalid_array_item_type(value):
    with pytest.raises(
            ValueError,
            match=
            r'The item at index \[\d+\]: \[.+\] is not from the type \[StringType\]'
    ):
        ArrayType(StringType()).validate(value)
示例#5
0
def test_record_type_wrong_value_type(value):
    with pytest.raises(
            ValueError,
            match=
            r'The value \[.*\] for field \[name\] should be \[StringType\]\.'):
        RecordType({
            'name': RecordTypeField('name', StringType())
        }).validate(value)
示例#6
0
def test_invalid_record_type(value):
    with pytest.raises(
            ValueError,
            match=
            r'The value \[(.|\s)*\] should have type dict but it has \[.*\].'):
        RecordType({
            'name': RecordTypeField('name', StringType())
        }).validate(value)
示例#7
0
def test_record_type_additional_key_in_value(value):
    regex = (
        r'The fields from value \[.*\] differs from the fields of the record type \[.*\]. '
        r'The following fields are not in the schema, but are present: \[.*\].'
    )
    with pytest.raises(ValueError, match=regex):
        RecordType({
            'name': RecordTypeField('name', StringType())
        }).validate(value)
示例#8
0
def test_invalid_map_type(value):
    with pytest.raises(
            ValueError,
            match=r'The value \[(.|\s)*\] should be dict but it is not.'):
        MapType(StringType()).validate(value)
示例#9
0
def test_record_type(value):
    assert RecordType({
        'name': RecordTypeField('name', StringType())
    }).validate(value) is True
示例#10
0
def test_array_union_type(value):
    assert ArrayType(UnionType([NullType(), StringType()
                                ])).validate(value) is True
示例#11
0
def test_invalid_array(value):
    with pytest.raises(
            ValueError,
            match=r'The value \[(.|\s)*\] should be list but it is not.'):
        assert ArrayType(StringType()).validate(value)
示例#12
0
def test_array_type(value):
    assert ArrayType(StringType()).validate(value) is True
示例#13
0
def test_invalid_union(value):
    t = UnionType([NullType(), StringType()])

    with pytest.raises(ValueError):
        t.validate(value)
示例#14
0
def test_union_type(value):
    t = UnionType([NullType(), StringType()])

    assert t.validate(value) is True
示例#15
0
def test_string_type(value):
    assert StringType().validate(value) is True
示例#16
0
def test_invalid_string(value):
    assert StringType().check_type(value) is False
示例#17
0
def test_record_type_repr(value):
    msg = (
        'RecordType <{\'name\': RecordTypeField <name: name, type: StringType, '
        'doc: None, default: None, order: None, aliases: None>}>')
    assert str(RecordType({'name': RecordTypeField('name',
                                                   StringType())})) == msg