Skip to content

Commit

Permalink
docs: Added docstrings for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KamenDimitrov97 committed Sep 2, 2024
1 parent a0655c0 commit aa7d6e4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 21 deletions.
2 changes: 1 addition & 1 deletion tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def floor(num: int, expected: AtRender[bool]) -> int:
return increment(num=num)

def test_cwl_with_parameter() -> None:
"""TODO: Docstring."""
"""Test workflows with configuration parameters."""
with set_configuration(flatten_all_nested=True):
result = increment(num=floor(num=3, expected=True))
workflow = construct(result, simplify_ids=True)
Expand Down
39 changes: 23 additions & 16 deletions tests/test_fieldable.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@

@dataclass
class Sides:
"""TODO: Docstring."""
"""A dataclass representing the sides with `left` and `right` integers."""
left: int
right: int

SIDES: Sides = Sides(3, 6)

@workflow()
def sum_sides() -> float:
"""TODO: Docstring."""
"""Workflow that returns the sum of the `left` and `right` sides."""
return sum(left=SIDES.left, right=SIDES.right)

def test_fields_of_parameters_usable() -> None:
"""TODO: Docstring."""
"""Test that fields of parameters can be used to construct and render a workflow correctly."""
result = sum_sides()
wkflw = construct(result, simplify_ids=True)
rendered = render(wkflw, allow_complex_types=True)["sum_sides-1"]
Expand Down Expand Up @@ -74,12 +74,12 @@ def test_fields_of_parameters_usable() -> None:

@dataclass
class MyDataclass:
"""TODO: Docstring."""
"""A dataclass with nested references to itself, containing `left` and `right` fields."""
left: int
right: "MyDataclass"

def test_can_get_field_reference_from_parameter() -> None:
"""TODO: Docstring."""
"""Test that field references can be retrieved from a parameter when constructing a workflow."""
my_param = param("my_param", typ=MyDataclass)
result = sum(left=my_param.left, right=sum(left=my_param.right.left, right=my_param.left))
wkflw = construct(result, simplify_ids=True)
Expand Down Expand Up @@ -122,8 +122,8 @@ def test_can_get_field_reference_from_parameter() -> None:
run: sum
""")

def test_can_get_field_reference_iff_parent_type_has_field() -> None:
"""TODO: Docstring."""
def test_can_get_field_reference_if_parent_type_has_field() -> None:
"""Test that a field reference is retrievable if the parent type has that field."""
@dataclass
class MyDataclass:
left: int
Expand All @@ -136,7 +136,7 @@ class MyDataclass:
assert param_reference.left.__type__ == int

def test_can_get_go_upwards_from_a_field_reference() -> None:
"""TODO: Docstring."""
"""Test that it's possible to move upwards in the hierarchy from a field reference."""
@dataclass
class MyDataclass:
left: int
Expand All @@ -150,7 +150,7 @@ class MyDataclass:
assert back.__type__ == MyDataclass

def test_can_get_field_references_from_dataclass() -> None:
"""TODO: Docstring."""
"""Test that field references can be extracted from a dataclass and used in workflows."""
@dataclass
class MyDataclass:
left: int
Expand All @@ -173,12 +173,12 @@ def get_left(my_dataclass: MyDataclass) -> int:
assert wkflw.result.__type__ == int

class MyDict(TypedDict):
"""TODO: Docstring."""
"""A typed dictionary with `left` as an integer and `right` as a float."""
left: int
right: float

def test_can_get_field_references_from_typed_dict() -> None:
"""TODO: Docstring."""
"""Test that field references can be extracted from a custom typed dictionary and used in workflows."""
@workflow()
def test_dict(**my_dict: Unpack[MyDict]) -> MyDict:
result: MyDict = {"left": mod10(num=my_dict["left"]), "right": pi()}
Expand All @@ -193,21 +193,24 @@ def test_dict(**my_dict: Unpack[MyDict]) -> MyDict:

@dataclass
class MyListWrapper:
"""TODO: Docstring."""
"""A dataclass that wraps a list of integers."""
my_list: list[int]

