Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Lib/test/support/hypothesis_helper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os

from test.support import mark

try:
import hypothesis
except ImportError:
Expand Down Expand Up @@ -51,3 +53,5 @@
),
)
hypothesis.settings.load_profile("cpython-local-dev")

mark_hypothesis = mark("hypothesis")
12 changes: 11 additions & 1 deletion Lib/test/test_base64.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class LazyImportTest(unittest.TestCase):
def test_lazy_import(self):
ensure_lazy_imports("base64", {"re", "getopt"})

from test.support.hypothesis_helper import hypothesis
from test.support.hypothesis_helper import hypothesis, mark_hypothesis


class LegacyBase64TestCase(unittest.TestCase):
Expand Down Expand Up @@ -74,6 +74,7 @@ def test_decodebytes(self):

@hypothesis.given(payload=hypothesis.strategies.binary())
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz')
@mark_hypothesis
def test_bytes_encode_decode_round_trip(self, payload):
encoded = base64.encodebytes(payload)
decoded = base64.decodebytes(encoded)
Expand Down Expand Up @@ -109,6 +110,7 @@ def test_decode(self):

@hypothesis.given(payload=hypothesis.strategies.binary())
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz')
@mark_hypothesis
def test_legacy_encode_decode_round_trip(self, payload):
from io import BytesIO
payload_file_r = BytesIO(payload)
Expand Down Expand Up @@ -503,6 +505,7 @@ def _altchars_strategy():
validate=hypothesis.strategies.booleans())
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz', b"_-", True)
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz', b"_-", False)
@mark_hypothesis
def test_b64_encode_decode_round_trip(self, payload, altchars, validate):
encoded = base64.b64encode(payload, altchars=altchars)
decoded = base64.b64decode(encoded, altchars=altchars,
Expand All @@ -511,13 +514,15 @@ def test_b64_encode_decode_round_trip(self, payload, altchars, validate):

@hypothesis.given(payload=hypothesis.strategies.binary())
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz')
@mark_hypothesis
def test_standard_b64_encode_decode_round_trip(self, payload):
encoded = base64.standard_b64encode(payload)
decoded = base64.standard_b64decode(encoded)
self.assertEqual(payload, decoded)

@hypothesis.given(payload=hypothesis.strategies.binary())
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz')
@mark_hypothesis
def test_urlsafe_b64_encode_decode_round_trip(self, payload):
encoded = base64.urlsafe_b64encode(payload)
decoded = base64.urlsafe_b64decode(encoded)
Expand Down Expand Up @@ -701,6 +706,7 @@ def test_b32decode_error(self):
| hypothesis.strategies.binary(min_size=1, max_size=1)))
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz', True, None)
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz', False, None)
@mark_hypothesis
def test_b32_encode_decode_round_trip(self, payload, casefold, map01):
encoded = base64.b32encode(payload)
decoded = base64.b32decode(encoded, casefold=casefold, map01=map01)
Expand Down Expand Up @@ -837,6 +843,7 @@ def test_b32hexdecode_error(self):
casefold=hypothesis.strategies.booleans())
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz', True)
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz', False)
@mark_hypothesis
def test_b32_hexencode_decode_round_trip(self, payload, casefold):
encoded = base64.b32hexencode(payload)
decoded = base64.b32hexdecode(encoded, casefold=casefold)
Expand Down Expand Up @@ -899,6 +906,7 @@ def test_b16decode_ignorechars(self):
casefold=hypothesis.strategies.booleans())
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz', True)
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz', False)
@mark_hypothesis
def test_b16_encode_decode_round_trip(self, payload, casefold):
endoded = base64.b16encode(payload)
decoded = base64.b16decode(endoded, casefold=casefold)
Expand Down Expand Up @@ -1321,6 +1329,7 @@ def add_padding(self, payload):
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz', False, 20, True, True)
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz', True, 0, False, True)
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz', True, 20, True, False)
@mark_hypothesis
def test_a85_encode_decode_round_trip(
self, payload, foldspaces, wrapcol, pad, adobe
):
Expand Down Expand Up @@ -1349,6 +1358,7 @@ def test_a85_encode_decode_round_trip(
pad=hypothesis.strategies.booleans())
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz', True)
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz', False)
@mark_hypothesis
def test_b85_encode_decode_round_trip(self, payload, pad):
encoded = base64.b85encode(payload, pad=pad)
if pad:
Expand Down
12 changes: 11 additions & 1 deletion Lib/test/test_binascii.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import re
import sys
from test.support import bigmemtest, _1G, _4G, check_impl_detail
from test.support.hypothesis_helper import hypothesis
from test.support.hypothesis_helper import hypothesis, mark_hypothesis


