Skip to content

Commit

Permalink
fix: constrained 0 length lists (#570)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcozzxx810 authored Aug 2, 2024
1 parent 67c5720 commit 24701eb
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion polyfactory/value_generators/constrained_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def handle_constrained_collection(
collection: set[T] | list[T] = set() if (collection_type in (frozenset, set) or unique_items) else []

try:
length = factory.__random__.randint(min_items, max_items) or 1
length = factory.__random__.randint(min_items, max_items)
while (i := len(collection)) < length:
if field_build_parameters and len(field_build_parameters) > i:
build_params = field_build_parameters[i]
Expand Down
2 changes: 1 addition & 1 deletion tests/constraints/test_frozen_set_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ def test_handle_constrained_set_with_different_types(t_type: Any) -> None:
field_meta=FieldMeta(name="test", annotation=frozenset, random=Random()),
item_type=t_type,
)
assert len(result) > 0
assert len(result) >= 0
2 changes: 1 addition & 1 deletion tests/constraints/test_list_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_handle_constrained_list_with_different_types(t_type: Any) -> None:
field_meta=field_meta.children[0], # type: ignore[index]
item_type=t_type,
)
assert len(result) > 0
assert len(result) >= 0


def test_handle_unique_items() -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/constraints/test_set_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ def test_handle_constrained_set_with_different_types(t_type: Any) -> None:
field_meta=FieldMeta(name="test", annotation=set, random=Random()),
item_type=t_type,
)
assert len(result) > 0
assert len(result) >= 0

0 comments on commit 24701eb

Please sign in to comment.