17
17
import pytest
18
18
19
19
from hypothesis import given , infer , settings , strategies as st
20
- from hypothesis .errors import (
21
- HypothesisDeprecationWarning ,
22
- InvalidArgument ,
23
- ResolutionFailed ,
24
- )
20
+ from hypothesis .errors import InvalidArgument , ResolutionFailed
25
21
from hypothesis .internal .compat import get_type_hints
26
22
from hypothesis .internal .reflection import get_pretty_function_description
27
23
from hypothesis .strategies ._internal import types
24
+ from hypothesis .strategies ._internal .lazy import LazyStrategy
28
25
from hypothesis .strategies ._internal .types import _global_type_lookup
29
26
from hypothesis .strategies ._internal .utils import _strategies
30
27
36
33
)
37
34
from tests .common .utils import fails_with , temp_registered
38
35
39
- # Build a set of all types output by core strategies
40
- blocklist = {
41
- "builds" ,
42
- "data" ,
43
- "deferred" ,
44
- "from_regex" ,
45
- "from_type" ,
46
- "ip_addresses" ,
47
- "iterables" ,
48
- "just" ,
49
- "nothing" ,
50
- "one_of" ,
51
- "permutations" ,
52
- "random_module" ,
53
- "randoms" ,
54
- "recursive" ,
55
- "runner" ,
56
- "sampled_from" ,
57
- "shared" ,
58
- "timezone_keys" ,
59
- "timezones" ,
36
+ types_with_core_strat = {
37
+ type_
38
+ for type_ , strat in _global_type_lookup .items ()
39
+ if isinstance (strat , LazyStrategy ) and strat .function in vars (st ).values ()
60
40
}
61
- assert set (_strategies ).issuperset (blocklist ), blocklist .difference (_strategies )
62
- types_with_core_strat = set ()
63
- for thing in (
64
- getattr (st , name )
65
- for name in sorted (_strategies )
66
- if name in dir (st ) and name not in blocklist
67
- ):
68
- for n in range (3 ):
69
- try :
70
- ex = find_any (thing (* ([st .nothing ()] * n )))
71
- types_with_core_strat .add (type (ex ))
72
- break
73
- except (TypeError , InvalidArgument , HypothesisDeprecationWarning ):
74
- continue
75
41
76
42
77
43
@pytest .mark .skipif (sys .version_info [:2 ] >= (3 , 14 ), reason = "FIXME-py314" )
@@ -91,7 +57,44 @@ def inner(ex):
91
57
92
58
93
59
def test_lookup_knows_about_all_core_strategies ():
94
- cannot_lookup = types_with_core_strat - set (types ._global_type_lookup )
60
+ # Build a set of all types output by core strategies
61
+ blocklist = {
62
+ "builds" ,
63
+ "data" ,
64
+ "deferred" ,
65
+ "from_regex" ,
66
+ "from_type" ,
67
+ "ip_addresses" ,
68
+ "iterables" ,
69
+ "just" ,
70
+ "nothing" ,
71
+ "one_of" ,
72
+ "permutations" ,
73
+ "random_module" ,
74
+ "randoms" ,
75
+ "recursive" ,
76
+ "runner" ,
77
+ "sampled_from" ,
78
+ "shared" ,
79
+ "timezone_keys" ,
80
+ "timezones" ,
81
+ }
82
+ assert set (_strategies ).issuperset (blocklist ), blocklist .difference (_strategies )
83
+ found = set ()
84
+ for thing in (
85
+ getattr (st , name )
86
+ for name in sorted (_strategies )
87
+ if name in dir (st ) and name not in blocklist
88
+ ):
89
+ for n in range (3 ):
90
+ try :
91
+ ex = find_any (thing (* ([st .nothing ()] * n )))
92
+ found .add (type (ex ))
93
+ break
94
+ except Exception :
95
+ continue
96
+
97
+ cannot_lookup = found - set (types ._global_type_lookup )
95
98
assert not cannot_lookup
96
99
97
100
0 commit comments