From 1dc5692c7c59104de47400bc6ba304b8528bb81a Mon Sep 17 00:00:00 2001 From: Phil Weir Date: Sun, 25 Aug 2024 01:06:16 +0100 Subject: [PATCH] chore: fix test linting - TODO: add docstrings --- tests/_lib/extra.py | 3 --- tests/test_annotations.py | 17 ++++++++++----- tests/test_configuration.py | 12 +++++++---- tests/test_cwl.py | 2 +- tests/test_errors.py | 16 ++++---------- tests/test_fieldable.py | 43 +++++++++++++++++++++++++------------ tests/test_nested.py | 4 +++- tests/test_render_module.py | 7 ++++-- tests/test_subworkflows.py | 2 ++ 9 files changed, 64 insertions(+), 42 deletions(-) diff --git a/tests/_lib/extra.py b/tests/_lib/extra.py index 921a93c0..3293044d 100644 --- a/tests/_lib/extra.py +++ b/tests/_lib/extra.py @@ -1,17 +1,14 @@ from dewret.tasks import task, workflow -from dewret.annotations import AtRender from .other import nothing JUMP: float = 1.0 test: float = nothing -from inspect import get_annotations @workflow() def try_nothing() -> int: """Check that we can see AtRender in another module.""" - if nothing: return increment(num=1) return increment(num=0) diff --git a/tests/test_annotations.py b/tests/test_annotations.py index a4cbb440..9a709003 100644 --- a/tests/test_annotations.py +++ b/tests/test_annotations.py @@ -1,8 +1,9 @@ +"""Verify we can interrogate annotations.""" + import pytest import yaml -from typing import Literal -from dewret.tasks import task, construct, workflow, TaskException +from dewret.tasks import construct, workflow, TaskException from dewret.renderers.cwl import render from dewret.annotations import AtRender, FunctionAnalyser, Fixed from dewret.core import set_configuration @@ -13,12 +14,15 @@ ARG2: bool = False class MyClass: + """TODO: Docstring.""" def method(self, arg1: bool, arg2: AtRender[int]) -> float: + """TODO: Docstring.""" arg3: float = 7.0 arg4: AtRender[float] = 8.0 return arg1 + arg2 + arg3 + arg4 + int(ARG1) + int(ARG2) def fn(arg5: int, arg6: AtRender[int]) -> float: + """TODO: Docstring.""" arg7: float = 7.0 arg8: AtRender[float] = 8.0 return arg5 + arg6 + arg7 + arg8 + int(ARG1) + int(ARG2) @@ -35,6 +39,7 @@ def to_int(num: int, should_double: AtRender[bool]) -> int | float: return increment(num=num) if should_double else sum(left=num, right=num) def test_can_analyze_annotations(): + """TODO: Docstring.""" my_obj = MyClass() analyser = FunctionAnalyser(my_obj.method) @@ -56,6 +61,7 @@ def test_can_analyze_annotations(): assert analyser.argument_has("ARG1", AtRender) is False def test_at_render() -> None: + """TODO: Docstring.""" with pytest.raises(TaskException) as _: result = to_int_bad(num=increment(num=3), should_double=True) wkflw = construct(result, simplify_ids=True) @@ -138,19 +144,20 @@ def test_at_render() -> None: def test_at_render_between_modules() -> None: - nothing = False + """TODO: Docstring.""" result = try_nothing() wkflw = construct(result, simplify_ids=True) subworkflows = render(wkflw, allow_complex_types=True) - rendered = subworkflows["__root__"] + subworkflows["__root__"] list_2: Fixed[list[int]] = [0, 1, 2, 3] def test_can_loop_over_fixed_length() -> None: + """TODO: Docstring.""" @workflow() def loop_over_lists(list_1: list[int]) -> list[int]: result = [] - for a, b in zip(list_1, list_2): + for a, b in zip(list_1, list_2, strict=False): result.append(a + b + len(list_2)) return result diff --git a/tests/test_configuration.py b/tests/test_configuration.py index 01b91206..b94e57e4 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -1,14 +1,16 @@ +"""Check configuration is consistent and usable.""" + import yaml import pytest -from dewret.tasks import construct, task, factory, workflow, TaskException +from dewret.tasks import construct, workflow, TaskException from dewret.renderers.cwl import render -from dewret.utils import hasher from dewret.tasks import set_configuration from dewret.annotations import AtRender -from ._lib.extra import increment, double, mod10, sum, triple_and_one +from ._lib.extra import increment @pytest.fixture def configuration(): + """TODO: Docstring.""" with set_configuration() as configuration: yield configuration.get() @@ -21,6 +23,7 @@ def floor(num: int, expected: AtRender[bool]) -> int: return increment(num=num) def test_cwl_with_parameter(configuration) -> None: + """TODO: Docstring.""" with set_configuration(flatten_all_nested=True): result = increment(num=floor(num=3, expected=True)) workflow = construct(result, simplify_ids=True) @@ -35,8 +38,9 @@ def test_cwl_with_parameter(configuration) -> None: workflow = construct(result, simplify_ids=True) rendered = render(workflow)["__root__"] num_param = list(workflow.find_parameters())[0] + assert num_param - assert rendered == yaml.safe_load(f""" + assert rendered == yaml.safe_load(""" cwlVersion: 1.2 class: Workflow inputs: diff --git a/tests/test_cwl.py b/tests/test_cwl.py index 52f7793a..4188424f 100644 --- a/tests/test_cwl.py +++ b/tests/test_cwl.py @@ -177,7 +177,7 @@ def test_cwl_with_positional_parameter() -> None: Produces CWL for a call with a changeable raw value, that is converted to a parameter, if and only if we are calling from outside a subworkflow. """ - with pytest.raises(TaskException) as exc: + with pytest.raises(TaskException) as _: result = increment(3) with set_configuration(allow_positional_args=True): result = increment(3) diff --git a/tests/test_errors.py b/tests/test_errors.py index 96607bce..3b21c332 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -4,7 +4,6 @@ from dewret.workflow import Task, Lazy from dewret.tasks import construct, task, workflow, TaskException from dewret.annotations import AtRender -from dewret.renderers.cwl import render from ._lib.extra import increment, pi, reverse_list # noqa: F401 @@ -14,7 +13,7 @@ def add_task(left: int, right: int) -> int: return left + right -ADD_TASK_LINE_NO: int = 11 +ADD_TASK_LINE_NO: int = 10 @workflow() @@ -37,14 +36,6 @@ def __init__(self, task: Task): ... -@task() -def pi() -> float: - """Get pi from math package.""" - import math - - return math.pi - - @task() def pi_exported_from_math() -> float: """Get pi from math package by name.""" @@ -242,6 +233,7 @@ def test_subworkflows_must_return_a_task() -> None: good_num: int = 4 def test_must_annotate_global() -> None: + """TODO: Docstrings.""" worse_num = 3 @workflow() @@ -249,7 +241,7 @@ def check_annotation() -> int | float: return increment(num=bad_num) with pytest.raises(TaskException) as exc: - result = check_annotation() + check_annotation() assert ( str(exc.value) @@ -261,7 +253,7 @@ def check_annotation_2() -> int | float: return increment(num=worse_num) with pytest.raises(TaskException) as exc: - result = check_annotation_2() + check_annotation_2() assert ( str(exc.value) diff --git a/tests/test_fieldable.py b/tests/test_fieldable.py index 5ef7c93d..e669f63f 100644 --- a/tests/test_fieldable.py +++ b/tests/test_fieldable.py @@ -1,8 +1,9 @@ +"""Check field management works.""" + from __future__ import annotations import yaml from dataclasses import dataclass -import pytest from typing import Unpack, TypedDict from dewret.tasks import task, construct, workflow, set_configuration @@ -10,10 +11,11 @@ from dewret.renderers.cwl import render from dewret.annotations import Fixed -from ._lib.extra import double, mod10, sum, pi +from ._lib.extra import mod10, sum, pi @dataclass class Sides: + """TODO: Docstring.""" left: int right: int @@ -21,9 +23,11 @@ class Sides: @workflow() def sum_sides() -> float: + """TODO: Docstring.""" return sum(left=SIDES.left, right=SIDES.right) def test_fields_of_parameters_usable() -> None: + """TODO: Docstring.""" result = sum_sides() wkflw = construct(result, simplify_ids=True) rendered = render(wkflw, allow_complex_types=True)["sum_sides-1"] @@ -69,10 +73,12 @@ def test_fields_of_parameters_usable() -> None: @dataclass class MyDataclass: + """TODO: Docstring.""" left: int right: "MyDataclass" def test_can_get_field_reference_from_parameter(): + """TODO: Docstring.""" my_param = param("my_param", typ=MyDataclass) result = sum(left=my_param.left, right=sum(left=my_param.right.left, right=my_param)) wkflw = construct(result, simplify_ids=True) @@ -116,6 +122,7 @@ def test_can_get_field_reference_from_parameter(): """) def test_can_get_field_reference_iff_parent_type_has_field(): + """TODO: Docstring.""" @dataclass class MyDataclass: left: int @@ -128,6 +135,7 @@ class MyDataclass: assert param_reference.left.__type__ == int def test_can_get_field_references_from_dataclass(): + """TODO: Docstring.""" @dataclass class MyDataclass: left: int @@ -149,10 +157,12 @@ def get_left(my_dataclass: MyDataclass) -> int: assert wkflw.result.__type__ == int class MyDict(TypedDict): + """TODO: Docstring.""" left: int right: float def test_can_get_field_references_from_typed_dict(): + """TODO: Docstring.""" @workflow() def test_dict(**my_dict: Unpack[MyDict]) -> MyDict: result: MyDict = {"left": mod10(num=my_dict["left"]), "right": pi()} @@ -166,9 +176,11 @@ def test_dict(**my_dict: Unpack[MyDict]) -> MyDict: @dataclass class MyListWrapper: + """TODO: Docstring.""" my_list: list[int] def test_can_iterate(): + """TODO: Docstring.""" @task() def test_task(alpha: int, beta: float, charlie: bool) -> int: return int(alpha + beta) @@ -289,6 +301,7 @@ def test_iterated_3(param: Fixed[list[tuple[int, int]]]) -> int: """) def test_can_use_plain_dict_fields(): + """TODO: Docstring.""" @workflow() def test_dict(left: int, right: float) -> dict[str, float | int]: result: dict[str, float | int] = {"left": mod10(num=left), "right": pi()} @@ -302,9 +315,11 @@ def test_dict(left: int, right: float) -> dict[str, float | int]: @dataclass class IndexTest: + """TODO: Docstring.""" left: Fixed[list[int]] def test_can_configure_field_separator(): + """TODO: Docstring.""" @task() def test_sep() -> IndexTest: return IndexTest(left=[3]) @@ -312,17 +327,17 @@ def test_sep() -> IndexTest: with set_configuration(field_index_types="int"): result = test_sep().left[0] wkflw = construct(result, simplify_ids=True) - rendered = render(wkflw, allow_complex_types=True)["__root__"] + render(wkflw, allow_complex_types=True)["__root__"] assert str(wkflw.result) == "test_sep-1/left[0]" - #with set_configuration(field_index_types="int,str"): - # result = test_sep().left[0] - # wkflw = construct(result, simplify_ids=True) - # rendered = render(wkflw, allow_complex_types=True)["__root__"] - # assert str(wkflw.result) == "test_sep-1[left][0]" - - #with set_configuration(field_index_types=""): - # result = test_sep().left[0] - # wkflw = construct(result, simplify_ids=True) - # rendered = render(wkflw, allow_complex_types=True)["__root__"] - # assert str(wkflw.result) == "test_sep-1/left/0" + with set_configuration(field_index_types="int,str"): + result = test_sep().left[0] + wkflw = construct(result, simplify_ids=True) + render(wkflw, allow_complex_types=True)["__root__"] + assert str(wkflw.result) == "test_sep-1[left][0]" + + with set_configuration(field_index_types=""): + result = test_sep().left[0] + wkflw = construct(result, simplify_ids=True) + render(wkflw, allow_complex_types=True)["__root__"] + assert str(wkflw.result) == "test_sep-1/left/0" diff --git a/tests/test_nested.py b/tests/test_nested.py index c05f85c2..3d901d8c 100644 --- a/tests/test_nested.py +++ b/tests/test_nested.py @@ -1,5 +1,6 @@ +"""Check complex nested structures and expressions can mix.""" + import yaml -import pytest import math from dewret.workflow import param from dewret.tasks import construct @@ -8,6 +9,7 @@ from ._lib.extra import reverse_list, max_list def test_can_supply_nested_raw(): + """TODO: Docstrings.""" pi = param("pi", math.pi) result = reverse_list(to_sort=[1., 3., pi]) workflow = construct(max_list(lst=result + result), simplify_ids=True) diff --git a/tests/test_render_module.py b/tests/test_render_module.py index 1cc36225..c8760aab 100644 --- a/tests/test_render_module.py +++ b/tests/test_render_module.py @@ -1,10 +1,13 @@ +"""Check renderers can be imported live.""" + from pathlib import Path -from dewret.tasks import construct, task, factory +from dewret.tasks import construct from dewret.render import get_render_method -from ._lib.extra import increment, double, mod10, sum, triple_and_one +from ._lib.extra import increment, triple_and_one def test_can_load_render_module(): + """TODO: Docstrings.""" result = triple_and_one(num=increment(num=3)) workflow = construct(result, simplify_ids=True) workflow._name = "Fred" diff --git a/tests/test_subworkflows.py b/tests/test_subworkflows.py index 7339ce25..0fdd43cd 100644 --- a/tests/test_subworkflows.py +++ b/tests/test_subworkflows.py @@ -546,12 +546,14 @@ def test_subworkflows_can_use_globals_in_right_scope() -> None: @define class PackResult: + """TODO: Docstrings.""" hearts: int clubs: int spades: int diamonds: int def test_combining_attrs_and_factories(): + """TODO: Docstrings.""" Pack = factory(PackResult) @task()