Skip to content

Commit b52e9bc

Browse files
committed
task(RHOAIENG-30722) fix unit test
1 parent fa8701b commit b52e9bc

File tree

5 files changed

+46
-27
lines changed

5 files changed

+46
-27
lines changed

docs/sphinx/user-docs/ray-cluster-interaction.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ list_all_clusters()
6161
The following methods require a ``Cluster`` object to be
6262
initialized. See :doc:`./cluster-configuration`
6363

64-
cluster.up()
65-
------------
66-
67-
| The ``cluster.up()`` function creates a Ray Cluster in the given namespace.
68-
6964
cluster.apply()
7065
------------
7166

src/codeflare_sdk/ray/cluster/cluster.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,9 @@ def apply(self, force=False):
241241
except AttributeError as e:
242242
raise RuntimeError(f"Failed to initialize DynamicClient: {e}")
243243
except Exception as e: # pragma: no cover
244-
if e.status == 422:
244+
if (
245+
hasattr(e, "status") and e.status == 422
246+
): # adding status check to avoid returning false positive
245247
print(
246248
"WARNING: RayCluster creation rejected due to invalid Kueue configuration. Please contact your administrator."
247249
)

src/codeflare_sdk/ray/cluster/pretty_print.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@
3030

3131
def print_no_resources_found():
3232
console = Console()
33-
console.print(Panel("[red]No resources found, have you run cluster.apply() yet? Run cluster.details() to check if it's ready."))
33+
console.print(
34+
Panel(
35+
"[red]No resources found, have you run cluster.apply() yet? Run cluster.details() to check if it's ready."
36+
)
37+
)
3438

3539

3640
def print_app_wrappers_status(app_wrappers: List[AppWrapper], starting: bool = False):

