Skip to content

Commit 9fe52e9

Browse files
authored
gh-162671: Support selecting hypothesis tests by label (#162672)
1 parent 62a7400 commit 9fe52e9

6 files changed

Lines changed: 34 additions & 4 deletions

File tree

‎Lib/test/support/hypothesis_helper.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import os
22

3+
from test.support import mark
4+
35
try:
46
import hypothesis
57
except ImportError:
@@ -55,3 +57,5 @@
5557
),
5658
)
5759
hypothesis.settings.load_profile("cpython-local-dev")
60+
61+
mark_hypothesis = mark("hypothesis")

‎Lib/test/test_base64.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class LazyImportTest(unittest.TestCase):
1616
def test_lazy_import(self):
1717
ensure_lazy_imports("base64", {"re", "getopt"})
1818

19-
from test.support.hypothesis_helper import hypothesis
19+
from test.support.hypothesis_helper import hypothesis, mark_hypothesis
2020

2121

2222
class LegacyBase64TestCase(unittest.TestCase):
@@ -74,6 +74,7 @@ def test_decodebytes(self):
7474

7575
@hypothesis.given(payload=hypothesis.strategies.binary())
7676
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz')
77+
@mark_hypothesis
7778
def test_bytes_encode_decode_round_trip(self, payload):
7879
encoded = base64.encodebytes(payload)
7980
decoded = base64.decodebytes(encoded)
@@ -109,6 +110,7 @@ def test_decode(self):
109110

110111
@hypothesis.given(payload=hypothesis.strategies.binary())
111112
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz')
113+
@mark_hypothesis
112114
def test_legacy_encode_decode_round_trip(self, payload):
113115
from io import BytesIO
114116
payload_file_r = BytesIO(payload)
@@ -503,6 +505,7 @@ def _altchars_strategy():
503505
validate=hypothesis.strategies.booleans())
504506
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz', b"_-", True)
505507
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz', b"_-", False)
508+
@mark_hypothesis
506509
def test_b64_encode_decode_round_trip(self, payload, altchars, validate):
507510
encoded = base64.b64encode(payload, altchars=altchars)
508511
decoded = base64.b64decode(encoded, altchars=altchars,
@@ -511,13 +514,15 @@ def test_b64_encode_decode_round_trip(self, payload, altchars, validate):
511514

512515
@hypothesis.given(payload=hypothesis.strategies.binary())
513516
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz')
517+
@mark_hypothesis
514518
def test_standard_b64_encode_decode_round_trip(self, payload):
515519
encoded = base64.standard_b64encode(payload)
516520
decoded = base64.standard_b64decode(encoded)
517521
self.assertEqual(payload, decoded)
518522

519523
@hypothesis.given(payload=hypothesis.strategies.binary())
520524
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz')
525+
@mark_hypothesis
521526
def test_urlsafe_b64_encode_decode_round_trip(self, payload):
522527
encoded = base64.urlsafe_b64encode(payload)
523528
decoded = base64.urlsafe_b64decode(encoded)
@@ -701,6 +706,7 @@ def test_b32decode_error(self):
701706
| hypothesis.strategies.binary(min_size=1, max_size=1)))
702707
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz', True, None)
703708
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz', False, None)
709+
@mark_hypothesis
704710
def test_b32_encode_decode_round_trip(self, payload, casefold, map01):
705711
encoded = base64.b32encode(payload)
706712
decoded = base64.b32decode(encoded, casefold=casefold, map01=map01)
@@ -837,6 +843,7 @@ def test_b32hexdecode_error(self):
837843
casefold=hypothesis.strategies.booleans())
838844
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz', True)
839845
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz', False)
846+
@mark_hypothesis
840847
def test_b32_hexencode_decode_round_trip(self, payload, casefold):
841848
encoded = base64.b32hexencode(payload)
842849
decoded = base64.b32hexdecode(encoded, casefold=casefold)
@@ -899,6 +906,7 @@ def test_b16decode_ignorechars(self):
899906
casefold=hypothesis.strategies.booleans())
900907
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz', True)
901908
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz', False)
909+
@mark_hypothesis
902910
def test_b16_encode_decode_round_trip(self, payload, casefold):
903911
endoded = base64.b16encode(payload)
904912
decoded = base64.b16decode(endoded, casefold=casefold)
@@ -1321,6 +1329,7 @@ def add_padding(self, payload):
13211329
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz', False, 20, True, True)
13221330
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz', True, 0, False, True)
13231331
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz', True, 20, True, False)
1332+
@mark_hypothesis
13241333
def test_a85_encode_decode_round_trip(
13251334
self, payload, foldspaces, wrapcol, pad, adobe
13261335
):
@@ -1349,6 +1358,7 @@ def test_a85_encode_decode_round_trip(
13491358
pad=hypothesis.strategies.booleans())
13501359
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz', True)
13511360
@hypothesis.example(b'abcdefghijklmnopqrstuvwxyz', False)
1361+
@mark_hypothesis
13521362
def test_b85_encode_decode_round_trip(self, payload, pad):
13531363
encoded = base64.b85encode(payload, pad=pad)
13541364
if pad:

