Skip to content

Commit db2a54b

Browse files
committed
Tighter format-strategy checks
Always check that examples are strings, even for unknown formats or in -O mode.
1 parent 1c5f107 commit db2a54b

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/hypothesis_jsonschema/_from_schema.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,10 @@ def _get_format_filter(
9797
) -> st.SearchStrategy[str]:
9898
def check_valid(string: str) -> str:
9999
try:
100-
assert isinstance(string, str)
100+
if not isinstance(string, str):
101+
raise jsonschema.FormatError(f"{string!r} is not a string")
101102
checker.check(string, format=format_name)
102-
except (AssertionError, jsonschema.FormatError) as err:
103+
except jsonschema.FormatError as err:
103104
raise InvalidArgument(
104105
f"Got string={string!r} from strategy {strategy!r}, but this "
105106
f"is not a valid value for the {format_name!r} checker."
@@ -136,8 +137,6 @@ def __from_schema(
136137
format_checker = jsonschema.FormatChecker()
137138
custom_formats = {
138139
name: _get_format_filter(name, format_checker, strategy)
139-
if name in format_checker.checkers
140-
else strategy
141140
for name, strategy in custom_formats.items()
142141
}
143142
custom_formats[_FORMATS_TOKEN] = None # type: ignore

0 commit comments

Comments
 (0)