Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: added some cases to test_can_analyze_annotations for completeness #57

Draft
wants to merge 2 commits into
base: release/0.10.0
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions tests/test_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

from ._lib.extra import increment, sum, try_nothing

from typing import Any

ARG1: AtRender[bool] = True
ARG2: bool = False

Expand Down Expand Up @@ -37,6 +39,12 @@ def to_int_bad(num: int, should_double: bool) -> int | float:
return increment(num=num) if should_double else sum(left=num, right=num)


@workflow()
def to_int_bad_2(num: int, should_double: Any) -> int | float:
"""A mock workflow that casts to an int with a wrong type for handling doubles."""
return increment(num=num) if should_double else sum(left=num, right=num)


@workflow()
def to_int(num: int, should_double: AtRender[bool]) -> int | float:
"""A mock workflow that casts to an int with a right type for handling doubles."""
Expand All @@ -56,6 +64,7 @@ def test_can_analyze_annotations() -> None:
assert analyser.argument_has("arg3", AtRender, exhaustive=True) is False
assert analyser.argument_has("ARG2", AtRender, exhaustive=True) is False
assert analyser.argument_has("arg2", AtRender, exhaustive=True) is True
assert analyser.argument_has("arg2", AtRender, exhaustive=False) is True
assert (
analyser.argument_has("arg4", AtRender, exhaustive=True) is False
) # Not a global/argument
Expand All @@ -67,19 +76,26 @@ def test_can_analyze_annotations() -> None:
assert analyser.argument_has("arg7", AtRender, exhaustive=True) is False
assert analyser.argument_has("ARG2", AtRender, exhaustive=True) is False
assert analyser.argument_has("arg6", AtRender, exhaustive=True) is True
assert analyser.argument_has("arg6", AtRender, exhaustive=False) is True
assert (
analyser.argument_has("arg8", AtRender, exhaustive=True) is False
) # Not a global/argument
assert analyser.argument_has("ARG1", AtRender, exhaustive=True) is True
assert analyser.argument_has("ARG1", AtRender) is False


def test_at_render() -> None:
"""Test the rendering of workflows with `dewret.annotations.AtRender` and exceptions handling."""
def test_at_render_bad() -> None:
"""Test the rendering of workflows with exceptions handling."""
with pytest.raises(TaskException) as _:
result = to_int_bad(num=increment(num=3), should_double=True)
wkflw = construct(result, simplify_ids=True)
with pytest.raises(TaskException) as _:
result = to_int_bad_2(num=increment(num=3), should_double=True)
wkflw = construct(result, simplify_ids=True)


def test_at_render() -> None:
"""Test the rendering of workflows with `dewret.annotations.AtRender`."""
result = to_int(num=increment(num=3), should_double=True)
wkflw = construct(result, simplify_ids=True)
subworkflows = render(wkflw, allow_complex_types=True)
Expand Down
Loading