@@ -446,11 +446,13 @@ def test_submit_with_auto_cluster(mocker):
446
446
447
447
def test_namespace_auto_detection_success (mocker ):
448
448
"""Test successful namespace auto-detection."""
449
+ mocker .patch ("kubernetes.config.load_kube_config" )
449
450
mocker .patch (
450
451
"codeflare_sdk.ray.rayjobs.rayjob.get_current_namespace" ,
451
452
return_value = "detected-ns" ,
452
453
)
453
454
mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
455
+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
454
456
455
457
rayjob = RayJob (
456
458
job_name = "test-job" , entrypoint = "python script.py" , cluster_name = "test-cluster"
@@ -461,10 +463,12 @@ def test_namespace_auto_detection_success(mocker):
461
463
462
464
def test_namespace_auto_detection_fallback (mocker ):
463
465
"""Test that namespace auto-detection failure raises an error."""
466
+ mocker .patch ("kubernetes.config.load_kube_config" )
464
467
mocker .patch (
465
468
"codeflare_sdk.ray.rayjobs.rayjob.get_current_namespace" , return_value = None
466
469
)
467
470
mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
471
+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
468
472
469
473
with pytest .raises (ValueError , match = "Could not auto-detect Kubernetes namespace" ):
470
474
RayJob (
@@ -476,11 +480,13 @@ def test_namespace_auto_detection_fallback(mocker):
476
480
477
481
def test_namespace_explicit_override (mocker ):
478
482
"""Test that explicit namespace overrides auto-detection."""
483
+ mocker .patch ("kubernetes.config.load_kube_config" )
479
484
mocker .patch (
480
485
"codeflare_sdk.ray.rayjobs.rayjob.get_current_namespace" ,
481
486
return_value = "detected-ns" ,
482
487
)
483
488
mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
489
+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
484
490
485
491
rayjob = RayJob (
486
492
job_name = "test-job" ,
@@ -494,7 +500,9 @@ def test_namespace_explicit_override(mocker):
494
500
495
501
def test_shutdown_behavior_with_cluster_config (mocker ):
496
502
"""Test that shutdown_after_job_finishes is True when cluster_config is provided."""
503
+ mocker .patch ("kubernetes.config.load_kube_config" )
497
504
mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
505
+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
498
506
499
507
from codeflare_sdk .ray .rayjobs .config import ManagedClusterConfig
500
508
@@ -512,7 +520,9 @@ def test_shutdown_behavior_with_cluster_config(mocker):
512
520
513
521
def test_shutdown_behavior_with_existing_cluster (mocker ):
514
522
"""Test that shutdown_after_job_finishes is False when using existing cluster."""
523
+ mocker .patch ("kubernetes.config.load_kube_config" )
515
524
mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
525
+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
516
526
517
527
rayjob = RayJob (
518
528
job_name = "test-job" ,
@@ -526,7 +536,9 @@ def test_shutdown_behavior_with_existing_cluster(mocker):
526
536
527
537
def test_rayjob_with_rayjob_cluster_config (mocker ):
528
538
"""Test RayJob with the new ManagedClusterConfig."""
539
+ mocker .patch ("kubernetes.config.load_kube_config" )
529
540
mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
541
+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
530
542
531
543
from codeflare_sdk .ray .rayjobs .config import ManagedClusterConfig
532
544
@@ -549,7 +561,9 @@ def test_rayjob_with_rayjob_cluster_config(mocker):
549
561
550
562
def test_rayjob_cluster_config_validation (mocker ):
551
563
"""Test validation of ManagedClusterConfig parameters."""
564
+ mocker .patch ("kubernetes.config.load_kube_config" )
552
565
mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
566
+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
553
567
554
568
from codeflare_sdk .ray .rayjobs .config import ManagedClusterConfig
555
569
@@ -621,7 +635,9 @@ def test_build_ray_cluster_spec_integration(mocker):
621
635
622
636
def test_rayjob_with_runtime_env (mocker ):
623
637
"""Test RayJob with runtime environment configuration."""
638
+ mocker .patch ("kubernetes.config.load_kube_config" )
624
639
mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
640
+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
625
641
626
642
runtime_env = {"pip" : ["numpy" , "pandas" ]}
627
643
@@ -642,7 +658,9 @@ def test_rayjob_with_runtime_env(mocker):
642
658
643
659
def test_rayjob_with_active_deadline_and_ttl (mocker ):
644
660
"""Test RayJob with both active deadline and TTL settings."""
661
+ mocker .patch ("kubernetes.config.load_kube_config" )
645
662
mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
663
+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
646
664
647
665
rayjob = RayJob (
648
666
job_name = "test-job" ,
@@ -664,7 +682,9 @@ def test_rayjob_with_active_deadline_and_ttl(mocker):
664
682
665
683
def test_rayjob_cluster_name_generation_with_config (mocker ):
666
684
"""Test cluster name generation when using cluster_config."""
685
+ mocker .patch ("kubernetes.config.load_kube_config" )
667
686
mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
687
+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
668
688
669
689
from codeflare_sdk .ray .rayjobs .config import ManagedClusterConfig
670
690
@@ -684,7 +704,9 @@ def test_rayjob_cluster_name_generation_with_config(mocker):
684
704
685
705
def test_rayjob_namespace_propagation_to_cluster_config (mocker ):
686
706
"""Test that job namespace is propagated to cluster config when None."""
707
+ mocker .patch ("kubernetes.config.load_kube_config" )
687
708
mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
709
+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
688
710
689
711
from codeflare_sdk .ray .rayjobs .rayjob import get_current_namespace
690
712
@@ -719,7 +741,9 @@ def test_rayjob_error_handling_invalid_cluster_config(mocker):
719
741
720
742
def test_rayjob_constructor_parameter_validation (mocker ):
721
743
"""Test constructor parameter validation."""
744
+ mocker .patch ("kubernetes.config.load_kube_config" )
722
745
mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
746
+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
723
747
724
748
# Test with valid parameters
725
749
rayjob = RayJob (
@@ -941,7 +965,9 @@ def test_build_ray_cluster_spec_with_image_pull_secrets(mocker):
941
965
942
966
def test_rayjob_user_override_shutdown_behavior (mocker ):
943
967
"""Test that user can override the auto-detected shutdown behavior."""
968
+ mocker .patch ("kubernetes.config.load_kube_config" )
944
969
mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
970
+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
945
971
946
972
# Test 1: User overrides shutdown to True even when using existing cluster
947
973
rayjob_existing_override = RayJob (
@@ -1009,6 +1035,7 @@ def test_submit_with_cluster_config_compatible_image_passes(self, mocker):
1009
1035
"""Test that submission passes with compatible cluster_config image."""
1010
1036
mocker .patch ("kubernetes.config.load_kube_config" )
1011
1037
mock_api_class = mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
1038
+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
1012
1039
mock_api_instance = MagicMock ()
1013
1040
mock_api_class .return_value = mock_api_instance
1014
1041
mock_api_instance .submit_job .return_value = True
@@ -1030,6 +1057,7 @@ def test_submit_with_cluster_config_incompatible_image_fails(self, mocker):
1030
1057
"""Test that submission fails with incompatible cluster_config image."""
1031
1058
mocker .patch ("kubernetes.config.load_kube_config" )
1032
1059
mock_api_class = mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
1060
+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
1033
1061
mock_api_instance = MagicMock ()
1034
1062
mock_api_class .return_value = mock_api_instance
1035
1063
@@ -1052,6 +1080,7 @@ def test_validate_ray_version_compatibility_method(self, mocker):
1052
1080
"""Test the _validate_ray_version_compatibility method directly."""
1053
1081
mocker .patch ("kubernetes.config.load_kube_config" )
1054
1082
mock_api_class = mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
1083
+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
1055
1084
mock_api_instance = MagicMock ()
1056
1085
mock_api_class .return_value = mock_api_instance
1057
1086
@@ -1087,6 +1116,7 @@ def test_validate_cluster_config_image_method(self, mocker):
1087
1116
"""Test the _validate_cluster_config_image method directly."""
1088
1117
mocker .patch ("kubernetes.config.load_kube_config" )
1089
1118
mock_api_class = mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
1119
+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
1090
1120
mock_api_instance = MagicMock ()
1091
1121
mock_api_class .return_value = mock_api_instance
1092
1122
@@ -1122,6 +1152,7 @@ def test_validate_cluster_config_image_edge_cases(self, mocker):
1122
1152
"""Test edge cases in _validate_cluster_config_image method."""
1123
1153
mocker .patch ("kubernetes.config.load_kube_config" )
1124
1154
mock_api_class = mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
1155
+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
1125
1156
mock_api_instance = MagicMock ()
1126
1157
mock_api_class .return_value = mock_api_instance
1127
1158
0 commit comments