-
Notifications
You must be signed in to change notification settings - Fork 486
[WIP] add unit tests for katib sdk #2305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import multiprocessing | ||
import pytest | ||
from unittest.mock import patch, Mock | ||
from kubeflow.katib import models | ||
from kubeflow.katib.api.katib_client import KatibClient | ||
|
||
@pytest.fixture | ||
def katib_client(): | ||
return KatibClient() | ||
|
||
@pytest.fixture | ||
def valid_experiment(): | ||
return models.V1beta1Experiment( | ||
metadata=models.V1ObjectMeta(name="test-experiment"), | ||
spec=models.V1beta1ExperimentSpec() | ||
) | ||
|
||
class TestCreateExperiment: | ||
@patch('kubeflow.katib.api.katib_client.client.CustomObjectsApi.create_namespaced_custom_object') | ||
def test_create_experiment_success(self, mock_create_namespaced_custom_object, katib_client, valid_experiment): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think, it would be nice if you could add unit test to verify these conditions: https://github.com/kubeflow/katib/blob/master/sdk/python/v1beta1/kubeflow/katib/api/katib_client.py#L96-L108. |
||
mock_create_namespaced_custom_object.return_value = {"metadata": {"name": "test-experiment"}} | ||
experiment = katib_client.create_experiment(valid_experiment) | ||
assert experiment == "Experiment default/test-experiment has been created" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
@patch('kubeflow.katib.api.katib_client.client.CustomObjectsApi.create_namespaced_custom_object') | ||
def test_create_experiment_timeout_error(self, mock_create_namespaced_custom_object, katib_client, valid_experiment): | ||
mock_create_namespaced_custom_object.side_effect = multiprocessing.TimeoutError() | ||
with pytest.raises(TimeoutError): | ||
katib_client.create_experiment(valid_experiment, namespace="timeout") | ||
|
||
@patch('kubeflow.katib.api.katib_client.client.CustomObjectsApi.create_namespaced_custom_object') | ||
def test_create_experiment_runtime_error(self, mock_create_namespaced_custom_object, katib_client, valid_experiment): | ||
mock_create_namespaced_custom_object.side_effect = RuntimeError() | ||
with pytest.raises(RuntimeError): | ||
katib_client.create_experiment(valid_experiment, namespace="runtime") | ||
Comment on lines
+28
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we testing here that |
||
|
||
class TestGetExperiment: | ||
@patch('kubeflow.katib.api.katib_client.client.CustomObjectsApi.get_namespaced_custom_object') | ||
def test_get_experiment_success(self, mock_get_namespaced_custom_object, katib_client, valid_experiment): | ||
mock_response = {"metadata": {"name": "test-experiment"}, "spec": {}, "status": {}} | ||
mock_get_namespaced_custom_object.return_value = mock_response | ||
experiment = katib_client.get_experiment("test-experiment") | ||
assert experiment == valid_experiment | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I can see, |
||
@patch('kubeflow.katib.api.katib_client.client.CustomObjectsApi.get_namespaced_custom_object') | ||
def test_get_experiment_timeout_error(self, mock_get_namespaced_custom_object, katib_client): | ||
mock_get_namespaced_custom_object.side_effect = multiprocessing.TimeoutError() | ||
with pytest.raises(TimeoutError): | ||
katib_client.get_experiment("test-experiment", namespace="timeout") | ||
|
||
@patch('kubeflow.katib.api.katib_client.client.CustomObjectsApi.get_namespaced_custom_object') | ||
def test_get_experiment_runtime_error(self, mock_get_namespaced_custom_object, katib_client): | ||
mock_get_namespaced_custom_object.side_effect = RuntimeError() | ||
with pytest.raises(RuntimeError): | ||
katib_client.get_experiment("test-experiment", namespace="runtime") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need this change ?