Skip to content

Commit

Permalink
fix(web) issue2551382 - handle crash in request call in test
Browse files Browse the repository at this point in the history
due to invalid utf8 with surrogate. Ci reports this failure in the
requests call from the test case:

>           string = string.encode(encoding, errors)
E           UnicodeEncodeError: 'utf-8' codec can't encode character
'\ud800' in position 48: surrogates not allowed
E           Falsifying example:
test_class_url_param_accepting_integer_values(
E               self=<test.test_liveserver.FuzzGetUrls
testMethod=test_class_url_param_accepting_integer_values>,
E               param='@verbose',  # or any other generated value
E               value='\ud800',
E           )
E           Explanation:
E               These lines were always and only run by failing
examples:
E
/opt/hostedtoolcache/Python/3.13.1/x64/lib/python3.13/site-packages/requests/utils.py:675
E
E           You can reproduce this example by temporarily adding
@reproduce_failure('6.122.3', b'AAAAAQDXAA==') as a decorator on your
test case
  • Loading branch information
rouilj committed Dec 17, 2024
1 parent 9dfb1e5 commit 89c9814
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions test/test_liveserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
skip_hypothesis = lambda func, *args, **kwargs: func

# ruff: noqa: E402
from hypothesis import example, given, settings
from hypothesis import example, given, reproduce_failure, settings
from hypothesis.strategies import binary, characters, emails, none, one_of, sampled_from, text

except ImportError:
Expand All @@ -46,7 +46,7 @@ def noop_strategy(*args, **kwargs):
pass

# define the decorator functions
example = given = settings = noop_decorators_with_args
example = given = reproduce_failure = settings = noop_decorators_with_args
# and stratgies using in decorators
binary = characters = emails, none = one_of = sampled_from = text = noop_strategy

Expand Down Expand Up @@ -237,8 +237,7 @@ def test_class_url_param_accepting_integer_values(self, param, value):
# invalid value for param
self.assertEqual(f.status_code, 400)

@given(sampled_from(['@verbose']),
one_of(characters(),text(min_size=1)))
@given(sampled_from(['@verbose']), text(min_size=1))
@example("@verbose", "1#")
@settings(max_examples=_max_examples,
deadline=10000) # 10000ms
Expand Down

0 comments on commit 89c9814

Please sign in to comment.