From 0ab7bc47752ce4daabb56dd7407862e9d6d9d1d6 Mon Sep 17 00:00:00 2001 From: kshitij-microsoft Date: Wed, 2 Oct 2024 00:44:51 +0530 Subject: [PATCH] changing mock for urlparse --- .../unittests/test_mocked_operations.py | 3 ++- .../unittests/test_workspace_operations.py | 18 +++++++----------- .../test_workspace_operations_base.py | 18 ++++++++---------- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/sdk/ml/azure-ai-ml/tests/workspace/ai_workspaces/unittests/test_mocked_operations.py b/sdk/ml/azure-ai-ml/tests/workspace/ai_workspaces/unittests/test_mocked_operations.py index ed567e3429df..6e98f1deaefd 100644 --- a/sdk/ml/azure-ai-ml/tests/workspace/ai_workspaces/unittests/test_mocked_operations.py +++ b/sdk/ml/azure-ai-ml/tests/workspace/ai_workspaces/unittests/test_mocked_operations.py @@ -42,7 +42,8 @@ def test_list(self, arg: str, mock_hub_operation: WorkspaceOperations) -> None: else: mock_hub_operation._operation.list_by_resource_group.assert_called_once() - def test_get(self, mock_hub_operation: WorkspaceOperations) -> None: + def test_get(self, mock_hub_operation: WorkspaceOperations, mocker: MockFixture) -> None: + mocker.patch("urllib.parse.urlparse") mock_hub_operation.get(name="random_name") mock_hub_operation._operation.get.assert_called_once() diff --git a/sdk/ml/azure-ai-ml/tests/workspace/unittests/test_workspace_operations.py b/sdk/ml/azure-ai-ml/tests/workspace/unittests/test_workspace_operations.py index 06664f6581d4..97e43a1cc1c5 100644 --- a/sdk/ml/azure-ai-ml/tests/workspace/unittests/test_workspace_operations.py +++ b/sdk/ml/azure-ai-ml/tests/workspace/unittests/test_workspace_operations.py @@ -28,15 +28,6 @@ def mock_credential() -> Mock: yield Mock() -def mock_urlparse(url: str) -> urllib.parse.ParseResult: - return urllib.parse.ParseResult( - scheme="http", netloc="example.com", path="/index.html", params="", query="a=1&b=2", fragment="" - ) - - -urllib.parse.urlparse = mock_urlparse - - @pytest.fixture def mock_workspace_operation( mock_workspace_scope: OperationScope, @@ -97,7 +88,8 @@ def test_list(self, arg: str, mock_workspace_operation: WorkspaceOperations) -> else: mock_workspace_operation._operation.list_by_resource_group.assert_called_once() - def test_get(self, mock_workspace_operation: WorkspaceOperations) -> None: + def test_get(self, mock_workspace_operation: WorkspaceOperations, mocker: MockFixture) -> None: + mocker.patch("urllib.parse.urlparse") mock_workspace_operation.get("random_name") mock_workspace_operation._operation.get.assert_called_once() @@ -124,7 +116,8 @@ def test_begin_create( mocker.patch("azure.ai.ml._arm_deployments.ArmDeploymentExecutor.deploy_resource", return_value=LROPoller) mock_workspace_operation.begin_create(workspace=Workspace(name="name")) - def test_update(self, mock_workspace_operation: WorkspaceOperations) -> None: + def test_update(self, mock_workspace_operation: WorkspaceOperations, mocker: MockFixture) -> None: + mocker.patch("urllib.parse.urlparse") ws = Workspace( name="name", description="description", @@ -145,6 +138,7 @@ def outgoing_call(rg, name, params, polling, cls): def test_update_with_role_assignemnt( self, mock_workspace_operation: WorkspaceOperations, mocker: MockFixture ) -> None: + mocker.patch("urllib.parse.urlparse") mocker.patch( "azure.ai.ml.operations.WorkspaceOperations._populate_feature_store_role_assignment_parameters", return_value=({}, {}, {}), @@ -173,6 +167,7 @@ def outgoing_call(rg, name, params, polling, cls): mock_workspace_operation._operation.begin_update.assert_called() def test_delete(self, mock_workspace_operation: WorkspaceOperations, mocker: MockFixture) -> None: + mocker.patch("urllib.parse.urlparse") mocker.patch("azure.ai.ml.operations._workspace_operations_base.delete_resource_by_arm_id", return_value=None) mocker.patch( "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 mock_workspace_operation._operation.begin_delete.assert_called_once() def test_purge(self, mock_workspace_operation: WorkspaceOperations, mocker: MockFixture) -> None: + mocker.patch("urllib.parse.urlparse") mocker.patch("azure.ai.ml.operations._workspace_operations_base.delete_resource_by_arm_id", return_value=None) mocker.patch( "azure.ai.ml.operations._workspace_operations_base.get_generic_arm_resource_by_arm_id", return_value=None diff --git a/sdk/ml/azure-ai-ml/tests/workspace/unittests/test_workspace_operations_base.py b/sdk/ml/azure-ai-ml/tests/workspace/unittests/test_workspace_operations_base.py index b52d910bd4b0..c3dcc424e34c 100644 --- a/sdk/ml/azure-ai-ml/tests/workspace/unittests/test_workspace_operations_base.py +++ b/sdk/ml/azure-ai-ml/tests/workspace/unittests/test_workspace_operations_base.py @@ -39,15 +39,6 @@ def mock_credential() -> Mock: yield Mock() -def mock_urlparse(url: str) -> urllib.parse.ParseResult: - return urllib.parse.ParseResult( - scheme="http", netloc="example.com", path="/index.html", params="", query="a=1&b=2", fragment="" - ) - - -urllib.parse.urlparse = mock_urlparse - - @pytest.fixture def mock_workspace_operation_base( mock_workspace_scope: OperationScope, @@ -188,6 +179,8 @@ def test_create_get_exception_swallow( def test_begin_create_existing_ws( self, mock_workspace_operation_base: WorkspaceOperationsBase, mocker: MockFixture ): + mocker.patch("urllib.parse.urlparse") + def outgoing_call(rg, name, params, polling, cls): assert name == "name" return DEFAULT @@ -197,7 +190,8 @@ def outgoing_call(rg, name, params, polling, cls): mock_workspace_operation_base.begin_create(workspace=Workspace(name="name")) mock_workspace_operation_base._operation.begin_update.assert_called() - def test_update(self, mock_workspace_operation_base: WorkspaceOperationsBase) -> None: + def test_update(self, mock_workspace_operation_base: WorkspaceOperationsBase, mocker: MockFixture) -> None: + mocker.patch("urllib.parse.urlparse") ws = Workspace( name="name", tags={"key": "value"}, @@ -254,6 +248,7 @@ def outgoing_call(rg, name, params, polling, cls): def test_update_with_empty_property_values( self, mock_workspace_operation_base: WorkspaceOperationsBase, mocker: MockFixture ) -> None: + mocker.patch("urllib.parse.urlparse") ws = Workspace(name="name", description="", display_name="", image_build_compute="") mocker.patch("azure.ai.ml.operations.WorkspaceOperations.get", return_value=ws) @@ -277,6 +272,7 @@ def outgoing_call(rg, name, params, polling, cls): mock_workspace_operation_base._operation.begin_update.assert_called() def test_delete_no_wait(self, mock_workspace_operation_base: WorkspaceOperationsBase, mocker: MockFixture) -> None: + mocker.patch("urllib.parse.urlparse") mocker.patch("azure.ai.ml.operations._workspace_operations_base.delete_resource_by_arm_id", return_value=None) mocker.patch( "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 mock_workspace_operation_base._operation.begin_delete.assert_called_once() def test_delete_wait(self, mock_workspace_operation_base: WorkspaceOperationsBase, mocker: MockFixture) -> None: + mocker.patch("urllib.parse.urlparse") mocker.patch("azure.ai.ml.operations._workspace_operations_base.delete_resource_by_arm_id", return_value=None) mocker.patch( "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( mock_workspace_operation_base: WorkspaceOperationsBase, mocker: MockFixture, ) -> None: + mocker.patch("urllib.parse.urlparse") ws = Workspace(name="name", location="test", serverless_compute=serverless_compute_settings) spy = mocker.spy(mock_workspace_operation_base._operation, "begin_update") mock_workspace_operation_base.begin_update(ws)