Skip to content

test_array_prefixitems_invalid[value0] failing on 0.6.2 #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mweinelt opened this issue Dec 3, 2023 · 2 comments · Fixed by #165
Closed

test_array_prefixitems_invalid[value0] failing on 0.6.2 #153

mweinelt opened this issue Dec 3, 2023 · 2 comments · Fixed by #165

Comments

@mweinelt
Copy link

mweinelt commented Dec 3, 2023

Hi, we're seeing the following test fail. Our environment is

  • Python 3.11.6
  • jsonschema 4.20.0
  • jsonschema-specifications 2023.11.2
  • rfc3339-validator 0.1.4
openapi-schema-validator> ______ TestOAS31ValidatorValidate.test_array_prefixitems_invalid[value0] _______
openapi-schema-validator> 
openapi-schema-validator> self = <test_validators.TestOAS31ValidatorValidate object at 0x7ffff5d0f710>
openapi-schema-validator> validator_class = <class 'jsonschema.validators.create.<locals>.Validator'>
openapi-schema-validator> value = [1600, 'Pennsylvania', 'Avenue', 'NW', 'Washington']
openapi-schema-validator> 
openapi-schema-validator>     @pytest.mark.parametrize(
openapi-schema-validator>         "value",
openapi-schema-validator>         [
openapi-schema-validator>             [1600, "Pennsylvania", "Avenue", "NW", "Washington"],
openapi-schema-validator>         ],
openapi-schema-validator>     )
openapi-schema-validator>     def test_array_prefixitems_invalid(self, validator_class, value):
openapi-schema-validator>         schema = {
openapi-schema-validator>             "type": "array",
openapi-schema-validator>             "prefixItems": [
openapi-schema-validator>                 {"type": "number"},
openapi-schema-validator>                 {"type": "string"},
openapi-schema-validator>                 {"enum": ["Street", "Avenue", "Boulevard"]},
openapi-schema-validator>                 {"enum": ["NW", "NE", "SW", "SE"]},
openapi-schema-validator>             ],
openapi-schema-validator>             "items": False,
openapi-schema-validator>         }
openapi-schema-validator>         validator = validator_class(
openapi-schema-validator>             schema,
openapi-schema-validator>             format_checker=oas31_format_checker,
openapi-schema-validator>         )
openapi-schema-validator>     
openapi-schema-validator>         with pytest.raises(ValidationError) as excinfo:
openapi-schema-validator>             validator.validate(value)
openapi-schema-validator>     
openapi-schema-validator>         error = "Expected at most 4 items, but found 5"
openapi-schema-validator> >       assert error in str(excinfo.value)
openapi-schema-validator> E       assert 'Expected at most 4 items, but found 5' in "Expected at most 4 items but found 1 extra: 'Washington'\n\nFailed validating 'items' in schema:\n    {'items': False,\n     'prefixItems': [{'type': 'number'},\n                     {'type': 'string'},\n                     {'enum': ['Street', 'Avenue', 'Boulevard']},\n                     {'enum': ['NW', 'NE', 'SW', 'SE']}],\n     'type': 'array'}\n\nOn instance:\n    [1600, 'Pennsylvania', 'Avenue', 'NW', 'Washington']"
openapi-schema-validator> E        +  where "Expected at most 4 items but found 1 extra: 'Washington'\n\nFailed validating 'items' in schema:\n    {'items': False,\n     'prefixItems': [{'type': 'number'},\n                     {'type': 'string'},\n                     {'enum': ['Street', 'Avenue', 'Boulevard']},\n                     {'enum': ['NW', 'NE', 'SW', 'SE']}],\n     'type': 'array'}\n\nOn instance:\n    [1600, 'Pennsylvania', 'Avenue', 'NW', 'Washington']" = str(<ValidationError: "Expected at most 4 items but found 1 extra: 'Washington'">)
openapi-schema-validator> E        +    where <ValidationError: "Expected at most 4 items but found 1 extra: 'Washington'"> = <ExceptionInfo <ValidationError: "Expected at most 4 items but found 1 extra: 'Washington'"> tblen=2>.value
openapi-schema-validator> 
openapi-schema-validator> error      = 'Expected at most 4 items, but found 5'
openapi-schema-validator> excinfo    = <ExceptionInfo <ValidationError: "Expected at most 4 items but found 1 extra: 'Washington'"> tblen=2>
openapi-schema-validator> schema     = {'items': False,
openapi-schema-validator>  'prefixItems': [{'type': 'number'},
openapi-schema-validator>                  {'type': 'string'},
openapi-schema-validator>                  {'enum': ['Street', 'Avenue', 'Boulevard']},
openapi-schema-validator>                  {'enum': ['NW', 'NE', 'SW', 'SE']}],
openapi-schema-validator>  'type': 'array'}
openapi-schema-validator> self       = <test_validators.TestOAS31ValidatorValidate object at 0x7ffff5d0f710>
openapi-schema-validator> validator  = Validator(schema={'items': False, 'prefixItems': [{'type': 'number'}, {'type': 'string'}, {'enum': ['Street', 'Avenue', 'Boulevard']}, {'enum': ['NW', 'NE', 'SW', 'SE']}], 'type': 'array'}, format_checker=<FormatChecker checkers=['date', 'date-time', 'double', 'email', 'float', 'idn-email', 'int32', 'int64', 'ipv4', 'ipv6', 'password', 'regex', 'time', 'uuid']>)
openapi-schema-validator> validator_class = <class 'jsonschema.validators.create.<locals>.Validator'>
openapi-schema-validator> value      = [1600, 'Pennsylvania', 'Avenue', 'NW', 'Washington']
openapi-schema-validator> 
openapi-schema-validator> tests/integration/test_validators.py:867: AssertionError
@yan12125
Copy link

The failure is caused by newer jsonschema. In python-jsonschema/jsonschema@8cff13d, the error message is changed. To get through this test, I just changed the expected error message with:

diff --git a/tests/integration/test_validators.py b/tests/integration/test_validators.py
index 07bc4df..5663c4c 100644
--- a/tests/integration/test_validators.py
+++ b/tests/integration/test_validators.py
@@ -863,5 +863,5 @@ class TestOAS31ValidatorValidate(BaseTestOASValidatorValidate):
         with pytest.raises(ValidationError) as excinfo:
             validator.validate(value)
 
-        error = "Expected at most 4 items, but found 5"
+        error = "Expected at most 4 items but found 1 extra"
         assert error in str(excinfo.value)

Not sure if the maintainer wants to support both older and newer error messages or not.

@kloczek
Copy link

kloczek commented Mar 15, 2024

Have the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants