[ENH] V1 -> V2 Migration - Flows (module)#1609
[ENH] V1 -> V2 Migration - Flows (module)#1609Omswastik-11 wants to merge 110 commits intoopenml:mainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1609 +/- ##
==========================================
- Coverage 52.04% 47.57% -4.47%
==========================================
Files 36 63 +27
Lines 4333 5070 +737
==========================================
+ Hits 2255 2412 +157
- Misses 2078 2658 +580 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: Omswastik-11 <omswastikpanda11@gmail.com>
614411f to
36184e5
Compare
for more information, see https://pre-commit.ci
|
Hi @geetu040 !! Can you review the pre-commit failure It was due to merge conflicts more specifically for tasks . Should I change it on my branch ? |
can you try again, sync your branch with mine? It should be fixed now. |
|
I think that due to conflicts it did not synced properly . I have to revert it manually |
geetu040
left a comment
There was a problem hiding this comment.
Nice overall, few changes needed. I'll look at the tests later when the implementation is final.
Signed-off-by: Omswastik-11 <omswastikpanda11@gmail.com>
Signed-off-by: Omswastik-11 <omswastikpanda11@gmail.com>
Signed-off-by: Omswastik-11 <omswastikpanda11@gmail.com>
This reverts commit fd43c48.
…into flow-migration-stacked # Conflicts: # openml/_api/setup/config.py
- removing this since it was not part of the sdk previously - some tests fail because of the timeout in stacked PRs - this option can easily be added if needed in future
…into flow-migration-stacked
| @mock.patch("openml.flows.functions.get_flow") | ||
| @mock.patch("openml.flows.functions.flow_exists") | ||
| @mock.patch("openml._api_calls._perform_api_call") | ||
| def test_publish_error(self, api_call_mock, flow_exists_mock, get_flow_mock): |
There was a problem hiding this comment.
what's happening here, doesn't look right, can you please explain?
There was a problem hiding this comment.
I thought we are not using openml._api_calls._perform_api_call anymore
There was a problem hiding this comment.
There was a problem hiding this comment.
https://github.com/openml/openml-python/pull/1609/changes#r2687563796
this comment was mentioned "resolved" but was never really answered, the question is still there: why skipping these tests?
There was a problem hiding this comment.
@pytest.mark.sklearn()
@mock.patch("openml.flows.functions.get_flow")
@mock.patch("openml._api_calls._perform_api_call")
@mock.patch("openml.flows.functions.flow_exists")
def test_publish_error(self, api_call_mock, flow_exists_mock, get_flow_mock):
model = sklearn.ensemble.RandomForestClassifier()
flow = self.extension.model_to_flow(model)
api_call_mock.return_value = (
"<oml:upload_flow>\n" " <oml:id>1</oml:id>\n" "</oml:upload_flow>"
)
flow_exists_mock.return_value = False
get_flow_mock.return_value = flow
flow.publish()
# Not collecting flow_id for deletion since this is a test for failed upload
assert api_call_mock.call_count == 1
assert get_flow_mock.call_count == 1
assert flow_exists_mock.call_count == 1
flow_copy = copy.deepcopy(flow)
flow_copy.name = flow_copy.name[:-1]
get_flow_mock.return_value = flow_copy
flow_exists_mock.return_value = 1
if Version(sklearn.__version__) < Version("0.22"):
fixture = (
"The flow on the server is inconsistent with the local flow. "
"The server flow ID is 1. Please check manually and remove "
"the flow if necessary! Error is:\n"
"'Flow sklearn.ensemble.forest.RandomForestClassifier: "
"values for attribute 'name' differ: "
"'sklearn.ensemble.forest.RandomForestClassifier'"
"\nvs\n'sklearn.ensemble.forest.RandomForestClassifie'.'"
)
else:
# sklearn.ensemble.forest -> sklearn.ensemble._forest
fixture = (
"The flow on the server is inconsistent with the local flow. "
"The server flow ID is 1. Please check manually and remove "
"the flow if necessary! Error is:\n"
"'Flow sklearn.ensemble._forest.RandomForestClassifier: "
"values for attribute 'name' differ: "
"'sklearn.ensemble._forest.RandomForestClassifier'"
"\nvs\n'sklearn.ensemble._forest.RandomForestClassifie'.'"
)
with pytest.raises(ValueError, match=fixture):
flow.publish()
TestBase._mark_entity_for_removal("flow", flow.flow_id, flow.name)
TestBase.logger.info(
f"collected from {__file__.split('/')[-1]}: {flow.flow_id}",
)
assert get_flow_mock.call_count == 2
@mock.patch.object(requests.Session, "delete")
def test_delete_flow_not_owned(mock_delete, test_files_directory, test_api_key):
openml.config.start_using_configuration_for_example()
content_file = test_files_directory / "mock_responses" / "flows" / "flow_delete_not_owned.xml"
mock_delete.return_value = create_request_response(
status_code=412,
content_filepath=content_file,
)
with pytest.raises(
OpenMLNotAuthorizedError,
match="The flow can not be deleted because it was not uploaded by you.",
):
openml.flows.delete_flow(40_000)
flow_url = "https://test.openml.org/api/v1/xml/flow/40000"
assert flow_url == mock_delete.call_args.args[0]
assert test_api_key == mock_delete.call_args.kwargs.get("params", {}).get("api_key")
@mock.patch.object(requests.Session, "delete")
def test_delete_flow_with_run(mock_delete, test_files_directory, test_api_key):
openml.config.start_using_configuration_for_example()
content_file = test_files_directory / "mock_responses" / "flows" / "flow_delete_has_runs.xml"
mock_delete.return_value = create_request_response(
status_code=412,
content_filepath=content_file,
)
with pytest.raises(
OpenMLNotAuthorizedError,
match="The flow can not be deleted because it still has associated entities:",
):
openml.flows.delete_flow(40_000)
flow_url = "https://test.openml.org/api/v1/xml/flow/40000"
assert flow_url == mock_delete.call_args.args[0]
assert test_api_key == mock_delete.call_args.kwargs.get("params", {}).get("api_key")
@mock.patch.object(requests.Session, "delete")
def test_delete_subflow(mock_delete, test_files_directory, test_api_key):
openml.config.start_using_configuration_for_example()
content_file = test_files_directory / "mock_responses" / "flows" / "flow_delete_is_subflow.xml"
mock_delete.return_value = create_request_response(
status_code=412,
content_filepath=content_file,
)
with pytest.raises(
OpenMLNotAuthorizedError,
match="The flow can not be deleted because it still has associated entities:",
):
openml.flows.delete_flow(40_000)
flow_url = "https://test.openml.org/api/v1/xml/flow/40000"
assert flow_url == mock_delete.call_args.args[0]
assert test_api_key == mock_delete.call_args.kwargs.get("params", {}).get("api_key")
@mock.patch.object(requests.Session, "delete")
def test_delete_flow_success(mock_delete, test_files_directory, test_api_key):
openml.config.start_using_configuration_for_example()
content_file = test_files_directory / "mock_responses" / "flows" / "flow_delete_successful.xml"
mock_delete.return_value = create_request_response(
status_code=200,
content_filepath=content_file,
)
success = openml.flows.delete_flow(33364)
assert success
flow_url = "https://test.openml.org/api/v1/xml/flow/33364"
assert flow_url == mock_delete.call_args.args[0]
assert test_api_key == mock_delete.call_args.kwargs.get("params", {}).get("api_key")
@mock.patch.object(requests.Session, "delete")
@pytest.mark.xfail(reason="failures_issue_1544", strict=False)
def test_delete_unknown_flow(mock_delete, test_files_directory, test_api_key):
openml.config.start_using_configuration_for_example()
content_file = test_files_directory / "mock_responses" / "flows" / "flow_delete_not_exist.xml"
mock_delete.return_value = create_request_response(
status_code=412,
content_filepath=content_file,
)
with pytest.raises(
OpenMLServerException,
match="flow does not exist",
):
openml.flows.delete_flow(9_999_999)
flow_url = "https://test.openml.org/api/v1/xml/flow/9999999"
assert flow_url == mock_delete.call_args.args[0]
assert test_api_key == mock_delete.call_args.kwargs.get("params", {}).get("api_key")
@geetu040 These are the tests failing I am not sure what to do with these |
Fixes #1601
added a
Createmethod inFlowAPIfor publishing flow but not refactored with oldpublish. (Needs discussion on this)Added tests using
fake_methodsso that we can test without localV2server . I have tested theFlowsV2methods (getandexists) anddeleteandlistwere not implemented inV2server so I skipped them .