Improved Command class management.
This commit is contained in:
58
tests/core/test_utils.py
Normal file
58
tests/core/test_utils.py
Normal file
@@ -0,0 +1,58 @@
|
||||
import pytest
|
||||
|
||||
from myfasthtml.core.utils import flatten
|
||||
|
||||
|
||||
@pytest.mark.parametrize("input_args,expected,test_description", [
|
||||
# Simple list without nesting
|
||||
(([1, 2, 3],), [1, 2, 3], "simple list"),
|
||||
|
||||
# Nested list (one level)
|
||||
(([1, [2, 3], 4],), [1, 2, 3, 4], "nested list one level"),
|
||||
|
||||
# Nested tuple
|
||||
(((1, (2, 3), 4),), [1, 2, 3, 4], "nested tuple"),
|
||||
|
||||
# Mixed list and tuple
|
||||
(([1, (2, 3), [4, 5]],), [1, 2, 3, 4, 5], "mixed list and tuple"),
|
||||
|
||||
# Deeply nested structure
|
||||
(([1, [2, [3, [4, 5]]]],), [1, 2, 3, 4, 5], "deeply nested structure"),
|
||||
|
||||
# Empty list
|
||||
(([],), [], "empty list"),
|
||||
|
||||
# Empty nested lists
|
||||
(([1, [], [2, []], 3],), [1, 2, 3], "empty nested lists"),
|
||||
|
||||
# Preserves order
|
||||
(([[3, 1], [4, 2]],), [3, 1, 4, 2], "preserves order"),
|
||||
|
||||
# Strings (should not be iterated)
|
||||
((["hello", ["world"]],), ["hello", "world"], "strings not iterated"),
|
||||
|
||||
# Mixed types
|
||||
(([1, "text", [2.5, True], None],), [1, "text", 2.5, True, None], "mixed types"),
|
||||
|
||||
# Multiple arguments with lists
|
||||
(([1, 2], [3, 4], 5), [1, 2, 3, 4, 5], "multiple arguments with lists"),
|
||||
|
||||
# Scalar values only
|
||||
((1, 2, 3), [1, 2, 3], "scalar values only"),
|
||||
|
||||
# Mixed scalars and lists
|
||||
((1, [2, 3], 4, [5, 6]), [1, 2, 3, 4, 5, 6], "mixed scalars and lists"),
|
||||
|
||||
# Multiple nested arguments
|
||||
(([1, [2]], [3, [4]], 5), [1, 2, 3, 4, 5], "multiple nested arguments"),
|
||||
|
||||
# No arguments
|
||||
((), [], "no arguments"),
|
||||
|
||||
# Complex real-world example
|
||||
(([1, [2, 3], [[4, 5], [6, 7]], [[[8, 9]]], 10],), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "complex nesting"),
|
||||
])
|
||||
def test_i_can_flatten(input_args, expected, test_description):
|
||||
"""Test that flatten correctly handles various nested structures and arguments."""
|
||||
result = flatten(*input_args)
|
||||
assert result == expected, f"Failed for test case: {test_description}"
|
||||
Reference in New Issue
Block a user