Skip to content

Commit b28b5e1

Browse files
committed
Fix unit tests
1 parent fac4b2f commit b28b5e1

File tree

2 files changed

+31
-20
lines changed

2 files changed

+31
-20
lines changed

src/codeflare_sdk/common/kueue/test_kueue.py

+20-14
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
from ..utils.unit_test_support import get_local_queue, createClusterConfig
14+
from ..utils.unit_test_support import (
15+
apply_template,
16+
get_local_queue,
17+
createClusterConfig,
18+
get_template_variables,
19+
)
1520
from unittest.mock import patch
1621
from codeflare_sdk.ray.cluster.cluster import Cluster, ClusterConfiguration
1722
import yaml
@@ -52,21 +57,21 @@ def test_cluster_creation_no_aw_local_queue(mocker):
5257
config.local_queue = "local-queue-default"
5358
cluster = Cluster(config)
5459
assert cluster.resource_yaml == f"{aw_dir}unit-test-cluster-kueue.yaml"
55-
assert filecmp.cmp(
56-
f"{aw_dir}unit-test-cluster-kueue.yaml",
60+
expected_rc = apply_template(
5761
f"{parent}/tests/test_cluster_yamls/kueue/ray_cluster_kueue.yaml",
58-
shallow=True,
62+
get_template_variables(),
5963
)
6064

65+
with open(f"{aw_dir}unit-test-cluster-kueue.yaml", "r") as f:
66+
cluster_kueue = yaml.load(f, Loader=yaml.FullLoader)
67+
assert cluster_kueue == expected_rc
68+
6169
# With resources loaded in memory, no Local Queue specified.
6270
config = createClusterConfig()
6371
config.name = "unit-test-cluster-kueue"
6472
config.write_to_file = False
6573
cluster = Cluster(config)
66-
67-
with open(f"{parent}/tests/test_cluster_yamls/kueue/ray_cluster_kueue.yaml") as f:
68-
expected_rc = yaml.load(f, Loader=yaml.FullLoader)
69-
assert cluster.resource_yaml == expected_rc
74+
assert cluster.resource_yaml == expected_rc
7075

7176

7277
def test_aw_creation_local_queue(mocker):
@@ -86,22 +91,23 @@ def test_aw_creation_local_queue(mocker):
8691
config.local_queue = "local-queue-default"
8792
cluster = Cluster(config)
8893
assert cluster.resource_yaml == f"{aw_dir}unit-test-aw-kueue.yaml"
89-
assert filecmp.cmp(
90-
f"{aw_dir}unit-test-aw-kueue.yaml",
94+
expected_rc = apply_template(
9195
f"{parent}/tests/test_cluster_yamls/kueue/aw_kueue.yaml",
92-
shallow=True,
96+
get_template_variables(),
9397
)
9498

99+
with open(f"{aw_dir}unit-test-aw-kueue.yaml", "r") as f:
100+
aw_kueue = yaml.load(f, Loader=yaml.FullLoader)
101+
assert aw_kueue == expected_rc
102+
95103
# With resources loaded in memory, no Local Queue specified.
96104
config = createClusterConfig()
97105
config.name = "unit-test-aw-kueue"
98106
config.appwrapper = True
99107
config.write_to_file = False
100108
cluster = Cluster(config)
101109

102-
with open(f"{parent}/tests/test_cluster_yamls/kueue/aw_kueue.yaml") as f:
103-
expected_rc = yaml.load(f, Loader=yaml.FullLoader)
104-
assert cluster.resource_yaml == expected_rc
110+
assert cluster.resource_yaml == expected_rc
105111

106112

107113
def test_get_local_queue_exists_fail(mocker):

src/codeflare_sdk/ray/cluster/test_config.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
# limitations under the License.
1414

1515
from codeflare_sdk.common.utils.unit_test_support import (
16+
apply_template,
1617
createClusterWrongType,
1718
get_local_queue,
1819
create_cluster_all_config_params,
20+
get_template_variables,
1921
)
2022
from codeflare_sdk.ray.cluster.cluster import ClusterConfiguration, Cluster
2123
from pathlib import Path
@@ -36,9 +38,11 @@ def test_default_cluster_creation(mocker):
3638

3739
cluster = Cluster(ClusterConfiguration(name="default-cluster", namespace="ns"))
3840

39-
with open(f"{expected_clusters_dir}/ray/default-ray-cluster.yaml") as f:
40-
expected_rc = yaml.load(f, Loader=yaml.FullLoader)
41-
assert cluster.resource_yaml == expected_rc
41+
expected_rc = apply_template(
42+
f"{expected_clusters_dir}/ray/default-ray-cluster.yaml",
43+
get_template_variables(),
44+
)
45+
assert cluster.resource_yaml == expected_rc
4246

4347

4448
def test_default_appwrapper_creation(mocker):
@@ -50,9 +54,10 @@ def test_default_appwrapper_creation(mocker):
5054
ClusterConfiguration(name="default-appwrapper", namespace="ns", appwrapper=True)
5155
)
5256

53-
with open(f"{expected_clusters_dir}/ray/default-appwrapper.yaml") as f:
54-
expected_aw = yaml.load(f, Loader=yaml.FullLoader)
55-
assert cluster.resource_yaml == expected_aw
57+
expected_aw = apply_template(
58+
f"{expected_clusters_dir}/ray/default-appwrapper.yaml", get_template_variables()
59+
)
60+
assert cluster.resource_yaml == expected_aw
5661

5762

5863
def test_config_creation_all_parameters(mocker):

0 commit comments

Comments
 (0)