Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] [Feature] Modular stacks #205

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Prev Previous commit
Next Next commit
[RPD-308] Add stack module validation #206
Christopher-Norman authored Aug 24, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 6722ba6dcdd5780077e7bb471c4039b0f92a1c5f
44 changes: 44 additions & 0 deletions src/matcha_ml/core/_validation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
""""Validation for core commands."""

from enum import Enum, EnumMeta

from matcha_ml.errors import MatchaInputError
from matcha_ml.services import AzureClient

@@ -8,6 +10,36 @@
MAXIMUM_RESOURCE_NAME_LEN = 24


class StackModuleMeta(EnumMeta):
"""Metaclass for the StackModule Enum."""

def __contains__(self, item: str) -> bool: # type: ignore
"""Method for checking if an item is a member of the enum.
Args:
item (str): the quantity to check for in the Enum.
Returns:
True if item is a member of the Enum, False otherwise.
"""
try:
self(item)
except ValueError:
return False
else:
return True


class StackModule(Enum, metaclass=StackModuleMeta):
"""Enum defining valid matcha stack modules."""

ZENML = "zenml"
COMMON = "common"
DVC = "dvc"
MLFLOW = "mlflow"
SELDON = "seldon"


def _is_alphanumeric(prefix: str) -> bool:
"""Check whether the prefix is an alphanumeric string.
@@ -100,3 +132,15 @@ def is_valid_region(region: str) -> bool:
"""
azure_client = AzureClient()
return bool(azure_client.is_valid_region(region))


def stack_module_is_valid(module: str) -> bool:
"""Checks whether a module name is valid.
Args:
module (str): The name of the stack module.
Returns:
bool: True, if the module exists in the StackModule enum, otherwise, False.
"""
return module in StackModule
16 changes: 16 additions & 0 deletions tests/test_core/test_core_validation.py
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
_is_alphanumeric,
_is_not_digits,
is_valid_prefix,
stack_module_is_valid,
)
from matcha_ml.errors import MatchaInputError

@@ -96,3 +97,18 @@ def test_is_valid_prefix_invalid(
is_valid_prefix(prefix)

assert str(err.value) == error_msg


def test_stack_module_is_valid_with_valid_module():
"""Test stack module validation returns True when the module is valid."""
assert stack_module_is_valid("zenml")


def test_stack_module_is_valid_with_valid_module_with_upper_case():
"""Test stack module validation returns False when the module is fully upper case and not valid."""
assert not stack_module_is_valid("ZENML")


def test_stack_module_is_valid_with_invalid_module():
"""Test stack module validation returns False when the module does not exist."""
assert not stack_module_is_valid("invalidmodule")