Skip to content

Commit 68c0b6b

Browse files
committed
gh-162671: Support selecting hypothesis tests by label
1 parent b0b0005 commit 68c0b6b

6 files changed

Lines changed: 48 additions & 5 deletions

File tree

‎Lib/test/support/hypothesis_helper.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,9 @@
5555
),
5656
)
5757
hypothesis.settings.load_profile("cpython-local-dev")
58+
59+
60+
def mark_hypothesis(func):
61+
from test.support import mark
62+
63+
return mark("hypothesis")(func)

‎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
@@ -2,7 +2,7 @@
22
import unittest
33
from math import isnan, nextafter
44
from test.support import requires_IEEE_754
5-
from test.support.hypothesis_helper import hypothesis
5+
from test.support.hypothesis_helper import hypothesis, mark_hypothesis
66

77
floats = hypothesis.strategies.floats
88
integers = hypothesis.strategies.integers
@@ -22,6 +22,7 @@ class NextafterTests(unittest.TestCase):
2222
x=floats(),
2323
y=floats(),
2424
steps=integers(min_value=0, max_value=2**16))
25+
@mark_hypothesis
2526
def test_count(self, x, y, steps):
2627
assert_equal_float(via_reduce(x, y, steps),
2728
nextafter(x, y, steps=steps))
@@ -32,6 +33,7 @@ def test_count(self, x, y, steps):
3233
y=floats(),
3334
a=integers(min_value=0),
3435
b=integers(min_value=0))
36+
@mark_hypothesis
3537
def test_addition_commutes(self, x, y, a, b):
3638
first = nextafter(x, y, steps=a)
3739
second = nextafter(first, y, steps=b)

‎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: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import unittest
66
import zoneinfo
77

8-
from test.support.hypothesis_helper import hypothesis
8+
from test.support.hypothesis_helper import hypothesis, mark_hypothesis
99

1010
import test.test_zoneinfo._support as test_support
1111

@@ -96,12 +96,14 @@ class ZoneInfoTest(ZoneInfoTestBase):
9696

9797
@hypothesis.given(key=valid_keys())
9898
@add_key_examples
99+
@mark_hypothesis
99100
def test_str(self, key):
100101
zi = self.klass(key)
101102
self.assertEqual(str(zi), key)
102103

103104
@hypothesis.given(key=valid_keys())
104105
@add_key_examples
106+
@mark_hypothesis
105107
def test_key(self, key):
106108
zi = self.klass(key)
107109

@@ -119,6 +121,7 @@ def test_key(self, key):
119121
@hypothesis.example(dt=datetime.time(0))
120122
@hypothesis.example(dt=datetime.time(12, 0))
121123
@hypothesis.example(dt=datetime.time(23, 59, 59, 999999))
124+
@mark_hypothesis
122125
def test_utc(self, dt):
123126
zi = self.klass("UTC")
124127
dt_zi = dt.replace(tzinfo=zi)
@@ -144,6 +147,7 @@ def setUp(self):
144147

145148
@hypothesis.given(key=valid_keys())
146149
@add_key_examples
150+
@mark_hypothesis
147151
def test_pickle_unpickle_cache(self, key):
148152
zi = self.klass(key)
149153
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
@@ -154,6 +158,7 @@ def test_pickle_unpickle_cache(self, key):
154158

155159
@hypothesis.given(key=valid_keys())
156160
@add_key_examples
161+
@mark_hypothesis
157162
def test_pickle_unpickle_no_cache(self, key):
158163
zi = self.klass.no_cache(key)
159164
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
@@ -165,6 +170,7 @@ def test_pickle_unpickle_no_cache(self, key):
165170

166171
@hypothesis.given(key=valid_keys())
167172
@add_key_examples
173+
@mark_hypothesis
168174
def test_pickle_unpickle_cache_multiple_rounds(self, key):
169175
"""Test that pickle/unpickle is idempotent."""
170176
zi_0 = self.klass(key)
@@ -183,6 +189,7 @@ def test_pickle_unpickle_cache_multiple_rounds(self, key):
183189

