Skip to content

Commit 4cf653d

Browse files
committed
updated test
Signed-off-by: Pat O'Connor <[email protected]>
1 parent c15a5ec commit 4cf653d

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

src/codeflare_sdk/ray/rayjobs/test_rayjob.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,14 @@ def test_rayjob_submit_failure(mocker):
8989
rayjob.submit()
9090

9191

92-
def test_rayjob_init_validation_both_provided():
92+
def test_rayjob_init_validation_both_provided(mocker):
9393
"""Test that providing both cluster_name and cluster_config raises error."""
94+
# Mock kubernetes config loading
95+
mocker.patch("kubernetes.config.load_kube_config")
96+
97+
# Mock the RayjobApi class entirely
98+
mocker.patch("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi")
99+
94100
cluster_config = ClusterConfiguration(name="test-cluster", namespace="test")
95101

96102
with pytest.raises(
@@ -104,16 +110,28 @@ def test_rayjob_init_validation_both_provided():
104110
)
105111

106112

107-
def test_rayjob_init_validation_neither_provided():
113+
def test_rayjob_init_validation_neither_provided(mocker):
108114
"""Test that providing neither cluster_name nor cluster_config raises error."""
115+
# Mock kubernetes config loading (though this should fail before reaching it)
116+
mocker.patch("kubernetes.config.load_kube_config")
117+
118+
# Mock the RayjobApi class entirely (though this should fail before reaching it)
119+
mocker.patch("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi")
120+
109121
with pytest.raises(
110122
ValueError, match="Either cluster_name or cluster_config must be provided"
111123
):
112124
RayJob(job_name="test-job", entrypoint="python script.py")
113125

114126

115-
def test_rayjob_init_with_cluster_config():
127+
def test_rayjob_init_with_cluster_config(mocker):
116128
"""Test RayJob initialization with cluster configuration for auto-creation."""
129+
# Mock kubernetes config loading
130+
mocker.patch("kubernetes.config.load_kube_config")
131+
132+
# Mock the RayjobApi class entirely
133+
mocker.patch("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi")
134+
117135
cluster_config = ClusterConfiguration(
118136
name="auto-cluster", namespace="test-namespace", num_workers=2
119137
)
@@ -130,8 +148,14 @@ def test_rayjob_init_with_cluster_config():
130148
assert rayjob._cluster_name is None
131149

132150

133-
def test_rayjob_cluster_name_generation():
151+
def test_rayjob_cluster_name_generation(mocker):
134152
"""Test that cluster names are generated when config has empty name."""
153+
# Mock kubernetes config loading
154+
mocker.patch("kubernetes.config.load_kube_config")
155+
156+
# Mock the RayjobApi class entirely
157+
mocker.patch("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi")
158+
135159
cluster_config = ClusterConfiguration(
136160
name="", # Empty name should trigger generation
137161
namespace="test-namespace",
@@ -150,6 +174,9 @@ def test_rayjob_cluster_name_generation():
150174
def test_build_ray_cluster_spec(mock_build_ray_cluster, mocker):
151175
"""Test _build_ray_cluster_spec method."""
152176
mocker.patch("kubernetes.config.load_kube_config")
177+
178+
# Mock the RayjobApi class entirely
179+
mocker.patch("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi")
153180

154181
mock_ray_cluster = {
155182
"apiVersion": "ray.io/v1",
@@ -189,6 +216,9 @@ def test_build_ray_cluster_spec(mock_build_ray_cluster, mocker):
189216
def test_build_rayjob_cr_with_existing_cluster(mocker):
190217
"""Test _build_rayjob_cr method with existing cluster."""
191218
mocker.patch("kubernetes.config.load_kube_config")
219+
220+
# Mock the RayjobApi class entirely
221+
mocker.patch("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi")
192222

193223
rayjob = RayJob(
194224
job_name="test-job",
@@ -221,6 +251,9 @@ def test_build_rayjob_cr_with_existing_cluster(mocker):
221251
def test_build_rayjob_cr_with_auto_cluster(mock_build_ray_cluster, mocker):
222252
"""Test _build_rayjob_cr method with auto-created cluster."""
223253
mocker.patch("kubernetes.config.load_kube_config")
254+
255+
# Mock the RayjobApi class entirely
256+
mocker.patch("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi")
224257

225258
mock_ray_cluster = {
226259
"apiVersion": "ray.io/v1",
@@ -270,6 +303,9 @@ def test_submit_validation_no_entrypoint(mocker):
270303
def test_submit_with_auto_cluster(mock_build_ray_cluster, mocker):
271304
"""Test successful submission with auto-created cluster."""
272305
mocker.patch("kubernetes.config.load_kube_config")
306+
307+
# Mock the RayjobApi class entirely
308+
mocker.patch("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi")
273309

274310
mock_ray_cluster = {
275311
"apiVersion": "ray.io/v1",

0 commit comments

Comments
 (0)