src/codeflare_sdk/ray/cluster/test_cluster.py

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def test_cluster_apply_down(mocker):
4949
mocker.patch("kubernetes.client.ApisApi.get_api_versions")
5050
mocker.patch("kubernetes.config.load_kube_config", return_value="ignore")
5151
mocker.patch("codeflare_sdk.ray.cluster.cluster.Cluster._throw_for_no_raycluster")
52+
mocker.patch("codeflare_sdk.ray.cluster.cluster.Cluster.get_dynamic_client")
5253
mocker.patch(
5354
"kubernetes.client.CustomObjectsApi.get_cluster_custom_object",
5455
return_value={"spec": {"domain": ""}},
@@ -256,6 +257,7 @@ def test_cluster_apply_down_no_mcad(mocker):
256257
mocker.patch("codeflare_sdk.ray.cluster.cluster.Cluster._throw_for_no_raycluster")
257258
mocker.patch("kubernetes.config.load_kube_config", return_value="ignore")
258259
mocker.patch("kubernetes.client.ApisApi.get_api_versions")
260+
mocker.patch("codeflare_sdk.ray.cluster.cluster.Cluster.get_dynamic_client")
259261
mocker.patch(
260262
"kubernetes.client.CustomObjectsApi.list_namespaced_custom_object",
261263
return_value=get_local_queue("kueue.x-k8s.io", "v1beta1", "ns", "localqueues"),
@@ -569,11 +571,15 @@ def test_list_queue_appwrappers(mocker, capsys):
569571
)
570572
list_all_queued("ns", appwrapper=True)
571573
captured = capsys.readouterr()
572-
assert captured.out == (
573-
"╭──────────────────────────────────────────────────────────────────────────────╮\n"
574-
"│ No resources found, have you run cluster.apply() yet? Run cluster.details() to check if it's ready. │\n"
575-
"╰──────────────────────────────────────────────────────────────────────────────╯\n"
576-
)
574+
# The Rich library's console width detection varies between test contexts
575+
# Accept either the two-line format (individual tests) or single-line format (full test suite)
576+
# Check for key parts of the message instead of the full text
577+
assert "No resources found" in captured.out
578+
assert "cluster.apply()" in captured.out
579+
assert "cluster.details()" in captured.out
580+
assert "check if it's ready" in captured.out
581+
assert "╭" in captured.out and "╮" in captured.out # Check for box characters
582+
assert "│" in captured.out # Check for vertical lines
577583
mocker.patch(
578584
"kubernetes.client.CustomObjectsApi.list_namespaced_custom_object",
579585
return_value=get_aw_obj_with_status(
@@ -614,11 +620,15 @@ def test_list_queue_rayclusters(mocker, capsys):
614620

615621
list_all_queued("ns")
616622
captured = capsys.readouterr()
617-
assert captured.out == (
618-
"╭──────────────────────────────────────────────────────────────────────────────╮\n"
619-
"│ No resources found, have you run cluster.apply() yet? Run cluster.details() to check if it's ready. │\n"
620-
"╰──────────────────────────────────────────────────────────────────────────────╯\n"
621-
)
623+
# The Rich library's console width detection varies between test contexts
624+
# Accept either the two-line format (individual tests) or single-line format (full test suite)
625+
# Check for key parts of the message instead of the full text
626+
assert "No resources found" in captured.out
627+
assert "cluster.apply()" in captured.out
628+
assert "cluster.details()" in captured.out
629+
assert "check if it's ready" in captured.out
630+
assert "╭" in captured.out and "╮" in captured.out # Check for box characters
631+
assert "│" in captured.out # Check for vertical lines
622632
mocker.patch(
623633
"kubernetes.client.CustomObjectsApi.list_namespaced_custom_object",
624634
return_value=get_ray_obj_with_status("ray.io", "v1", "ns", "rayclusters"),
@@ -656,11 +666,15 @@ def test_list_clusters(mocker, capsys):
656666
)
657667
list_all_clusters("ns")
658668
captured = capsys.readouterr()
659-
assert captured.out == (
660-
"╭──────────────────────────────────────────────────────────────────────────────╮\n"
661-
"│ No resources found, have you run cluster.apply() yet? Run cluster.details() to check if it's ready. │\n"
662-
"╰──────────────────────────────────────────────────────────────────────────────╯\n"
663-
)
669+
# The Rich library's console width detection varies between test contexts
670+
# Accept either the two-line format (individual tests) or single-line format (full test suite)
671+
# Check for key parts of the message instead of the full text
672+
assert "No resources found" in captured.out
673+
assert "cluster.apply()" in captured.out
674+
assert "cluster.details()" in captured.out
675+
assert "check if it's ready" in captured.out
676+
assert "╭" in captured.out and "╮" in captured.out # Check for box characters
677+
assert "│" in captured.out # Check for vertical lines
664678
mocker.patch(
665679
"kubernetes.client.CustomObjectsApi.list_namespaced_custom_object",
666680
side_effect=get_ray_obj,

src/codeflare_sdk/ray/cluster/test_pretty_print.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,15 @@ def test_print_no_resources(capsys):
3838
except Exception:
3939
assert 1 == 0
4040
captured = capsys.readouterr()
41-
assert captured.out == (
42-
"╭──────────────────────────────────────────────────────────────────────────────╮\n"
43-
"│ No resources found, have you run cluster.apply() yet? Run cluster.details() to check if it's ready. │\n"
44-
"╰──────────────────────────────────────────────────────────────────────────────╯\n"
45-
)
41+
# The Rich library's console width detection varies between test contexts
42+
# Accept either the two-line format (individual tests) or single-line format (full test suite)
43+
# Check for key parts of the message instead of the full text
44+
assert "No resources found" in captured.out
45+
assert "cluster.apply()" in captured.out
46+
assert "cluster.details()" in captured.out
47+
assert "check if it's ready" in captured.out
48+
assert "╭" in captured.out and "╮" in captured.out # Check for box characters
49+
assert "│" in captured.out # Check for vertical lines
4650

4751

4852
def test_print_appwrappers(capsys):

0 commit comments

Comments
 (0)