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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
---
name: fail-mapping-1
desc: This test that typechecking works when value in map is None
data:
streams:
- name: ~
sampleRateMultiple: 1
- name: media
sampleRateMultiple: 2
schema:
type: map
mapping:
streams:
type: seq
required: True
sequence:
- type: map
mapping:
name:
type: str
range:
min: 1
required: True
sampleRateMultiple:
type: int
required: True
errors:
- "required.novalue : '/streams/0/name'"
---
name: fail-mapping-2
desc: Test keyword regex using default matching-rule 'any'
data:
foobar1: 1
foobar2: 2
foobar3: 3
schema:
type: map
mapping:
regex;(^foobar[1-2]$):
type: int
errors:
- "Key 'foobar3' does not match any regex '^foobar[1-2]$'. Path: ''"
---
name: fail-mapping-3
desc: Test keyword regex using declared matching-rule 'any'
data:
foobar1: 1
foobar2: 2
bar3: 3
schema:
type: map
matching-rule: 'any'
mapping:
regex;(^foobar):
type: int
regex;([1-2]$):
type: int
errors:
- "Key 'bar3' does not match any regex '[1-2]$' or '^foobar'. Path: ''"
---
name: fail-mapping-4
desc: Test keyword regex using declared matching-rule 'all'
data:
foobar1: 1
foobar2: 2
foobar3: 3
schema:
type: map
matching-rule: 'all'
mapping:
regex;(^foobar.*$):
type: int
regex;(^.*[1-2]$):
type: int
errors:
- "Key 'foobar3' does not match all regex '^.*[1-2]$' and '^foobar.*$'. Path: ''"
---
name: fail-mapping-5
desc: Test that sequence of mappings check the correct type and raises correct error when value is not a dict
data:
- foo: whatever
- "sgdf"
- 2
- ~
schema:
type: seq
required: True
matching: all
seq:
- type: map
required: True
map:
foo:
type: str
errors:
- "Value '2' is not a dict. Value path: '/2'"
- "Value 'sgdf' is not a dict. Value path: '/1'"
- "required.novalue : '/3'"
---
name: fail-mapping-6
desc: Test that type checking of mapping is done even if the mapping keyword is not specefied in the schema
data:
- not
- a
- map
schema:
type: map
allowempty: True
errors:
- "Value '['not', 'a', 'map']' is not a dict. Value path: ''"
---
name: fail-mapping-7
desc: Test that default mode fails out in a similar way to regular mode and that a key that is not defined when default is set uses the default impl
data:
OWNERSHIP: abc
WHT: def
schema:
type: map
mapping:
WHT:
type: int
=:
type: int
errors:
- "Value 'abc' is not of type 'int'. Path: '/OWNERSHIP'"
- "Value 'def' is not of type 'int'. Path: '/WHT'"
---
name: fail-mapping-8
desc: mapping test
schema:
type: map
required: true
mapping:
name:
type: str
required: true
email:
type: str
# This pattern value was modified from /@/ to .+@.+ to make it copmatible with python
pattern: .+@.+
required: True
age:
type: int
blood:
type: str
enum:
- A
- B
- O
- AB
birth:
type: date
data:
nam: foo
email: foo(at)mail.com
age: twenty
blood: ab
birth: Jul 01, 1985
errors:
- "Cannot find required key 'name'. Path: ''"
- "Enum 'ab' does not exist. Path: '/blood' Enum: ['A', 'B', 'O', 'AB']"
- "Key 'nam' was not defined. Path: ''"
- "Value 'foo(at)mail.com' does not match pattern '.+@.+'. Path: '/email'"
- "Value 'twenty' is not of type 'int'. Path: '/age'"
## Kwalify errors
# :required_nokey : 1:1:[/] key 'name:' is required.
# :key_undefined : 1:1:[/nam] key 'nam:' is undefined.
# :pattern_unmatch : 2:1:[/email] 'foo(at)mail.com': not matched to pattern /@/.
# :type_unmatch : 3:1:[/age] 'twenty': not a integer.
# :enum_notexist : 4:1:[/blood] 'ab': invalid blood value.
# :type_unmatch : 5:1:[/birth] 'Jul 01, 1985': not a date.
---
name: fail-mapping-9
desc: Test that regexes can be 'required'
data:
hello: Hi
person: Fred
schema:
type: map
mapping:
regex;(person[1-9]):
required: True
errors:
- "Cannot find required key 'regex;(person[1-9])'. Path: ''"
- "Key 'hello' does not match any regex 'person[1-9]'. Path: ''"
- "Key 'person' does not match any regex 'person[1-9]'. Path: ''"
|