Skip to content

Commit

Permalink
Update tests and format/fix lint
Browse files Browse the repository at this point in the history
Signed-off-by: Elliot Gunton <[email protected]>
  • Loading branch information
elliotgunton committed Nov 27, 2024
1 parent 2fbb2a1 commit c0c5979
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 34 deletions.
2 changes: 0 additions & 2 deletions src/hera/workflows/io/_io_mixins.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sys
import warnings
from typing import TYPE_CHECKING, Iterator, List, Optional, Tuple, Type, Union

if sys.version_info >= (3, 11):
Expand All @@ -8,7 +7,6 @@
from typing_extensions import Self


from hera.shared import global_config
from hera.shared._pydantic import _PYDANTIC_VERSION, FieldInfo, get_field_annotations, get_fields
from hera.shared._type_util import construct_io_from_annotation, get_workflow_annotation
from hera.shared.serialization import MISSING, serialize
Expand Down
1 change: 0 additions & 1 deletion src/hera/workflows/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import inspect
import sys
import textwrap
import warnings
from abc import abstractmethod
from functools import wraps
from typing import (
Expand Down
33 changes: 3 additions & 30 deletions tests/test_script_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,33 +64,10 @@ def test_script_annotations_artifact_regression(module_name, global_config_fixtu
_compare_workflows(workflow_old, output_old, output_new)


def test_double_default_throws_a_value_error(global_config_fixture):
"""Test asserting that it is not possible to define default in the annotation and normal Python."""
def test_parameter_default_throws_a_value_error(global_config_fixture):
"""Test asserting that it is not possible to define default in the annotation."""

# GIVEN
global_config_fixture.experimental_features["suppress_parameter_default_error"] = True

@script()
def echo_int(an_int: Annotated[int, Parameter(default=1)] = 2):
print(an_int)

global_config_fixture.experimental_features["script_annotations"] = True
with pytest.raises(ValueError) as e:
with Workflow(generate_name="test-default-", entrypoint="my-steps") as w:
with Steps(name="my-steps"):
echo_int()

w.to_dict()

assert "default cannot be set via both the function parameter default and the Parameter's default" in str(e.value)


def test_parameter_default_without_suppression_throws_a_value_error(global_config_fixture):
"""Test asserting that it is not possible to define default in the annotation and normal Python."""

# GIVEN
global_config_fixture.experimental_features["suppress_parameter_default_error"] = False

@script()
def echo_int(an_int: Annotated[int, Parameter(default=1)]):
print(an_int)
Expand All @@ -103,11 +80,7 @@ def echo_int(an_int: Annotated[int, Parameter(default=1)]):

w.to_dict()

assert (
"default cannot be set via the Parameter's default, use a Python default value instead"
"You can suppress this error by setting "
'global_config.experimental_features["suppress_parameter_default_error"] = True'
) in str(e.value)
assert ("default cannot be set via the Parameter's default, use a Python default value instead") in str(e.value)


@pytest.mark.parametrize(
Expand Down
2 changes: 1 addition & 1 deletion tests/workflow_decorators/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def setup() -> SetupOutput:


class ConcatInput(Input):
word_a: Annotated[str, Parameter(name="word_a", default="")]
word_a: Annotated[str, Parameter(name="word_a")] = ""
word_b: str


Expand Down

0 comments on commit c0c5979

Please sign in to comment.