Skip to content

Commit

Permalink
test: Test Resources init behavior with disk
Browse files Browse the repository at this point in the history
Signed-off-by: JiangJiaWei1103 <[email protected]>
  • Loading branch information
JiangJiaWei1103 committed Feb 9, 2025
1 parent a321036 commit 2add341
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions flytekit/core/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ def _check_others(value):
self.disk = self.ephemeral_storage
else:
self.disk = disk

# This alias ensures backward compatibility, allowing `ephemeral_storage`
# to mirror the value of `disk` for seamless attribute access
self.ephemeral_storage = self.disk
_check_others(self.disk)

Expand Down
24 changes: 24 additions & 0 deletions tests/flytekit/unit/core/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,27 @@ def test_pod_spec_from_resources_requests_set():
)
pod_spec = pod_spec_from_resources(k8s_pod_name=k8s_pod_name, requests=requests, limits=limits)
assert expected_pod_spec == V1PodSpec(**pod_spec)


def test_disk():
# Define expected warning and error messages
WARN_MSG = "ephemeral_storage is deprecated and will be removed in the future. Please use disk instead."
ERR_MSG = (
"Cannot specify both disk and ephemeral_storage."
"Please use disk because ephemeral_storage is deprecated and will be removed in the future."
)

# Specify both disk and ephemeral_storage
with pytest.raises(ValueError, match=ERR_MSG):
resources = Resources(cpu="1", mem="1Gi", gpu="1", disk="1Gi", ephemeral_storage="1Gi")

# Specify only ephemeral_storage
with pytest.warns(DeprecationWarning, match=WARN_MSG):
resources = Resources(cpu="1", mem="1Gi", gpu="1", ephemeral_storage="1Gi")
assert resources.disk == "1Gi"
assert resources.ephemeral_storage == "1Gi"

# Specify only disk
resources = Resources(cpu="1", mem="1Gi", gpu="1", disk="1Gi")
assert resources.disk == "1Gi"
assert resources.ephemeral_storage == "1Gi"

0 comments on commit 2add341

Please sign in to comment.