From c777360efdec43f80eca531a75578bfb79886288 Mon Sep 17 00:00:00 2001 From: Ketan Umare Date: Thu, 14 Oct 2021 21:13:58 -0700 Subject: [PATCH] unit tests Signed-off-by: Ketan Umare --- flytekit/common/utils.py | 2 +- flytekit/core/workflow.py | 2 +- .../flytekit/unit/common_tests/test_utils.py | 22 +++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 tests/flytekit/unit/common_tests/test_utils.py diff --git a/flytekit/common/utils.py b/flytekit/common/utils.py index a61ee42a37..1d0395fd90 100644 --- a/flytekit/common/utils.py +++ b/flytekit/common/utils.py @@ -11,7 +11,7 @@ from flytekit.models.core import identifier as _identifier -def _dnsify(value): # type: (str) -> str +def _dnsify(value: str) -> str: """ Converts value into a DNS-compliant (RFC1035/RFC1123 DNS_LABEL). The resulting string must only consist of alphanumeric (lower-case a-z, and 0-9) and not exceed 63 characters. It's permitted to have '-' character as long diff --git a/flytekit/core/workflow.py b/flytekit/core/workflow.py index 857b429222..a14be3d0a5 100644 --- a/flytekit/core/workflow.py +++ b/flytekit/core/workflow.py @@ -187,7 +187,7 @@ def name(self) -> str: @property def short_name(self) -> str: - return self._name.split(".")[-1] + return extract_obj_name(self._name) @property def workflow_metadata(self) -> Optional[WorkflowMetadata]: diff --git a/tests/flytekit/unit/common_tests/test_utils.py b/tests/flytekit/unit/common_tests/test_utils.py new file mode 100644 index 0000000000..a24d585d1c --- /dev/null +++ b/tests/flytekit/unit/common_tests/test_utils.py @@ -0,0 +1,22 @@ +import pytest + +from flytekit.common.utils import _dnsify + + +@pytest.mark.parametrize( + "input,expected", + [ + ("test.abc", "test-abc"), + ("test", "test"), + ("", ""), + (".test", "test"), + ("Test", "test"), + ("test.", "test"), + ("test-", "test"), + ("test$", "test"), + ("te$t$", "tet"), + ("t" * 64, f"da4b348ebe-{'t'*52}"), + ], +) +def test_dnsify(input, expected): + assert _dnsify(input) == expected