1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
import unittest
import json
from schema_salad.schema import load_schema
from schema_salad.validate import validate_ex
from schema_salad.sourceline import cmap
class TestValidate(unittest.TestCase):
schema = cmap({"name": "_", "$graph":[{
"name": "File",
"type": "record",
"fields": [{
"name": "class",
"type": {
"type": "enum",
"name": "File_class",
"symbols": ["#_/File"]
},
"jsonldPredicate": {
"_id": "@type",
"_type": "@vocab"
}
}, {
"name": "location",
"type": "string",
"jsonldPredicate": "_:location"
}]
}, {
"name": "Directory",
"type": "record",
"fields": [{
"name": "class",
"type": {
"type": "enum",
"name": "Directory_class",
"symbols": ["#_/Directory"]
},
"jsonldPredicate": {
"_id": "@type",
"_type": "@vocab"
}
}, {
"name": "location",
"type": "string",
"jsonldPredicate": "_:location"
}, {
"name": "listing",
"type": {
"type": "array",
"items": ["File", "Directory"]
}
}],
}]})
def test_validate_big(self):
document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(self.schema)
with open("biglisting.yml") as f:
biglisting = json.load(f)
self.assertEquals(True, validate_ex(avsc_names.get_name("Directory", ""), biglisting,
strict=True, raise_ex=False))
# def test_validate_small(self):
# document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(self.schema)
# with open("smalllisting.yml") as f:
# smalllisting = json.load(f)
# validate_ex(avsc_names.get_name("Directory", ""), smalllisting,
# strict=True, raise_ex=True)
|