Skip to content

Commit

Permalink
refactor: update formatting using black
Browse files Browse the repository at this point in the history
  • Loading branch information
dimakis authored and anishasthana committed Nov 9, 2023
1 parent e452eff commit 7f25549
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
5 changes: 2 additions & 3 deletions src/codeflare_sdk/cluster/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,13 @@ def evaluate_dispatch_priority(self):
def validate_image_config(self):
"""
Validates that the image configuration is not empty.
:param image: The image string to validate
:raises ValueError: If the image is not specified
"""
if self.config.image == "" or self.config.image == None:
raise ValueError("Image must be specified in the ClusterConfiguration")


def create_app_wrapper(self):
"""
Called upon cluster object creation, creates an AppWrapper yaml based on
Expand All @@ -153,7 +152,7 @@ def create_app_wrapper(self):
raise TypeError(
f"Namespace {self.config.namespace} is of type {type(self.config.namespace)}. Check your Kubernetes Authentication."
)

# Validate image configuration
self.validate_image_config()

Expand Down
41 changes: 33 additions & 8 deletions tests/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ def test_config_creation():
assert config.dispatch_priority == None
assert config.mcad == True
assert config.local_interactive == False



def test_cluster_creation(mocker):
Expand All @@ -262,7 +261,8 @@ def test_cluster_creation(mocker):
assert filecmp.cmp(
"unit-test-cluster.yaml", f"{parent}/tests/test-case.yaml", shallow=True
)



def test_create_app_wrapper_raises_error_with_no_image():
config = createClusterConfig()
config.image = "" # Clear the image to test error handling
Expand All @@ -271,8 +271,9 @@ def test_create_app_wrapper_raises_error_with_no_image():
cluster.create_app_wrapper()
assert False, "Expected ValueError when 'image' is not specified."
except ValueError as error:
assert str(error) == "Image must be specified in the ClusterConfiguration", \
"Error message did not match expected output."
assert (
str(error) == "Image must be specified in the ClusterConfiguration"
), "Error message did not match expected output."


def test_cluster_creation_no_mcad(mocker):
Expand Down Expand Up @@ -748,7 +749,13 @@ def test_ray_details(mocker, capsys):
"codeflare_sdk.cluster.cluster.Cluster.cluster_dashboard_uri",
return_value="",
)
cf = Cluster(ClusterConfiguration(name="raytest2", namespace="ns", image= "quay.io/project-codeflare/ray:latest-py39-cu118"))
cf = Cluster(
ClusterConfiguration(
name="raytest2",
namespace="ns",
image="quay.io/project-codeflare/ray:latest-py39-cu118",
)
)
captured = capsys.readouterr()
ray2 = _copy_to_ray(cf)
details = cf.details()
Expand Down Expand Up @@ -1914,7 +1921,13 @@ def test_cluster_status(mocker):
head_mem=8,
head_gpu=0,
)
cf = Cluster(ClusterConfiguration(name="test", namespace="ns", image="quay.io/project-codeflare/ray:latest-py39-cu118"))
cf = Cluster(
ClusterConfiguration(
name="test",
namespace="ns",
image="quay.io/project-codeflare/ray:latest-py39-cu118",
)
)
mocker.patch("codeflare_sdk.cluster.cluster._app_wrapper_status", return_value=None)
mocker.patch("codeflare_sdk.cluster.cluster._ray_cluster_status", return_value=None)
status, ready = cf.status()
Expand Down Expand Up @@ -2004,7 +2017,13 @@ def test_wait_ready(mocker, capsys):
mock_response = mocker.Mock()
mock_response.status_code = 200
mocker.patch("requests.get", return_value=mock_response)
cf = Cluster(ClusterConfiguration(name="test", namespace="ns", image= "quay.io/project-codeflare/ray:latest-py39-cu118"))
cf = Cluster(
ClusterConfiguration(
name="test",
namespace="ns",
image="quay.io/project-codeflare/ray:latest-py39-cu118",
)
)
try:
cf.wait_ready(timeout=5)
assert 1 == 0
Expand Down Expand Up @@ -2669,7 +2688,13 @@ def test_gen_app_wrapper_with_oauth(mocker: MockerFixture):
mocker.patch(
"codeflare_sdk.utils.generate_yaml.write_user_appwrapper", write_user_appwrapper
)
Cluster(ClusterConfiguration("test_cluster", openshift_oauth=True, image= "quay.io/project-codeflare/ray:latest-py39-cu118"))
Cluster(
ClusterConfiguration(
"test_cluster",
openshift_oauth=True,
image="quay.io/project-codeflare/ray:latest-py39-cu118",
)
)
user_yaml = write_user_appwrapper.call_args.args[0]
assert any(
container["name"] == "oauth-proxy"
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_test_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def createClusterConfig():
machine_types=["cpu.small", "gpu.large"],
image_pull_secrets=["unit-test-pull-secret"],
ingress_domain="apps.cluster.awsroute.org",
image="quay.io/project-codeflare/ray:latest-py39-cu118"
image="quay.io/project-codeflare/ray:latest-py39-cu118",
)
return config

Expand Down

0 comments on commit 7f25549

Please sign in to comment.