33"""
44Testing strategies for Hypothesis-based tests.
55"""
6-
6+ import functools
77import keyword
88import string
99
@@ -111,13 +111,19 @@ def simple_attrs_with_metadata(draw):
111111
112112simple_attrs = simple_attrs_without_metadata | simple_attrs_with_metadata ()
113113
114+
114115# Python functions support up to 255 arguments.
115116list_of_attrs = st .lists (simple_attrs , max_size = 3 )
116117
117118
118119@st .composite
119120def simple_classes (
120- draw , slots = None , frozen = None , weakref_slot = None , private_attrs = None
121+ draw ,
122+ slots = None ,
123+ frozen = None ,
124+ weakref_slot = None ,
125+ private_attrs = None ,
126+ cached_property = None ,
121127):
122128 """
123129 A strategy that generates classes with default non-attr attributes.
@@ -157,6 +163,7 @@ class HypClass:
157163 pre_init_flag = draw (st .booleans ())
158164 post_init_flag = draw (st .booleans ())
159165 init_flag = draw (st .booleans ())
166+ cached_property_flag = draw (st .booleans ())
160167
161168 if pre_init_flag :
162169
@@ -179,9 +186,20 @@ def init(self, *args, **kwargs):
179186
180187 cls_dict ["__init__" ] = init
181188
189+ bases = (object ,)
190+ if cached_property or (cached_property is None and cached_property_flag ):
191+
192+ class BaseWithCachedProperty :
193+ @functools .cached_property
194+ def _cached_property (self ) -> int :
195+ return 1
196+
197+ bases = (BaseWithCachedProperty ,)
198+
182199 return make_class (
183200 "HypClass" ,
184201 cls_dict ,
202+ bases = bases ,
185203 slots = slots_flag if slots is None else slots ,
186204 frozen = frozen_flag if frozen is None else frozen ,
187205 weakref_slot = weakref_flag if weakref_slot is None else weakref_slot ,
0 commit comments