Skip to content

Commit

Permalink
fix: Make StorageProfileOperatingSystemFamily enum case-insensitive
Browse files Browse the repository at this point in the history
Signed-off-by: Caden Marofke <[email protected]>
  • Loading branch information
marofke authored and mwiebe committed Mar 20, 2024
1 parent f9bd1b9 commit 0da921c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/deadline/job_attachments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,20 @@ class OutputFile:


class StorageProfileOperatingSystemFamily(str, Enum):
"""Case-insensitive enum for the storage profile operating system family type."""

WINDOWS = "windows"
LINUX = "linux"
MACOS = "macos"

@classmethod
def _missing_(cls, value):
value = value.lower()
for member in cls:
if member == value:
return member
return None


class PathFormat(str, Enum):
WINDOWS = "windows"
Expand Down
33 changes: 32 additions & 1 deletion test/unit/deadline_job_attachments/test_models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
from unittest.mock import patch

from deadline.job_attachments.models import PathFormat
from deadline.job_attachments.models import PathFormat, StorageProfileOperatingSystemFamily

import pytest

Expand All @@ -17,3 +17,34 @@ def test_get_host_path_format_string(self, sys_os: str, expected_output: str):
"""
with patch("sys.platform", sys_os):
assert PathFormat.get_host_path_format_string() == expected_output

@pytest.mark.parametrize(
("input", "output"),
[
("windows", StorageProfileOperatingSystemFamily.WINDOWS),
("WINDOWS", StorageProfileOperatingSystemFamily.WINDOWS),
("wInDoWs", StorageProfileOperatingSystemFamily.WINDOWS),
("linux", StorageProfileOperatingSystemFamily.LINUX),
("LINUX", StorageProfileOperatingSystemFamily.LINUX),
("LiNuX", StorageProfileOperatingSystemFamily.LINUX),
("macos", StorageProfileOperatingSystemFamily.MACOS),
("MACOS", StorageProfileOperatingSystemFamily.MACOS),
("maCOs", StorageProfileOperatingSystemFamily.MACOS),
],
)
def test_storage_profile_operating_system_family_case(
self, input: str, output: StorageProfileOperatingSystemFamily
) -> None:
"""
Tests that the correct enum types are created regardless of input string casing.
"""
assert StorageProfileOperatingSystemFamily(input) == output

@pytest.mark.parametrize(("input"), [("linuxx"), ("darwin"), ("oSx"), ("MSDOS")])
def test_storage_profile_operating_system_raises_type_error(self, input):
"""
Tests that a ValueError is raised when a non-valid string is given.
I.e. our case-insensitivity isn't causing false-positives.
"""
with pytest.raises(ValueError):
StorageProfileOperatingSystemFamily(input)

0 comments on commit 0da921c

Please sign in to comment.