184190
@hypothesis.given(key=valid_keys())
185191
@add_key_examples
192+
@mark_hypothesis
186193
def test_pickle_unpickle_no_cache_multiple_rounds(self, key):
187194
"""Test that pickle/unpickle is idempotent."""
188195
zi_cache = self.klass(key)
@@ -215,6 +222,7 @@ class ZoneInfoCacheTest(ZoneInfoTestBase):
215222

216223
@hypothesis.given(key=valid_keys())
217224
@add_key_examples
225+
@mark_hypothesis
218226
def test_cache(self, key):
219227
zi_0 = self.klass(key)
220228
zi_1 = self.klass(key)
@@ -223,6 +231,7 @@ def test_cache(self, key):
223231

224232
@hypothesis.given(key=valid_keys())
225233
@add_key_examples
234+
@mark_hypothesis
226235
def test_no_cache(self, key):
227236
zi_0 = self.klass.no_cache(key)
228237
zi_1 = self.klass.no_cache(key)
@@ -246,6 +255,7 @@ def _is_ambiguous(self, dt):
246255
@hypothesis.example(dt=datetime.datetime(1970, 1, 1), key="America/New_York")
247256
@hypothesis.example(dt=datetime.datetime(2020, 1, 1), key="Europe/Paris")
248257
@hypothesis.example(dt=datetime.datetime(2020, 6, 1), key="Europe/Paris")
258+
@mark_hypothesis
249259
def test_same_str(self, dt, key):
250260
py_dt = dt.replace(tzinfo=py_zoneinfo.ZoneInfo(key))
251261
c_dt = dt.replace(tzinfo=c_zoneinfo.ZoneInfo(key))
@@ -261,6 +271,7 @@ def test_same_str(self, dt, key):
261271
@hypothesis.example(dt=datetime.datetime(2040, 1, 1), key="Europe/Paris")
262272
@hypothesis.example(dt=datetime.datetime.min, key="Asia/Tokyo")
263273
@hypothesis.example(dt=datetime.datetime.max, key="Asia/Tokyo")
274+
@mark_hypothesis
264275
def test_same_offsets_and_names(self, dt, key):
265276
py_dt = dt.replace(tzinfo=py_zoneinfo.ZoneInfo(key))
266277
c_dt = dt.replace(tzinfo=c_zoneinfo.ZoneInfo(key))
@@ -281,6 +292,7 @@ def test_same_offsets_and_names(self, dt, key):
281292
dt=datetime.datetime(2006, 10, 29, 5, 15, tzinfo=UTC),
282293
key="America/New_York",
283294
)
295+
@mark_hypothesis
284296
def test_same_from_utc(self, dt, key):
285297
py_zi = py_zoneinfo.ZoneInfo(key)
286298
c_zi = c_zoneinfo.ZoneInfo(key)
@@ -322,6 +334,7 @@ def test_same_from_utc(self, dt, key):
322334
@hypothesis.example(dt=datetime.datetime.min, key="America/New_York")
323335
@hypothesis.example(dt=datetime.datetime.min, key="Asia/Tokyo")
324336
@hypothesis.example(dt=datetime.datetime.max, key="Asia/Tokyo")
337+
@mark_hypothesis
325338
def test_same_to_utc(self, dt, key):
326339
py_dt = dt.replace(tzinfo=py_zoneinfo.ZoneInfo(key))
327340
c_dt = dt.replace(tzinfo=c_zoneinfo.ZoneInfo(key))
@@ -349,6 +362,7 @@ def test_same_to_utc(self, dt, key):
349362

350363
@hypothesis.given(key=valid_keys())
351364
@add_key_examples
365+
@mark_hypothesis
352366
def test_cross_module_pickle(self, key):
353367
py_zi = py_zoneinfo.ZoneInfo(key)
354368
c_zi = c_zoneinfo.ZoneInfo(key)

0 commit comments

Comments
 (0)