Skip to content

Commit ddcf8b6

Browse files
committed
Fix more tests
1 parent f2ebb50 commit ddcf8b6

3 files changed

Lines changed: 23 additions & 21 deletions

File tree

tests/test_gen_dict.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def test_type_names_with_quotes():
327327
assert converter.structure({1: 1}, Dict[Annotated[int, "'"], int]) == {1: 1}
328328

329329
converter.register_structure_hook_func(
330-
lambda t: t is Union[Literal["a", 2, 3], Literal[4]], lambda v, _: v
330+
lambda t: t == Union[Literal["a", 2, 3], Literal[4]], lambda v, _: v
331331
)
332332
assert converter.structure(
333333
{2: "a"}, Dict[Union[Literal["a", 2, 3], Literal[4]], str]

tests/untyped.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
Tuple,
1919
)
2020

21-
import attr
21+
from attr import attrib
2222
from attr._make import _CountingAttr
2323
from attrs import NOTHING, AttrsInstance, Factory, make_class
2424
from hypothesis import strategies as st
@@ -206,7 +206,7 @@ def just_class(tup):
206206
nested_cl = tup[1][0]
207207
default = Factory(nested_cl)
208208
combined_attrs = list(tup[0])
209-
combined_attrs.append((attr.ib(default=default), st.just(nested_cl())))
209+
combined_attrs.append((attrib(default=default), st.just(nested_cl())))
210210
return _create_hyp_class(combined_attrs)
211211

212212

@@ -217,7 +217,7 @@ def make_with_default(takes_self: bool) -> SearchStrategy[AttrsAndArgs]:
217217
combined_attrs = list(tup[0])
218218
combined_attrs.append(
219219
(
220-
attr.ib(
220+
attrib(
221221
default=(
222222
Factory(
223223
nested_cl if not takes_self else lambda _: nested_cl(),
@@ -238,7 +238,7 @@ def just_frozen_class_with_type(tup):
238238
nested_cl = tup[1][0]
239239
combined_attrs = list(tup[0])
240240
combined_attrs.append(
241-
(attr.ib(default=nested_cl(), type=nested_cl), st.just(nested_cl()))
241+
(attrib(default=nested_cl(), type=nested_cl), st.just(nested_cl()))
242242
)
243243
return _create_hyp_class(combined_attrs)
244244

@@ -250,7 +250,7 @@ def make_with_default(takes_self: bool) -> SearchStrategy[AttrsAndArgs]:
250250
combined_attrs = list(tup[0])
251251
combined_attrs.append(
252252
(
253-
attr.ib(
253+
attrib(
254254
default=(
255255
Factory(lambda: [nested_cl()])
256256
if not takes_self
@@ -277,7 +277,7 @@ def make_with_default(takes_self: bool) -> SearchStrategy[AttrsAndArgs]:
277277
)
278278
combined_attrs = list(tup[0])
279279
combined_attrs.append(
280-
(attr.ib(default=default, type=List[nested_cl]), st.just([nested_cl()]))
280+
(attrib(default=default, type=List[nested_cl]), st.just([nested_cl()]))
281281
)
282282
return _create_hyp_class(combined_attrs)
283283

@@ -288,7 +288,7 @@ def dict_of_class(tup):
288288
nested_cl = tup[1][0]
289289
default = Factory(lambda: {"cls": nested_cl()})
290290
combined_attrs = list(tup[0])
291-
combined_attrs.append((attr.ib(default=default), st.just({"cls": nested_cl()})))
291+
combined_attrs.append((attrib(default=default), st.just({"cls": nested_cl()})))
292292
return _create_hyp_class(combined_attrs)
293293

294294

@@ -328,7 +328,7 @@ def bare_attrs(draw, defaults=None, kw_only=None):
328328
if defaults is True or (defaults is None and draw(st.booleans())):
329329
default = None
330330
return (
331-
attr.ib(
331+
attrib(
332332
default=default, kw_only=draw(st.booleans()) if kw_only is None else kw_only
333333
),
334334
st.just(None),
@@ -345,7 +345,7 @@ def int_attrs(draw, defaults=None, kw_only=None):
345345
if defaults is True or (defaults is None and draw(st.booleans())):
346346
default = draw(st.integers())
347347
return (
348-
attr.ib(
348+
attrib(
349349
default=default, kw_only=draw(st.booleans()) if kw_only is None else kw_only
350350
),
351351
st.integers(),
@@ -366,12 +366,12 @@ def str_attrs(draw, defaults=None, type_annotations=None, kw_only=None):
366366
else:
367367
type = None
368368
return (
369-
attr.ib(
369+
attrib(
370370
default=default,
371371
type=type,
372372
kw_only=draw(st.booleans()) if kw_only is None else kw_only,
373373
),
374-
st.text(),
374+
st.text(max_size=5),
375375
)
376376

377377

@@ -385,7 +385,7 @@ def float_attrs(draw, defaults=None, kw_only=None):
385385
if defaults is True or (defaults is None and draw(st.booleans())):
386386
default = draw(st.floats(allow_nan=False))
387387
return (
388-
attr.ib(
388+
attrib(
389389
default=default, kw_only=draw(st.booleans()) if kw_only is None else kw_only
390390
),
391391
st.floats(allow_nan=False),
@@ -399,12 +399,12 @@ def dict_attrs(draw, defaults=None, kw_only=None):
399399
for that attribute. The dictionaries map strings to integers.
400400
"""
401401
default = NOTHING
402-
val_strat = st.dictionaries(keys=st.text(), values=st.integers())
402+
val_strat = st.dictionaries(keys=st.text(max_size=5), values=st.integers())
403403
if defaults is True or (defaults is None and draw(st.booleans())):
404404
default_val = draw(val_strat)
405405
default = Factory(lambda: default_val)
406406
return (
407-
attr.ib(
407+
attrib(
408408
default=default, kw_only=draw(st.booleans()) if kw_only is None else kw_only
409409
),
410410
val_strat,
@@ -423,7 +423,7 @@ def optional_attrs(draw, defaults=None, kw_only=None):
423423
default = draw(val_strat)
424424

425425
return (
426-
attr.ib(
426+
attrib(
427427
default=default, kw_only=draw(st.booleans()) if kw_only is None else kw_only
428428
),
429429
val_strat,
@@ -441,14 +441,16 @@ def simple_attrs(defaults=None, kw_only=None):
441441
)
442442

443443

444-
def lists_of_attrs(defaults=None, min_size=0, kw_only=None):
444+
def lists_of_attrs(defaults=None, min_size=0, kw_only=None) -> SearchStrategy[list]:
445445
# Python functions support up to 255 arguments.
446446
return st.lists(
447447
simple_attrs(defaults, kw_only), min_size=min_size, max_size=10
448448
).map(lambda lst: sorted(lst, key=lambda t: t[0]._default is not NOTHING))
449449

450450

451-
def simple_classes(defaults=None, min_attrs=0, frozen=None, kw_only=None):
451+
def simple_classes(
452+
defaults=None, min_attrs=0, frozen=None, kw_only=None
453+
) -> SearchStrategy:
452454
"""
453455
Return a strategy that yields tuples of simple classes and values to
454456
instantiate them.

uv.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)