Skip to content

Commit 0ab7bc4

Browse files
changing mock for urlparse
1 parent ae32d9d commit 0ab7bc4

File tree

3 files changed

+17
-22
lines changed

3 files changed

+17
-22
lines changed

sdk/ml/azure-ai-ml/tests/workspace/ai_workspaces/unittests/test_mocked_operations.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ def test_list(self, arg: str, mock_hub_operation: WorkspaceOperations) -> None:
4242
else:
4343
mock_hub_operation._operation.list_by_resource_group.assert_called_once()
4444

45-
def test_get(self, mock_hub_operation: WorkspaceOperations) -> None:
45+
def test_get(self, mock_hub_operation: WorkspaceOperations, mocker: MockFixture) -> None:
46+
mocker.patch("urllib.parse.urlparse")
4647
mock_hub_operation.get(name="random_name")
4748
mock_hub_operation._operation.get.assert_called_once()
4849

sdk/ml/azure-ai-ml/tests/workspace/unittests/test_workspace_operations.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,6 @@ def mock_credential() -> Mock:
2828
yield Mock()
2929

3030

31-
def mock_urlparse(url: str) -> urllib.parse.ParseResult:
32-
return urllib.parse.ParseResult(
33-
scheme="http", netloc="example.com", path="/index.html", params="", query="a=1&b=2", fragment=""
34-
)
35-
36-
37-
urllib.parse.urlparse = mock_urlparse
38-
39-
4031
@pytest.fixture
4132
def mock_workspace_operation(
4233
mock_workspace_scope: OperationScope,
@@ -97,7 +88,8 @@ def test_list(self, arg: str, mock_workspace_operation: WorkspaceOperations) ->
9788
else:
9889
mock_workspace_operation._operation.list_by_resource_group.assert_called_once()
9990

100-
def test_get(self, mock_workspace_operation: WorkspaceOperations) -> None:
91+
def test_get(self, mock_workspace_operation: WorkspaceOperations, mocker: MockFixture) -> None:
92+
mocker.patch("urllib.parse.urlparse")
10193
mock_workspace_operation.get("random_name")
10294
mock_workspace_operation._operation.get.assert_called_once()
10395

@@ -124,7 +116,8 @@ def test_begin_create(
124116
mocker.patch("azure.ai.ml._arm_deployments.ArmDeploymentExecutor.deploy_resource", return_value=LROPoller)
125117
mock_workspace_operation.begin_create(workspace=Workspace(name="name"))
126118

127-
def test_update(self, mock_workspace_operation: WorkspaceOperations) -> None:
119+
def test_update(self, mock_workspace_operation: WorkspaceOperations, mocker: MockFixture) -> None:
120+
mocker.patch("urllib.parse.urlparse")
128121
ws = Workspace(
129122
name="name",
130123
description="description",
@@ -145,6 +138,7 @@ def outgoing_call(rg, name, params, polling, cls):
145138
def test_update_with_role_assignemnt(
146139
self, mock_workspace_operation: WorkspaceOperations, mocker: MockFixture
147140
) -> None:
141+
mocker.patch("urllib.parse.urlparse")
148142
mocker.patch(
149143
"azure.ai.ml.operations.WorkspaceOperations._populate_feature_store_role_assignment_parameters",
150144
return_value=({}, {}, {}),
@@ -173,6 +167,7 @@ def outgoing_call(rg, name, params, polling, cls):
173167
mock_workspace_operation._operation.begin_update.assert_called()
174168

175169
def test_delete(self, mock_workspace_operation: WorkspaceOperations, mocker: MockFixture) -> None:
170+
mocker.patch("urllib.parse.urlparse")
176171
mocker.patch("azure.ai.ml.operations._workspace_operations_base.delete_resource_by_arm_id", return_value=None)
177172
mocker.patch(
178173
"azure.ai.ml.operations._workspace_operations_base.get_generic_arm_resource_by_arm_id", return_value=None
@@ -181,6 +176,7 @@ def test_delete(self, mock_workspace_operation: WorkspaceOperations, mocker: Moc
181176
mock_workspace_operation._operation.begin_delete.assert_called_once()
182177

183178
def test_purge(self, mock_workspace_operation: WorkspaceOperations, mocker: MockFixture) -> None:
179+
mocker.patch("urllib.parse.urlparse")
184180
mocker.patch("azure.ai.ml.operations._workspace_operations_base.delete_resource_by_arm_id", return_value=None)
185181
mocker.patch(
186182
"azure.ai.ml.operations._workspace_operations_base.get_generic_arm_resource_by_arm_id", return_value=None

sdk/ml/azure-ai-ml/tests/workspace/unittests/test_workspace_operations_base.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,6 @@ def mock_credential() -> Mock:
3939
yield Mock()
4040

4141

42-
def mock_urlparse(url: str) -> urllib.parse.ParseResult:
43-
return urllib.parse.ParseResult(
44-
scheme="http", netloc="example.com", path="/index.html", params="", query="a=1&b=2", fragment=""
45-
)
46-
47-
48-
urllib.parse.urlparse = mock_urlparse
49-
50-
5142
@pytest.fixture
5243
def mock_workspace_operation_base(
5344
mock_workspace_scope: OperationScope,
@@ -188,6 +179,8 @@ def test_create_get_exception_swallow(
188179
def test_begin_create_existing_ws(
189180
self, mock_workspace_operation_base: WorkspaceOperationsBase, mocker: MockFixture
190181
):
182+
mocker.patch("urllib.parse.urlparse")
183+
191184
def outgoing_call(rg, name, params, polling, cls):
192185
assert name == "name"
193186
return DEFAULT
@@ -197,7 +190,8 @@ def outgoing_call(rg, name, params, polling, cls):
197190
mock_workspace_operation_base.begin_create(workspace=Workspace(name="name"))
198191
mock_workspace_operation_base._operation.begin_update.assert_called()
199192

200-
def test_update(self, mock_workspace_operation_base: WorkspaceOperationsBase) -> None:
193+
def test_update(self, mock_workspace_operation_base: WorkspaceOperationsBase, mocker: MockFixture) -> None:
194+
mocker.patch("urllib.parse.urlparse")
201195
ws = Workspace(
202196
name="name",
203197
tags={"key": "value"},
@@ -254,6 +248,7 @@ def outgoing_call(rg, name, params, polling, cls):
254248
def test_update_with_empty_property_values(
255249
self, mock_workspace_operation_base: WorkspaceOperationsBase, mocker: MockFixture
256250
) -> None:
251+
mocker.patch("urllib.parse.urlparse")
257252
ws = Workspace(name="name", description="", display_name="", image_build_compute="")
258253
mocker.patch("azure.ai.ml.operations.WorkspaceOperations.get", return_value=ws)
259254

@@ -277,6 +272,7 @@ def outgoing_call(rg, name, params, polling, cls):
277272
mock_workspace_operation_base._operation.begin_update.assert_called()
278273

279274
def test_delete_no_wait(self, mock_workspace_operation_base: WorkspaceOperationsBase, mocker: MockFixture) -> None:
275+
mocker.patch("urllib.parse.urlparse")
280276
mocker.patch("azure.ai.ml.operations._workspace_operations_base.delete_resource_by_arm_id", return_value=None)
281277
mocker.patch(
282278
"azure.ai.ml.operations._workspace_operations_base.get_generic_arm_resource_by_arm_id", return_value=None
@@ -285,6 +281,7 @@ def test_delete_no_wait(self, mock_workspace_operation_base: WorkspaceOperations
285281
mock_workspace_operation_base._operation.begin_delete.assert_called_once()
286282

287283
def test_delete_wait(self, mock_workspace_operation_base: WorkspaceOperationsBase, mocker: MockFixture) -> None:
284+
mocker.patch("urllib.parse.urlparse")
288285
mocker.patch("azure.ai.ml.operations._workspace_operations_base.delete_resource_by_arm_id", return_value=None)
289286
mocker.patch(
290287
"azure.ai.ml.operations._workspace_operations_base.get_generic_arm_resource_by_arm_id", return_value=None
@@ -610,6 +607,7 @@ def test_update_workspace_with_serverless_custom_vnet(
610607
mock_workspace_operation_base: WorkspaceOperationsBase,
611608
mocker: MockFixture,
612609
) -> None:
610+
mocker.patch("urllib.parse.urlparse")
613611
ws = Workspace(name="name", location="test", serverless_compute=serverless_compute_settings)
614612
spy = mocker.spy(mock_workspace_operation_base._operation, "begin_update")
615613
mock_workspace_operation_base.begin_update(ws)

0 commit comments

Comments
 (0)