|
| 1 | +import re |
1 | 2 | import warnings |
2 | 3 | from base64 import b64encode |
3 | 4 | from typing import Any |
|
30 | 31 | from openapi_schema_validator import oas30_strict_format_checker |
31 | 32 | from openapi_schema_validator import oas31_format_checker |
32 | 33 | from openapi_schema_validator import oas32_format_checker |
| 34 | +from openapi_schema_validator import validate |
33 | 35 | from openapi_schema_validator._dialects import OAS31_BASE_DIALECT_ID |
34 | 36 | from openapi_schema_validator._dialects import OAS31_BASE_DIALECT_METASCHEMA |
35 | 37 | from openapi_schema_validator._dialects import OAS32_BASE_DIALECT_ID |
@@ -124,6 +126,21 @@ def test_string_invalid(self, validator_class, value): |
124 | 126 | with pytest.raises(ValidationError): |
125 | 127 | validator.validate(value) |
126 | 128 |
|
| 129 | + def test_invalid_pattern_raises_regex_error(self, validator_class): |
| 130 | + schema = {"type": "string", "pattern": "["} |
| 131 | + validator = validator_class(schema) |
| 132 | + |
| 133 | + with pytest.raises(re.error): |
| 134 | + validator.validate("foo") |
| 135 | + |
| 136 | + def test_invalid_pattern_rejected_by_validate_helper( |
| 137 | + self, validator_class |
| 138 | + ): |
| 139 | + schema = {"type": "string", "pattern": "["} |
| 140 | + |
| 141 | + with pytest.raises(SchemaError, match="is not a 'regex'"): |
| 142 | + validate("foo", schema, cls=validator_class) |
| 143 | + |
127 | 144 | def test_referencing(self, validator_class): |
128 | 145 | name_schema = Resource.from_contents( |
129 | 146 | { |
|
0 commit comments