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)
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
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)
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)
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)
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)
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)
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)
def test_record_type(value): assert RecordType({ 'name': RecordTypeField('name', StringType()) }).validate(value) is True
def test_array_union_type(value): assert ArrayType(UnionType([NullType(), StringType() ])).validate(value) is True
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)
def test_array_type(value): assert ArrayType(StringType()).validate(value) is True
def test_invalid_union(value): t = UnionType([NullType(), StringType()]) with pytest.raises(ValueError): t.validate(value)
def test_union_type(value): t = UnionType([NullType(), StringType()]) assert t.validate(value) is True
def test_string_type(value): assert StringType().validate(value) is True
def test_invalid_string(value): assert StringType().check_type(value) is False
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