Skip to content

Commit

Permalink
Add tests to cover change
Browse files Browse the repository at this point in the history
  • Loading branch information
tatiana committed Dec 2, 2024
1 parent 44c8646 commit 9bf426a
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,3 +772,36 @@ def test_delete_ray_cluster_exception(
with pytest.raises(AirflowException) as exc_info:
ray_hook.delete_ray_cluster(ray_cluster_yaml="test.yaml", gpu_device_plugin_yaml="gpu.yaml")
assert "Failed to delete Ray cluster: Cluster deletion failed" in str(exc_info.value)

@patch("ray_provider.hooks.RayHook.create_daemon_set")
@patch("ray_provider.hooks.RayHook.get_daemon_set", return_value=True)
def test_setup_ray_cluster_with_config_existing_daemon(self, mock_get_daemon_set, mock_create_daemon_set, ray_hook):
gpu_device_plugin_yaml = (
"https://raw.githubusercontent.com/NVIDIA/k8s-device-plugin/v0.9.0/nvidia-device-plugin.yml"
)
response = ray_hook._setup_gpu_driver(gpu_device_plugin_yaml)
assert response is None
mock_get_daemon_set.assert_called_once()
mock_create_daemon_set.assert_not_called()

@patch("ray_provider.hooks.RayHook.create_daemon_set")
@patch("ray_provider.hooks.RayHook.get_daemon_set", return_value=False)
def test_setup_ray_cluster_with_config_inexistent_daemon(
self, mock_get_daemon_set, mock_create_daemon_set, ray_hook
):
gpu_device_plugin_yaml = (
"https://raw.githubusercontent.com/NVIDIA/k8s-device-plugin/v0.9.0/nvidia-device-plugin.yml"
)
response = ray_hook._setup_gpu_driver(gpu_device_plugin_yaml)
assert response is None
mock_get_daemon_set.assert_called_once()
mock_create_daemon_set.assert_called_once()

@patch("ray_provider.hooks.RayHook.create_daemon_set")
@patch("ray_provider.hooks.RayHook.get_daemon_set")
def test_setup_ray_cluster_no_config(self, mock_get_daemon_set, mock_create_daemon_set, ray_hook):
gpu_device_plugin_yaml = ""
response = ray_hook._setup_gpu_driver(gpu_device_plugin_yaml)
assert response is None
mock_get_daemon_set.assert_not_called()
mock_create_daemon_set.assert_not_called()

0 comments on commit 9bf426a

Please sign in to comment.