# Note: "*_hex" functions are aliases for "(un)hexlify"
Expand Down Expand Up @@ -420,6 +420,7 @@ def test_base64_canonical(self):
@hypothesis.example(b'\x00')
@hypothesis.example(b'\xff\xff')
@hypothesis.example(b'abc')
@mark_hypothesis
def test_base64_canonical_roundtrip(self, payload):
# The encoder must always produce canonical output.
encoded = binascii.b2a_base64(payload, newline=False)
Expand Down Expand Up @@ -866,6 +867,7 @@ def test_base85_canonical(self):
@hypothesis.example(b'\x00')
@hypothesis.example(b'\xff\xff')
@hypothesis.example(b'abc')
@mark_hypothesis
def test_base85_canonical_roundtrip(self, payload):
encoded = binascii.b2a_base85(payload)
decoded = binascii.a2b_base85(encoded, canonical=True)
Expand All @@ -875,6 +877,7 @@ def test_base85_canonical_roundtrip(self, payload):
@hypothesis.example(b'\x00')
@hypothesis.example(b'\xff')
@hypothesis.example(b'ab\x00')
@mark_hypothesis
def test_base85_canonical_unique(self, payload):
# For a partial group, sweeping all 85 last-digit values should
# yield exactly one encoding that both decodes to the original
Expand Down Expand Up @@ -953,6 +956,7 @@ def test_ascii85_canonical(self):
@hypothesis.example(b'\x00\x00\x00\x00') # triggers z abbreviation
@hypothesis.example(b'\xff\xff')
@hypothesis.example(b'abc')
@mark_hypothesis
def test_ascii85_canonical_roundtrip(self, payload):
encoded = binascii.b2a_ascii85(payload)
decoded = binascii.a2b_ascii85(encoded, canonical=True)
Expand All @@ -962,6 +966,7 @@ def test_ascii85_canonical_roundtrip(self, payload):
@hypothesis.example(b'\x00')
@hypothesis.example(b'\xff')
@hypothesis.example(b'ab\x00')
@mark_hypothesis
def test_ascii85_canonical_unique(self, payload):
hypothesis.assume(len(payload) % 4 != 0)
canonical_enc = binascii.b2a_ascii85(payload)
Expand Down Expand Up @@ -1189,6 +1194,7 @@ def test_base32_canonical(self):
@hypothesis.example(b'\x00')
@hypothesis.example(b'\xff\xff')
@hypothesis.example(b'abc')
@mark_hypothesis
def test_base32_canonical_roundtrip(self, payload):
encoded = binascii.b2a_base32(payload)
decoded = binascii.a2b_base32(encoded, canonical=True)
Expand Down Expand Up @@ -1331,6 +1337,7 @@ def test_uu(self):
binary=hypothesis.strategies.binary(max_size=45),
backtick=hypothesis.strategies.booleans(),
)
@mark_hypothesis
def test_b2a_roundtrip(self, binary, backtick):
converted = binascii.b2a_uu(self.type2test(binary), backtick=backtick)
restored = binascii.a2b_uu(self.type2test(converted))
Expand Down Expand Up @@ -1374,6 +1381,7 @@ def test_hex(self):
self.assertEqual(binascii.unhexlify(self.type2test(t)), u)

@hypothesis.given(binary=hypothesis.strategies.binary())
@mark_hypothesis
def test_hex_roundtrip(self, binary):
converted = binascii.hexlify(self.type2test(binary))
restored = binascii.unhexlify(self.type2test(converted))
Expand Down Expand Up @@ -1508,6 +1516,7 @@ def test_qp(self):
istext=hypothesis.strategies.booleans(),
header=hypothesis.strategies.booleans(),
)
@mark_hypothesis
def test_b2a_qp_a2b_qp_round_trip(self, binary, quotetabs, istext, header):
converted = binascii.b2a_qp(
self.type2test(binary),
Expand Down Expand Up @@ -1605,6 +1614,7 @@ def test_b2a_base64_wrapcol(self):
binary=hypothesis.strategies.binary(),
newline=hypothesis.strategies.booleans(),
)
@mark_hypothesis
def test_base64_roundtrip(self, binary, newline):
converted = binascii.b2a_base64(self.type2test(binary), newline=newline)
restored = binascii.a2b_base64(self.type2test(converted))
Expand Down
4 changes: 3 additions & 1 deletion Lib/test/test_math_property.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import functools
import unittest
from math import isnan, nextafter
from test.support import requires_IEEE_754
from test.support import requires_IEEE_754, mark_module
from test.support.hypothesis_helper import hypothesis

mark_module('hypothesis')

floats = hypothesis.strategies.floats
integers = hypothesis.strategies.integers

Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_tools/test_makeunicodedata.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
from test.test_tools import skip_if_missing, imports_under_tool
from test import support
from test.support.hypothesis_helper import hypothesis
from test.support.hypothesis_helper import hypothesis, mark_hypothesis

st = hypothesis.strategies
given = hypothesis.given
Expand Down Expand Up @@ -115,6 +115,7 @@ def test_forbid_empty_dawg(self):
("ab", "1"),
]
)
@mark_hypothesis
def test_dawg(self, data):
# suppress debug prints
with support.captured_stdout() as output:
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_zoneinfo/test_zoneinfo_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import unittest
import zoneinfo

from test.support import mark_module
from test.support.hypothesis_helper import hypothesis

import test.test_zoneinfo._support as test_support

mark_module('hypothesis')

ZoneInfoTestBase = test_support.ZoneInfoTestBase

py_zoneinfo, c_zoneinfo = test_support.get_modules()
Expand Down
Loading