‎Lib/test/test_binascii.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import re
77
import sys
88
from test.support import bigmemtest, _1G, _4G, check_impl_detail
9-
from test.support.hypothesis_helper import hypothesis
9+
from test.support.hypothesis_helper import hypothesis, mark_hypothesis
1010

1111

1212
# Note: "*_hex" functions are aliases for "(un)hexlify"
@@ -420,6 +420,7 @@ def test_base64_canonical(self):
420420
@hypothesis.example(b'\x00')
421421
@hypothesis.example(b'\xff\xff')
422422
@hypothesis.example(b'abc')
423+
@mark_hypothesis
423424
def test_base64_canonical_roundtrip(self, payload):
424425
# The encoder must always produce canonical output.
425426
encoded = binascii.b2a_base64(payload, newline=False)
@@ -866,6 +867,7 @@ def test_base85_canonical(self):
866867
@hypothesis.example(b'\x00')
867868
@hypothesis.example(b'\xff\xff')
868869
@hypothesis.example(b'abc')
870+
@mark_hypothesis
869871
def test_base85_canonical_roundtrip(self, payload):
870872
encoded = binascii.b2a_base85(payload)
871873
decoded = binascii.a2b_base85(encoded, canonical=True)
@@ -875,6 +877,7 @@ def test_base85_canonical_roundtrip(self, payload):
875877
@hypothesis.example(b'\x00')
876878
@hypothesis.example(b'\xff')
877879
@hypothesis.example(b'ab\x00')
880+
@mark_hypothesis
878881
def test_base85_canonical_unique(self, payload):
879882
# For a partial group, sweeping all 85 last-digit values should
880883
# yield exactly one encoding that both decodes to the original
@@ -953,6 +956,7 @@ def test_ascii85_canonical(self):
953956
@hypothesis.example(b'\x00\x00\x00\x00') # triggers z abbreviation
954957
@hypothesis.example(b'\xff\xff')
955958
@hypothesis.example(b'abc')
959+
@mark_hypothesis
956960
def test_ascii85_canonical_roundtrip(self, payload):
957961
encoded = binascii.b2a_ascii85(payload)
958962
decoded = binascii.a2b_ascii85(encoded, canonical=True)
@@ -962,6 +966,7 @@ def test_ascii85_canonical_roundtrip(self, payload):
962966
@hypothesis.example(b'\x00')
963967
@hypothesis.example(b'\xff')
964968
@hypothesis.example(b'ab\x00')
969+
@mark_hypothesis
965970
def test_ascii85_canonical_unique(self, payload):
966971
hypothesis.assume(len(payload) % 4 != 0)
967972
canonical_enc = binascii.b2a_ascii85(payload)
@@ -1189,6 +1194,7 @@ def test_base32_canonical(self):
11891194
@hypothesis.example(b'\x00')
11901195
@hypothesis.example(b'\xff\xff')
11911196
@hypothesis.example(b'abc')
1197+
@mark_hypothesis
11921198
def test_base32_canonical_roundtrip(self, payload):
11931199
encoded = binascii.b2a_base32(payload)
11941200
decoded = binascii.a2b_base32(encoded, canonical=True)
@@ -1331,6 +1337,7 @@ def test_uu(self):
13311337
binary=hypothesis.strategies.binary(max_size=45),
13321338
backtick=hypothesis.strategies.booleans(),
13331339
)
1340+
@mark_hypothesis
13341341
def test_b2a_roundtrip(self, binary, backtick):
13351342
converted = binascii.b2a_uu(self.type2test(binary), backtick=backtick)
13361343
restored = binascii.a2b_uu(self.type2test(converted))
@@ -1374,6 +1381,7 @@ def test_hex(self):
13741381
self.assertEqual(binascii.unhexlify(self.type2test(t)), u)
13751382

