Skip to content

Commit b9ff8c4

Browse files
committed
Squashed 'json/' changes from f82764080..91ecacf60
91ecacf60 Forward port a missing null instance property test. fe3eda228 Apply #579 to case descriptions as well. git-subtree-dir: json git-subtree-split: 91ecacf6093692d0fc0082f7a08ed74f74a5f715
1 parent 7a5fd08 commit b9ff8c4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+198
-191
lines changed

bin/jsonschema_suite

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,27 @@ class SanityTests(unittest.TestCase):
9494
seen.add(each)
9595
self.assertFalse(duplicated, "Elements are not unique.")
9696

97+
def assertFollowsDescriptionStyle(self, description):
98+
"""
99+
Instead of saying "test that X frobs" or "X should frob" use "X frobs".
100+
101+
See e.g. https://jml.io/pages/test-docstrings.html
102+
103+
This test isn't comprehensive (it doesn't catch all the extra
104+
verbiage there), but it's just to catch whatever it manages to
105+
cover.
106+
"""
107+
108+
message = (
109+
"In descriptions, don't say 'Test that X frobs' or 'X should "
110+
"frob' or 'X should be valid'. Just say 'X frobs' or 'X is "
111+
"valid'. It's shorter, and the test suite is entirely about "
112+
"what *should* be already. "
113+
"See https://jml.io/pages/test-docstrings.html for help."
114+
)
115+
self.assertNotRegex(description, r"\bshould\b", message)
116+
self.assertNotRegex(description, r"(?i)\btest(s)? that\b", message)
117+
97118
def test_all_test_files_are_valid_json(self):
98119
"""
99120
All test files contain valid JSON.
@@ -160,36 +181,15 @@ class SanityTests(unittest.TestCase):
160181
)
161182
print(f"Found {count} test cases.")
162183

163-
def test_descriptions_do_not_use_modal_verbs(self):
164-
"""
165-
Instead of saying "test that X frobs" or "X should frob" use "X frobs".
166-
167-
See e.g. https://jml.io/pages/test-docstrings.html
168-
169-
This test isn't comprehensive (it doesn't catch all the extra
170-
verbiage there), but it's just to catch whatever it manages to
171-
cover.
172-
"""
184+
def test_case_descriptions_do_not_use_modal_verbs(self):
185+
for case in cases(self.test_files):
186+
with self.subTest(description=case["description"]):
187+
self.assertFollowsDescriptionStyle(case["description"])
173188

174-
message = (
175-
"In descriptions, don't say 'Test that X frobs' or 'X should "
176-
"frob' or 'X should be valid'. Just say 'X frobs' or 'X is "
177-
"valid'. It's shorter, and the test suite is entirely about "
178-
"what *should* be already. "
179-
"See https://jml.io/pages/test-docstrings.html for help."
180-
)
189+
def test_test_descriptions_do_not_use_modal_verbs(self):
181190
for test in tests(self.test_files):
182191
with self.subTest(description=test["description"]):
183-
self.assertNotRegex(
184-
test["description"],
185-
r"\bshould\b",
186-
message,
187-
)
188-
self.assertNotRegex(
189-
test["description"],
190-
r"(?i)\btest(s)? that\b",
191-
message,
192-
)
192+
self.assertFollowsDescriptionStyle(test["description"])
193193

194194
@unittest.skipIf(jsonschema is None, "Validation library not present!")
195195
def test_all_schemas_are_valid(self):

tests/draft-next/additionalProperties.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@
6060
]
6161
},
6262
{
63-
"description":
64-
"additionalProperties allows a schema which should validate",
63+
"description": "additionalProperties with schema",
6564
"schema": {
6665
"properties": {"foo": {}, "bar": {}},
6766
"additionalProperties": {"type": "boolean"}
@@ -115,7 +114,7 @@
115114
]
116115
},
117116
{
118-
"description": "additionalProperties should not look in applicators",
117+
"description": "additionalProperties does not look in applicators",
119118
"schema": {
120119
"allOf": [
121120
{"properties": {"foo": {}}}
@@ -131,15 +130,15 @@
131130
]
132131
},
133132
{
134-
"description": "additionalProperties should properly handle null data",
133+
"description": "additionalProperties with null valued instance properties",
135134
"schema": {
136135
"additionalProperties": {
137136
"type": "null"
138137
}
139138
},
140139
"tests": [
141140
{
142-
"description": "null properties allowed",
141+
"description": "allows null values",
143142
"data": {"foo": null},
144143
"valid": true
145144
}

tests/draft-next/contains.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,15 @@
239239
]
240240
},
241241
{
242-
"description": "contains should properly handle null data",
242+
"description": "contains with null instance elements",
243243
"schema": {
244244
"contains": {
245245
"type": "null"
246246
}
247247
},
248248
"tests": [
249249
{
250-
"description": "null items allowed",
250+
"description": "allows null items",
251251
"data": [ null ],
252252
"valid": true
253253
}

tests/draft-next/dynamicRef.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
3-
"description": "A $dynamicRef to a $dynamicAnchor in the same schema resource should behave like a normal $ref to an $anchor",
3+
"description": "A $dynamicRef to a $dynamicAnchor in the same schema resource behaves like a normal $ref to an $anchor",
44
"schema": {
55
"$id": "https://test.json-schema.org/dynamicRef-dynamicAnchor-same-schema/root",
66
"type": "array",
@@ -26,7 +26,7 @@
2626
]
2727
},
2828
{
29-
"description": "A $ref to a $dynamicAnchor in the same schema resource should behave like a normal $ref to an $anchor",
29+
"description": "A $ref to a $dynamicAnchor in the same schema resource behaves like a normal $ref to an $anchor",
3030
"schema": {
3131
"$id": "https://test.json-schema.org/ref-dynamicAnchor-same-schema/root",
3232
"type": "array",
@@ -52,7 +52,7 @@
5252
]
5353
},
5454
{
55-
"description": "A $dynamicRef should resolve to the first $dynamicAnchor still in scope that is encountered when the schema is evaluated",
55+
"description": "A $dynamicRef resolves to the first $dynamicAnchor still in scope that is encountered when the schema is evaluated",
5656
"schema": {
5757
"$id": "https://test.json-schema.org/typical-dynamic-resolution/root",
5858
"$ref": "list",
@@ -82,7 +82,7 @@
8282
]
8383
},
8484
{
85-
"description": "A $dynamicRef with intermediate scopes that don't include a matching $dynamicAnchor should not affect dynamic scope resolution",
85+
"description": "A $dynamicRef with intermediate scopes that don't include a matching $dynamicAnchor does not affect dynamic scope resolution",
8686
"schema": {
8787
"$id": "https://test.json-schema.org/dynamic-resolution-with-intermediate-scopes/root",
8888
"$ref": "intermediate-scope",
@@ -116,7 +116,7 @@
116116
]
117117
},
118118
{
119-
"description": "An $anchor with the same name as a $dynamicAnchor should not be used for dynamic scope resolution",
119+
"description": "An $anchor with the same name as a $dynamicAnchor is not used for dynamic scope resolution",
120120
"schema": {
121121
"$id": "https://test.json-schema.org/dynamic-resolution-ignores-anchors/root",
122122
"$ref": "list",
@@ -146,7 +146,7 @@
146146
]
147147
},
148148
{
149-
"description": "A $dynamicRef that initially resolves to a schema with a matching $dynamicAnchor should resolve to the first $dynamicAnchor in the dynamic scope",
149+
"description": "A $dynamicRef that initially resolves to a schema with a matching $dynamicAnchor resolves to the first $dynamicAnchor in the dynamic scope",
150150
"schema": {
151151
"$id": "https://test.json-schema.org/relative-dynamic-reference/root",
152152
"$dynamicAnchor": "meta",
@@ -243,7 +243,7 @@
243243
]
244244
},
245245
{
246-
"description": "after leaving a dynamic scope, it should not be used by a $dynamicRef",
246+
"description": "after leaving a dynamic scope, it is not used by a $dynamicRef",
247247
"schema": {
248248
"$id": "https://test.json-schema.org/dynamic-ref-leaving-dynamic-scope/main",
249249
"if": {

tests/draft-next/items.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@
254254
]
255255
},
256256
{
257-
"description": "items with null",
257+
"description": "items with null instance elements",
258258
"schema": {
259259
"items": {
260260
"type": "null"

tests/draft-next/multipleOf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
]
5959
},
6060
{
61-
"description": "invalid instance should not raise error when float division = inf",
61+
"description": "float division = inf",
6262
"schema": {"type": "integer", "multipleOf": 0.123456789},
6363
"tests": [
6464
{

tests/draft-next/optional/ecmascript-regex.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@
290290
]
291291
},
292292
{
293-
"description": "unicode semantics should be used for all pattern matching",
293+
"description": "patterns always use unicode semantics with pattern",
294294
"schema": { "pattern": "\\p{Letter}cole" },
295295
"tests": [
296296
{
@@ -416,7 +416,7 @@
416416
]
417417
},
418418
{
419-
"description": "unicode semantics should be used for all patternProperties matching",
419+
"description": "patterns always use unicode semantics with patternProperties",
420420
"schema": {
421421
"type": "object",
422422
"patternProperties": {

tests/draft-next/patternProperties.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,15 @@
154154
]
155155
},
156156
{
157-
"description": "patternProperties should properly handle null data",
157+
"description": "patternProperties with null valued instance properties",
158158
"schema": {
159159
"patternProperties": {
160160
"^.*bar$": {"type": "null"}
161161
}
162162
},
163163
"tests": [
164164
{
165-
"description": "null properties allowed",
165+
"description": "allows null values",
166166
"data": {"foobar": null},
167167
"valid": true
168168
}

tests/draft-next/prefixItems.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
]
8080
},
8181
{
82-
"description": "prefixItems properly handles null data",
82+
"description": "prefixItems with null instance elements",
8383
"schema": {
8484
"prefixItems": [
8585
{
@@ -89,7 +89,7 @@
8989
},
9090
"tests": [
9191
{
92-
"description": "null items allowed",
92+
"description": "allows null elements",
9393
"data": [ null ],
9494
"valid": true
9595
}

tests/draft-next/properties.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,15 @@
165165
]
166166
},
167167
{
168-
"description": "properties should properly handle null data",
168+
"description": "properties with null valued instance properties",
169169
"schema": {
170170
"properties": {
171171
"foo": {"type": "null"}
172172
}
173173
},
174174
"tests": [
175175
{
176-
"description": "null properties allowed",
176+
"description": "allows null values",
177177
"data": {"foo": null},
178178
"valid": true
179179
}

tests/draft-next/unevaluatedItems.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,15 +627,15 @@
627627
]
628628
},
629629
{
630-
"description": "unevaluatedItems should properly handle null data",
630+
"description": "unevaluatedItems with null instance elements",
631631
"schema": {
632632
"unevaluatedItems": {
633633
"type": "null"
634634
}
635635
},
636636
"tests": [
637637
{
638-
"description": "null items allowed",
638+
"description": "allows null elements",
639639
"data": [ null ],
640640
"valid": true
641641
}

tests/draft-next/unevaluatedProperties.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,5 +1392,20 @@
13921392
"valid": true
13931393
}
13941394
]
1395+
},
1396+
{
1397+
"description": "unevaluatedProperties with null valued instance properties",
1398+
"schema": {
1399+
"unevaluatedProperties": {
1400+
"type": "null"
1401+
}
1402+
},
1403+
"tests": [
1404+
{
1405+
"description": "allows null valued properties",
1406+
"data": {"foo": null},
1407+
"valid": true
1408+
}
1409+
]
13951410
}
13961411
]

tests/draft2019-09/additionalItems.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
]
9696
},
9797
{
98-
"description": "additionalItems should not look in applicators, valid case",
98+
"description": "additionalItems does not look in applicators, valid case",
9999
"schema": {
100100
"allOf": [
101101
{ "items": [ { "type": "integer" } ] }
@@ -111,7 +111,7 @@
111111
]
112112
},
113113
{
114-
"description": "additionalItems should not look in applicators, invalid case",
114+
"description": "additionalItems does not look in applicators, invalid case",
115115
"schema": {
116116
"allOf": [
117117
{ "items": [ { "type": "integer" }, { "type": "string" } ] }
@@ -147,15 +147,15 @@
147147
]
148148
},
149149
{
150-
"description": "additionalItems should properly handle null data",
150+
"description": "additionalItems with null instance elements",
151151
"schema": {
152152
"additionalItems": {
153153
"type": "null"
154154
}
155155
},
156156
"tests": [
157157
{
158-
"description": "null items allowed",
158+
"description": "allows null elements",
159159
"data": [ null ],
160160
"valid": true
161161
}

tests/draft2019-09/additionalProperties.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@
6060
]
6161
},
6262
{
63-
"description":
64-
"additionalProperties allows a schema which should validate",
63+
"description": "additionalProperties with schema",
6564
"schema": {
6665
"properties": {"foo": {}, "bar": {}},
6766
"additionalProperties": {"type": "boolean"}
@@ -115,7 +114,7 @@
115114
]
116115
},
117116
{
118-
"description": "additionalProperties should not look in applicators",
117+
"description": "additionalProperties does not look in applicators",
119118
"schema": {
120119
"allOf": [
121120
{"properties": {"foo": {}}}
@@ -131,15 +130,15 @@
131130
]
132131
},
133132
{
134-
"description": "additionalProperties should properly handle null data",
133+
"description": "additionalProperties with null valued instance properties",
135134
"schema": {
136135
"additionalProperties": {
137136
"type": "null"
138137
}
139138
},
140139
"tests": [
141140
{
142-
"description": "null properties allowed",
141+
"description": "allows null values",
143142
"data": {"foo": null},
144143
"valid": true
145144
}

0 commit comments

Comments
 (0)