Skip to content

Commit

Permalink
Revert "blacken json tests"
Browse files Browse the repository at this point in the history
This reverts commit 496718e.
Undo blacken to reduce diff size of PR
  • Loading branch information
hudson-ai committed Nov 4, 2024
1 parent b236a2c commit ce84d53
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 277 deletions.
58 changes: 22 additions & 36 deletions tests/unit/library/json/test_allOf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from jsonschema import ValidationError, validate

from guidance import json as gen_json

from .utils import check_match_failure, generate_and_check


Expand Down Expand Up @@ -139,6 +138,7 @@ def test_allOf_simple_maximum(self, test_object, valid):
validate(instance=test_object, schema=schema)
check_match_failure(bad_string=json_dumps(test_object), schema_obj=schema)


@pytest.mark.parametrize(
["test_object", "valid"],
[
Expand Down Expand Up @@ -357,41 +357,32 @@ def test_allOf_combined_with_anyOf_oneOf(self, test_object, valid):
({"foo": 0, "bar": 5, "baz": 4}, False),
# invalid: baz is not an integer or null
({"foo": 0, "bar": 5, "baz": "quxx"}, False),
],
]
)
@pytest.mark.parametrize(
"schema",
[
# The following are equivalent to this:
{
"properties": {
"foo": {"type": ["integer", "null"], "maximum": 4},
"bar": {"minimum": 5, "maximum": 5},
},
"additionalProperties": {"type": ["integer", "null"], "minimum": 5},
"properties": {"foo": {"type": ["integer", "null"], "maximum": 4}, "bar": {"minimum": 5, "maximum": 5}},
"additionalProperties": {"type": ["integer", "null"], "minimum": 5}
},
# additionalProperties in parent schema
{
"allOf": [
{"properties": {"foo": {"maximum": 4}}, "additionalProperties": {"minimum": 5}}
],
"properties": {"bar": {"maximum": 5}},
"additionalProperties": {"type": ["integer", "null"]},
"additionalProperties": {"type": ["integer", "null"]}
},
# additionalProperties in allOf
{
"allOf": [
{
"properties": {"foo": {"maximum": 4}},
"additionalProperties": {"minimum": 5},
},
{
"properties": {"bar": {"maximum": 5}},
"additionalProperties": {"type": ["integer", "null"]},
},
{"properties": {"foo": {"maximum": 4}}, "additionalProperties": {"minimum": 5}},
{"properties": {"bar": {"maximum": 5}}, "additionalProperties": {"type": ["integer", "null"]}}
]
},
],
]
)
def test_additionalProperties_in_allOf(self, schema, test_object, valid):
if valid:
Expand All @@ -405,19 +396,19 @@ def test_additionalProperties_in_allOf(self, schema, test_object, valid):
@pytest.mark.parametrize(
"test_object, valid",
[
({}, True), # empty object is valid
({"foo": 1}, False), # foo is not a string
({"foo": "x"}, False), # foo is not an integer
({"foo": True}, False), # foo is not a string or an integer
],
({}, True), # empty object is valid
({"foo": 1}, False), # foo is not a string
({"foo": "x"}, False), # foo is not an integer
({"foo": True}, False), # foo is not a string or an integer
]
)
def test_inconsistent_additionalProperties_in_allOf(self, test_object, valid):
schema = {
"type": "object",
"allOf": [
{"additionalProperties": {"type": "integer"}},
{"additionalProperties": {"type": "string"}},
],
{"additionalProperties": {"type": "string"}}
]
}
if valid:
validate(instance=test_object, schema=schema)
Expand Down Expand Up @@ -449,38 +440,33 @@ def test_inconsistent_additionalProperties_in_allOf(self, test_object, valid):
([0, 5, 4], False),
# invalid: baz is not an integer or null
([0, 5, "quxx"], False),
],
]
)
@pytest.mark.parametrize(
"schema",
[
# The following are equivalent to this:
{
"prefixItems": [
{"type": ["integer", "null"], "maximum": 4},
{"minimum": 5, "maximum": 5},
],
"items": {"type": ["integer", "null"], "minimum": 5},
"prefixItems": [{"type": ["integer", "null"], "maximum": 4}, {"minimum": 5, "maximum": 5}],
"items": {"type": ["integer", "null"], "minimum": 5}
},
# items in parent schema
{
"allOf": [
{"prefixItems": [{"maximum": 4}], "items": {"minimum": 5}},
],
"prefixItems": [{"type": ["integer", "null"]}, {"maximum": 5}],
"items": {"type": ["integer", "null"]},
"items": {"type": ["integer", "null"]}
},
# items in allOf
{
"allOf": [
{"prefixItems": [{"maximum": 4}], "items": {"minimum": 5}},
{
"prefixItems": [{"type": ["integer", "null"]}, {"maximum": 5}],
"items": {"type": ["integer", "null"]},
},
{"prefixItems": [{"type": ["integer", "null"]}, {"maximum": 5}], "items": {"type": ["integer", "null"]}}
]
},
],
]
)
def test_items_and_prefixitems_in_allOf(self, schema, test_object, valid):
if valid:
Expand Down
Loading

0 comments on commit ce84d53

Please sign in to comment.