Skip to content

Commit

Permalink
Add test on Hera Input class for coverage
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 c0c5979 commit 94c4e36
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/test_script_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from hera.shared._pydantic import _PYDANTIC_VERSION
from hera.workflows import Workflow, script
from hera.workflows.io import Input
from hera.workflows.parameter import Parameter
from hera.workflows.steps import Steps

Expand Down Expand Up @@ -83,6 +84,30 @@ def echo_int(an_int: Annotated[int, Parameter(default=1)]):
assert ("default cannot be set via the Parameter's default, use a Python default value instead") in str(e.value)


def test_pydantic_input_with_default_throws_a_value_error(global_config_fixture):
"""Test asserting that it is not possible to define default in the annotation in a Hera Input class."""

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

class ExampleInput(Input):
an_int: Annotated[int, Parameter(default=1)]

@script()
def echo_int(pydantic_input: ExampleInput):
print(pydantic_input.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 the Parameter's default, use a Python default value instead") in str(e.value)


@pytest.mark.parametrize(
"function_name,expected_input,expected_output",
[
Expand Down

0 comments on commit 94c4e36

Please sign in to comment.