Skip to content

Commit 3139251

Browse files
authored
expand allowed errors from hypothesis test for url parsing (#684)
1 parent e9e76b8 commit 3139251

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

tests/test_hypothesis.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ def url_validator():
143143
return SchemaValidator({'type': 'url'})
144144

145145

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+
146150
@given(strategies.text())
147151
def test_urls_text(url_validator, text):
148152
try:
@@ -151,10 +155,7 @@ def test_urls_text(url_validator, text):
151155
assert exc.error_count() == 1
152156
error = exc.errors(include_url=False)[0]
153157
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
158159

159160

160161
@pytest.fixture(scope='module')
@@ -170,10 +171,7 @@ def test_multi_host_urls_text(multi_host_url_validator, text):
170171
assert exc.error_count() == 1
171172
error = exc.errors(include_url=False)[0]
172173
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
177175

178176

179177
@pytest.fixture(scope='module')

0 commit comments

Comments
 (0)