@@ -112,7 +112,7 @@ def test_beta_function() -> None:
112
112
113
113
doc = beta_function .__doc__
114
114
assert isinstance (doc , str )
115
- assert doc .startswith ("[*Beta*] original doc" )
115
+ assert doc .startswith ("[*Beta*] original doc" )
116
116
117
117
assert not inspect .iscoroutinefunction (beta_function )
118
118
@@ -132,7 +132,7 @@ async def test_beta_async_function() -> None:
132
132
133
133
doc = beta_function .__doc__
134
134
assert isinstance (doc , str )
135
- assert doc .startswith ("[*Beta*] original doc" )
135
+ assert doc .startswith ("[*Beta*] original doc" )
136
136
137
137
assert inspect .iscoroutinefunction (beta_async_function )
138
138
@@ -152,7 +152,7 @@ def test_beta_method() -> None:
152
152
153
153
doc = obj .beta_method .__doc__
154
154
assert isinstance (doc , str )
155
- assert doc .startswith ("[*Beta*] original doc" )
155
+ assert doc .startswith ("[*Beta*] original doc" )
156
156
157
157
assert not inspect .iscoroutinefunction (obj .beta_method )
158
158
@@ -173,7 +173,7 @@ async def test_beta_async_method() -> None:
173
173
174
174
doc = obj .beta_method .__doc__
175
175
assert isinstance (doc , str )
176
- assert doc .startswith ("[*Beta*] original doc" )
176
+ assert doc .startswith ("[*Beta*] original doc" )
177
177
178
178
assert inspect .iscoroutinefunction (obj .beta_async_method )
179
179
@@ -192,7 +192,7 @@ def test_beta_classmethod() -> None:
192
192
193
193
doc = ClassWithBetaMethods .beta_classmethod .__doc__
194
194
assert isinstance (doc , str )
195
- assert doc .startswith ("[*Beta*] original doc" )
195
+ assert doc .startswith ("[*Beta*] original doc" )
196
196
197
197
198
198
def test_beta_staticmethod () -> None :
@@ -211,7 +211,7 @@ def test_beta_staticmethod() -> None:
211
211
)
212
212
doc = ClassWithBetaMethods .beta_staticmethod .__doc__
213
213
assert isinstance (doc , str )
214
- assert doc .startswith ("[*Beta*] original doc" )
214
+ assert doc .startswith ("[*Beta*] original doc" )
215
215
216
216
217
217
def test_beta_property () -> None :
@@ -231,13 +231,12 @@ def test_beta_property() -> None:
231
231
)
232
232
doc = ClassWithBetaMethods .beta_property .__doc__
233
233
assert isinstance (doc , str )
234
- assert doc .startswith ("[*Beta*] original doc" )
234
+ assert doc .startswith ("[*Beta*] original doc" )
235
235
236
236
237
- def test_whole_class_deprecation () -> None :
238
- """Test whole class deprecation ."""
237
+ def test_whole_class_beta () -> None :
238
+ """Test whole class beta status ."""
239
239
240
- # Test whole class deprecation
241
240
@beta ()
242
241
class BetaClass :
243
242
def __init__ (self ) -> None :
@@ -269,6 +268,73 @@ def beta_method(self) -> str:
269
268
)
270
269
271
270
271
+ def test_whole_class_inherited_beta () -> None :
272
+ """Test whole class beta status for inherited class.
273
+
274
+ The original version of beta decorator created duplicates with
275
+ '[*Beta*]'.
276
+ """
277
+
278
+ # Test whole class beta status
279
+ @beta ()
280
+ class BetaClass :
281
+ @beta ()
282
+ def beta_method (self ) -> str :
283
+ """original doc"""
284
+ return "This is a beta method."
285
+
286
+ @beta ()
287
+ class InheritedBetaClass (BetaClass ):
288
+ @beta ()
289
+ def beta_method (self ) -> str :
290
+ """original doc"""
291
+ return "This is a beta method 2."
292
+
293
+ with warnings .catch_warnings (record = True ) as warning_list :
294
+ warnings .simplefilter ("always" )
295
+
296
+ obj = BetaClass ()
297
+ assert obj .beta_method () == "This is a beta method."
298
+
299
+ assert len (warning_list ) == 2
300
+ warning = warning_list [0 ].message
301
+ assert str (warning ) == (
302
+ "The class `BetaClass` is in beta. It is actively being worked on, so the "
303
+ "API may change."
304
+ )
305
+
306
+ warning = warning_list [1 ].message
307
+ assert str (warning ) == (
308
+ "The function `beta_method` is in beta. It is actively being worked on, so "
309
+ "the API may change."
310
+ )
311
+
312
+ with warnings .catch_warnings (record = True ) as warning_list :
313
+ warnings .simplefilter ("always" )
314
+
315
+ obj = InheritedBetaClass ()
316
+ assert obj .beta_method () == "This is a beta method 2."
317
+
318
+ assert len (warning_list ) == 2
319
+ warning = warning_list [0 ].message
320
+ assert str (warning ) == (
321
+ "The class `InheritedBetaClass` is in beta. "
322
+ "It is actively being worked on, so the "
323
+ "API may change."
324
+ )
325
+
326
+ warning = warning_list [1 ].message
327
+ assert str (warning ) == (
328
+ "The function `beta_method` is in beta. "
329
+ "It is actively being worked on, so "
330
+ "the API may change."
331
+ )
332
+
333
+ # if [*Beta*] was inserted only once:
334
+ if obj .__doc__ is not None :
335
+ assert obj .__doc__ .count ("[*Beta*]" ) == 1
336
+
337
+
272
338
# Tests with pydantic models
273
339
class MyModel (BaseModel ):
274
340
@beta ()
@@ -292,4 +358,4 @@ def test_beta_method_pydantic() -> None:
292
358
293
359
doc = obj .beta_method .__doc__
294
360
assert isinstance (doc , str )
295
- assert doc .startswith ("[*Beta*] original doc" )
361
+ assert doc .startswith ("[*Beta*] original doc" )
0 commit comments