-
Notifications
You must be signed in to change notification settings - Fork 86
Open
Description
Environment
- Python version: 3.5.2
- PyKwalify version: 1.8.0
Steps to Reproduce
- create input YML file as below
test.yml
mydata:
name: 123
age: ABCD
hobbies: [cooking, painting, cooking]
- create YML schema as below
type: map
mapping:
mydata:
type: map
mapping:
name:
type: str
range:
min: 1
max: 10
age:
type: int
range:
min: 21
max: 100
hobbies:
type: seq
sequence:
- type: str
unique: true
required: true
- Write Python test case for validation as below
validate_yml.py
#! /usr/bin/python3
@author: Minal Deshmukh
import pykwalify
from pykwalify.core import Core, SchemaError
from pykwalify.errors import RuleError
yaml_file = "./test.yml"
schema_file = "./schema.yml"
yaml_schema = Core(source_file=yaml_file, schema_files=[schema_file])
try:
pykwalify.init_logging(0)
yaml_schema.validate(raise_exception=True)
except (SchemaError, RuleError):
for error in yaml_schema.errors:
print("error -->",error)
print ("Data Type of error is -->",type(error))
- Execute test case as below
python3 validate_yml.py
OUTPUT
error --> Value 'ABCD' is not of type 'int'. Path: '/mydata/age'
Data Type of error is --> <class 'pykwalify.errors.SchemaError.SchemaErrorEntry'>
error --> Value '123' is not of type 'str'. Path: '/mydata/name'
Data Type of error is --> <class 'pykwalify.errors.SchemaError.SchemaErrorEntry'>
error --> Value 'cooking' is not unique. Previous path: '/mydata/hobbies/0'. Path: '/mydata/hobbies/2'
Data Type of error is --> <class 'str'>
Schema
type: map
mapping:
mydata:
type: map
mapping:
name:
type: str
range:
min: 1
max: 10
age:
type: int
range:
min: 21
max: 100
hobbies:
type: seq
sequence:
- type: str
unique: true
required: true
Data
mydata:
name: 123
age: ABCD
hobbies: [cooking, painting, cooking]
Expected Behavior
Expected data type of the error below is 'pykwalify.errors.SchemaError.SchemaErrorEntry'
error --> Value 'cooking' is not unique. Previous path: '/mydata/hobbies/0'. Path: '/mydata/hobbies/2'
Data Type of error is --> <class 'str'>
Observed Behavior
Data type is different than the other error data types
error --> Value 'cooking' is not unique. Previous path: '/mydata/hobbies/0'. Path: '/mydata/hobbies/2'
Data Type of error is --> <class 'str'>
Metadata
Metadata
Assignees
Labels
No labels