Skip to content

Commit

Permalink
Merge pull request #279 from cwacek/fix/278
Browse files Browse the repository at this point in the history
tests: Add a test to validate expected behavior on #278
  • Loading branch information
cwacek authored Feb 24, 2024
2 parents 4ea8b43 + 0dde416 commit c7936eb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions python_jsonschema_objects/wrapper_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ def validate_items(self):
try:
if isinstance(elem, (six.string_types, six.integer_types, float)):
val = typ(elem)
elif isinstance(elem, classbuilder.LiteralValue):
val = typ(elem._value)
else:
val = typ(**util.coerce_for_expansion(elem))
except TypeError as e:
Expand Down
6 changes: 5 additions & 1 deletion test/test_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,15 @@ def test_arrays_can_have_reffed_items_of_mixed_type():
builder = pjs.ObjectBuilder(schema)
ns = builder.build_classes()

ns.Test(list=["foo", "bar"])
x = ns.Test(list=["foo", "bar"])
ns.Test(list=[{"bar": "nice"}, "bar"])
with pytest.raises(pjs.ValidationError):
ns.Test(list=[100])

assert x.list == ["foo", "bar"]
x.list.append(ns.Foo("bleh"))
assert x.list == ["foo", "bar", "bleh"]


def test_regression_39():
builder = pjs.ObjectBuilder("test/thing-two.json")
Expand Down

0 comments on commit c7936eb

Please sign in to comment.