def test_can_iterate() -> None:
"""TODO: Docstring."""
"""Test iteration over a list of tasks and validate positional argument handling."""
@task()
def test_task(alpha: int, beta: float, charlie: bool) -> int:
"""Task that adds `alpha` and `beta` and returns the integer result."""
return int(alpha + beta)

@task()
def test_list() -> list[int | float]:
"""Task that returns a list containing an integer and a float."""
return [1, 2.]

@workflow()
def test_iterated() -> int:
"""Workflow that tests task iteration over a list."""
# We ignore the type as mypy cannot confirm that the length and types match the args.
return test_task(*test_list()) # type: ignore

Expand Down Expand Up @@ -250,10 +253,12 @@ def test_iterated() -> int:

@task()
def test_list_2() -> MyListWrapper:
"""Task that returns a `MyListWrapper` containing a list of integers."""
return MyListWrapper(my_list=[1, 2])

@workflow()
def test_iterated_2(my_wrapper: MyListWrapper) -> int:
"""Workflow that tests iteration over a list in a `MyListWrapper`."""
# mypy cannot confirm argument types match.
return test_task(*my_wrapper.my_list) # type: ignore

Expand All @@ -263,10 +268,12 @@ def test_iterated_2(my_wrapper: MyListWrapper) -> int:

@task()
def test_list_3() -> Fixed[list[tuple[int, int]]]:
"""Task that returns a list of integer tuples wrapped in a `dewret.annotations.Fixed` type."""
return [(0, 1), (2, 3)]

@workflow()
def test_iterated_3(param: Fixed[list[tuple[int, int]]]) -> int:
"""Workflow that iterates over a list of integer tuples and performs operations."""
# mypy cannot confirm argument types match.
retval = mod10(*test_list_3()[0]) # type: ignore
for pair in param:
Expand Down Expand Up @@ -322,7 +329,7 @@ def test_iterated_3(param: Fixed[list[tuple[int, int]]]) -> int:
""")

def test_can_use_plain_dict_fields() -> None:
"""TODO: Docstring."""
"""Test the use of plain dictionary fields in workflows."""
@workflow()
def test_dict(left: int, right: float) -> dict[str, float | int]:
result: dict[str, float | int] = {"left": mod10(num=left), "right": pi()}
Expand All @@ -337,11 +344,11 @@ def test_dict(left: int, right: float) -> dict[str, float | int]:

@dataclass
class IndexTest:
"""TODO: Docstring."""
"""A dataclass for testing indexed fields, containing a `left` field that is a list of integers."""
left: Fixed[list[int]]

def test_can_configure_field_separator() -> None:
"""TODO: Docstring."""
"""Test the ability to configure the field separator in workflows."""
@task()
def test_sep() -> IndexTest:
return IndexTest(left=[3])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_nested.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ._lib.extra import reverse_list, max_list

def test_can_supply_nested_raw() -> None:
"""TODO: Docstrings."""
"""TODO: The structures are important for future CWL rendering."""
pi = param("pi", math.pi)
result = reverse_list(to_sort=[1., 3., pi])
workflow = construct(max_list(lst=result + result), simplify_ids=True)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_render_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ._lib.extra import increment, triple_and_one

def test_can_load_render_module() -> None:
"""TODO: Docstrings."""
"""Checks if we can load a render module"""
result = triple_and_one(num=increment(num=3))
workflow = construct(result, simplify_ids=True)
workflow._name = "Fred"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_subworkflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,14 +547,14 @@ def test_subworkflows_can_use_globals_in_right_scope() -> None:

@define
class PackResult:
"""TODO: Docstrings."""
"""A class representing the counts of card suits in a deck, including hearts, clubs, spades, and diamonds."""
hearts: int
clubs: int
spades: int
diamonds: int

def test_combining_attrs_and_factories() -> None:
"""TODO: Docstrings."""
"""Check combining attributes from a dataclass with factory-produced instances."""
Pack = factory(PackResult)

@task()
Expand Down

0 comments on commit aa7d6e4

Please sign in to comment.