Skip to content

Commit

Permalink
fix: Compatibility with python 3.8/3.9/3.10.
Browse files Browse the repository at this point in the history
Signed-off-by: DanCardin <[email protected]>
  • Loading branch information
DanCardin committed Dec 19, 2023
1 parent 1f83bb7 commit aede98a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/hera/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ def main(argv=None):
cappa.invoke(Hera, argv=argv)


if __name__ == "__main__":
if __name__ == "__main__": # pragma: no cover
main()
3 changes: 2 additions & 1 deletion src/hera/_cli/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from dataclasses import dataclass
from pathlib import Path
from typing import Union

from cappa import Arg, Subcommands, command
from typing_extensions import Annotated
Expand Down Expand Up @@ -36,7 +37,7 @@ class GenerateYaml:
),
]
to: Annotated[
Path | None,
Union[Path, None],
Arg(
long=True,
help=(
Expand Down
11 changes: 9 additions & 2 deletions tests/cli/test_generate_yaml.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from textwrap import dedent
from unittest.mock import mock_open, patch

Expand All @@ -11,6 +12,12 @@ def get_stdout(capsys):
return capsys.readouterr().out


def patch_open():
if sys.version_info == (3, 10):
return patch("pathlib._NormalAccessor.open", new=mock_open())
return patch("io.open", new=mock_open())


single_workflow_output = dedent(
"""\
apiVersion: argoproj.io/v1alpha1
Expand Down Expand Up @@ -175,7 +182,7 @@ def test_source_file_output_folder():
dest_is_file_patch = patch("pathlib.Path.is_file", return_value=False)
makedirs_patch = patch("os.makedirs")

open_patch = patch("io.open", new=mock_open())
open_patch = patch_open()

with source_is_dir_patch, dest_exists_patch, dest_is_file_patch, makedirs_patch, open_patch:
cappa.invoke(
Expand All @@ -202,7 +209,7 @@ def test_source_folder_output_folder():
dest_exists_patch = patch("os.path.exists", return_value=False)
makedirs_patch = patch("os.makedirs")

open_patch = patch("io.open", new=mock_open())
open_patch = patch_open()

with source_is_dir_patch, dest_exists_patch, makedirs_patch, open_patch:
cappa.invoke(
Expand Down

0 comments on commit aede98a

Please sign in to comment.