Fix failing hypothesis tests on the main branch (#3956)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Hood Chatham 2023-06-26 00:33:08 -07:00 committed by GitHub
parent 41b4276307
commit a7a98c75a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 4 deletions

View File

@ -1,4 +1,6 @@
# See also test_pyproxy, test_jsproxy, and test_python.
import io
import pickle
from typing import Any
import pytest
@ -14,6 +16,22 @@ from pytest_pyodide.hypothesis import (
)
class NoHypothesisUnpickler(pickle.Unpickler):
def find_class(self, module, name):
# Only allow safe classes from builtins.
if module == "hypothesis":
raise pickle.UnpicklingError()
return super().find_class(module, name)
def no_hypothesis(x):
try:
NoHypothesisUnpickler(io.BytesIO(pickle.dumps(x))).load()
return True
except Exception:
return False
@given(s=text())
@settings(deadline=10000)
@example("\ufeff")
@ -329,7 +347,7 @@ def test_big_int_conversions3(selenium_module_scope, n, exp):
main(selenium, s)
@given(obj=any_equal_to_self_strategy)
@given(obj=any_equal_to_self_strategy.filter(no_hypothesis))
@std_hypothesis_settings
@run_in_pyodide
def test_hyp_py2js2py(selenium, obj):
@ -356,7 +374,7 @@ def test_hyp_py2js2py(selenium, obj):
del __main__.obj
@given(obj=any_equal_to_self_strategy)
@given(obj=any_equal_to_self_strategy.filter(no_hypothesis))
@std_hypothesis_settings
@run_in_pyodide
def test_hyp_py2js2py_2(selenium, obj):
@ -389,7 +407,7 @@ def test_big_integer_py2js2py(selenium, a):
# Generate an object of any type
@pytest.mark.skip_refcount_check
@pytest.mark.skip_pyproxy_check
@given(obj=any_strategy)
@given(obj=any_strategy.filter(no_hypothesis))
@std_hypothesis_settings
@run_in_pyodide
def test_hyp_tojs_no_crash(selenium, obj):
@ -413,7 +431,7 @@ def test_hyp_tojs_no_crash(selenium, obj):
@pytest.mark.skip_refcount_check
@pytest.mark.skip_pyproxy_check
@given(obj=any_strategy)
@given(obj=any_strategy.filter(no_hypothesis))
@example(obj=range(0, 2147483648)) # length is too big to fit in ssize_t
@settings(
std_hypothesis_settings,