MCPcopy
hub / github.com/python-attrs/attrs / test_kw_only

Method test_kw_only

tests/test_make.py:251–297  ·  view source on GitHub ↗

Converts all attributes in the current class if `kw_only` is provided. Base class attributes are **not** affected.

(self)

Source from the content-addressed store, hash-verified

249 ) == e.value.args
250
251 def test_kw_only(self):
252 """
253 Converts all attributes in the current class if `kw_only` is provided.
254 Base class attributes are **not** affected.
255 """
256
257 @attr.s
258 class B:
259 b = attr.ib()
260
261 for b_a in B.__attrs_attrs__:
262 assert b_a.kw_only is False
263
264 class C(B):
265 x = attr.ib(default=None)
266 y = attr.ib()
267
268 attrs, base_attrs, _ = _transform_attrs(
269 C, None, False, ClassProps.KeywordOnly.YES, True, None
270 )
271
272 assert len(attrs) == 3
273 assert len(base_attrs) == 1
274
275 for a in attrs:
276 if a.name == "b":
277 assert a.kw_only is False
278 else:
279 assert a.kw_only is True
280
281 attrs, base_attrs, _ = _transform_attrs(
282 C,
283 None,
284 False,
285 ClassProps.KeywordOnly.FORCE,
286 True,
287 None,
288 )
289
290 assert len(attrs) == 3
291 assert len(base_attrs) == 1
292
293 for a in attrs:
294 assert a.kw_only is True
295
296 for b_a in B.__attrs_attrs__:
297 assert b_a.kw_only is False
298
299 def test_these(self):
300 """

Callers

nothing calls this directly

Calls 1

_transform_attrsFunction · 0.90

Tested by

no test coverage detected