From 89c98145dc42d1388f9122838bae6fb9e340a953 Mon Sep 17 00:00:00 2001 From: John Rouillard Date: Mon, 16 Dec 2024 19:19:07 -0500 Subject: [PATCH] fix(web) issue2551382 - handle crash in request call in test 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=, 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 --- test/test_liveserver.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/test_liveserver.py b/test/test_liveserver.py index f4796856..9d9e1649 100644 --- a/test/test_liveserver.py +++ b/test/test_liveserver.py @@ -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: @@ -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 @@ -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