@@ -143,6 +143,10 @@ def url_validator():
143
143
return SchemaValidator ({'type' : 'url' })
144
144
145
145
146
+ # Parsing errors which hypothesis is likely to hit
147
+ _URL_PARSE_ERRORS = {'input is empty' , 'relative URL without a base' , 'empty host' }
148
+
149
+
146
150
@given (strategies .text ())
147
151
def test_urls_text (url_validator , text ):
148
152
try :
@@ -151,10 +155,7 @@ def test_urls_text(url_validator, text):
151
155
assert exc .error_count () == 1
152
156
error = exc .errors (include_url = False )[0 ]
153
157
assert error ['type' ] == 'url_parsing'
154
- if len (text ) == 0 :
155
- assert error ['ctx' ]['error' ] == 'input is empty'
156
- else :
157
- assert error ['ctx' ]['error' ] == 'relative URL without a base'
158
+ assert error ['ctx' ]['error' ] in _URL_PARSE_ERRORS
158
159
159
160
160
161
@pytest .fixture (scope = 'module' )
@@ -170,10 +171,7 @@ def test_multi_host_urls_text(multi_host_url_validator, text):
170
171
assert exc .error_count () == 1
171
172
error = exc .errors (include_url = False )[0 ]
172
173
assert error ['type' ] == 'url_parsing'
173
- if len (text ) == 0 :
174
- assert error ['ctx' ]['error' ] == 'input is empty'
175
- else :
176
- assert error ['ctx' ]['error' ] == 'relative URL without a base'
174
+ assert error ['ctx' ]['error' ] in _URL_PARSE_ERRORS
177
175
178
176
179
177
@pytest .fixture (scope = 'module' )
0 commit comments