File: test_validate.pyx

package info (click to toggle)
python-schema-salad 2.2.20170111180227-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,168 kB
  • ctags: 213
  • sloc: python: 2,991; makefile: 138
file content (71 lines) | stat: -rw-r--r-- 2,152 bytes parent folder | download | duplicates (2)
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)