13761383
@hypothesis.given(binary=hypothesis.strategies.binary())
1384+
@mark_hypothesis
13771385
def test_hex_roundtrip(self, binary):
13781386
converted = binascii.hexlify(self.type2test(binary))
13791387
restored = binascii.unhexlify(self.type2test(converted))
@@ -1527,6 +1535,7 @@ def test_qp(self):
15271535
istext=hypothesis.strategies.booleans(),
15281536
header=hypothesis.strategies.booleans(),
15291537
)
1538+
@mark_hypothesis
15301539
def test_b2a_qp_a2b_qp_round_trip(self, binary, quotetabs, istext, header):
15311540
converted = binascii.b2a_qp(
15321541
self.type2test(binary),
@@ -1624,6 +1633,7 @@ def test_b2a_base64_wrapcol(self):
16241633
binary=hypothesis.strategies.binary(),
16251634
newline=hypothesis.strategies.booleans(),
16261635
)
1636+
@mark_hypothesis
16271637
def test_base64_roundtrip(self, binary, newline):
16281638
converted = binascii.b2a_base64(self.type2test(binary), newline=newline)
16291639
restored = binascii.a2b_base64(self.type2test(converted))

‎Lib/test/test_math_property.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import functools
22
import unittest
33
from math import isnan, nextafter
4-
from test.support import requires_IEEE_754
4+
from test.support import requires_IEEE_754, mark_module
55
from test.support.hypothesis_helper import hypothesis
66

7+
mark_module('hypothesis')
8+
79
floats = hypothesis.strategies.floats
810
integers = hypothesis.strategies.integers
911

‎Lib/test/test_tools/test_makeunicodedata.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import unittest
22
from test.test_tools import skip_if_missing, imports_under_tool
33
from test import support
4-
from test.support.hypothesis_helper import hypothesis
4+
from test.support.hypothesis_helper import hypothesis, mark_hypothesis
55

66
st = hypothesis.strategies
77
given = hypothesis.given
@@ -115,6 +115,7 @@ def test_forbid_empty_dawg(self):
115115
("ab", "1"),
116116
]
117117
)
118+
@mark_hypothesis
118119
def test_dawg(self, data):
119120
# suppress debug prints
120121
with support.captured_stdout() as output:

‎Lib/test/test_zoneinfo/test_zoneinfo_property.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
import unittest
66
import zoneinfo
77

8+
from test.support import mark_module
89
from test.support.hypothesis_helper import hypothesis
910

1011
import test.test_zoneinfo._support as test_support
1112

13+
mark_module('hypothesis')
14+
1215
ZoneInfoTestBase = test_support.ZoneInfoTestBase
1316

1417
py_zoneinfo, c_zoneinfo = test_support.get_modules()

0 commit comments

Comments
 (0)