Skip to content

Commit 51dbb2e

Browse files
black and pylint fixes
1 parent 78536bc commit 51dbb2e

File tree

4 files changed

+49
-51
lines changed

4 files changed

+49
-51
lines changed

sdk/ml/azure-ai-ml/azure/ai/ml/_utils/_endpoint_utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@
3939
initialize_logger_info(module_logger, terminator="")
4040

4141

42-
def check_and_log_default_deployment_template(
43-
deployment: Deployment, credential: Optional[TokenCredential]
44-
) -> None:
42+
def check_default_deployment_template(deployment: Deployment, credential: Optional[TokenCredential]) -> None:
4543
"""Check if a registry model has a default deployment template and log if found.
4644
4745
:param Deployment deployment: Endpoint deployment object.
@@ -231,7 +229,7 @@ def upload_dependencies(
231229
else None
232230
)
233231

234-
check_and_log_default_deployment_template(deployment, credential)
232+
check_default_deployment_template(deployment, credential)
235233

236234
if not is_registry_id_for_resource(deployment.model):
237235
deployment.model = (

sdk/ml/azure-ai-ml/tests/model/unittests/test_model_default_deployment_template.py

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Unit tests for Model with default_deployment_template functionality."""
2+
23
from pathlib import Path
34
from unittest.mock import Mock, patch
45

@@ -34,22 +35,20 @@ def test_model_init_with_default_deployment_template_object(self) -> None:
3435
path="./model.pkl",
3536
default_deployment_template=template,
3637
)
37-
38+
3839
assert model.default_deployment_template is not None
3940
assert model.default_deployment_template.asset_id == template.asset_id
4041

4142
def test_model_init_with_default_deployment_template_dict(self) -> None:
4243
"""Test creating a Model with default_deployment_template as dict."""
43-
template_dict = {
44-
"asset_id": "azureml://registries/test-registry/deploymenttemplates/template1/versions/1"
45-
}
44+
template_dict = {"asset_id": "azureml://registries/test-registry/deploymenttemplates/template1/versions/1"}
4645
model = Model(
4746
name="test-model",
4847
version="1",
4948
path="./model.pkl",
5049
default_deployment_template=template_dict, # type: ignore[arg-type]
5150
)
52-
51+
5352
assert model.default_deployment_template is not None
5453
assert isinstance(model.default_deployment_template, DefaultDeploymentTemplate)
5554
assert model.default_deployment_template.asset_id == template_dict["asset_id"]
@@ -61,7 +60,7 @@ def test_model_init_without_default_deployment_template(self) -> None:
6160
version="1",
6261
path="./model.pkl",
6362
)
64-
63+
6564
assert model.default_deployment_template is None
6665

6766
def test_model_to_rest_object_with_default_deployment_template(self) -> None:
@@ -76,9 +75,9 @@ def test_model_to_rest_object_with_default_deployment_template(self) -> None:
7675
description="Test model",
7776
default_deployment_template=template,
7877
)
79-
78+
8079
rest_object = model._to_rest_object()
81-
80+
8281
# Should return ModelVersionData when default_deployment_template is present
8382
assert isinstance(rest_object, ModelVersionData)
8483
assert isinstance(rest_object.properties, ModelVersionDetails)
@@ -95,9 +94,9 @@ def test_model_to_rest_object_without_default_deployment_template(self) -> None:
9594
description="Test model",
9695
stage="Production",
9796
)
98-
97+
9998
rest_object = model._to_rest_object()
100-
99+
101100
# Should return ModelVersion when default_deployment_template is not present
102101
assert isinstance(rest_object, ModelVersion)
103102
assert isinstance(rest_object.properties, ModelVersionProperties)
@@ -106,7 +105,7 @@ def test_model_to_rest_object_without_default_deployment_template(self) -> None:
106105
def test_model_from_rest_object_with_default_deployment_template_dict(self) -> None:
107106
"""Test Model._from_rest_object() with default_deployment_template as dict."""
108107
template_asset_id = "azureml://registries/test-registry/deploymenttemplates/template1/versions/1"
109-
108+
110109
# Create mock REST object
111110
rest_properties = Mock(spec=ModelVersionDetails)
112111
rest_properties.description = "Test model"
@@ -120,29 +119,29 @@ def test_model_from_rest_object_with_default_deployment_template_dict(self) -> N
120119
rest_properties.intellectual_property = None
121120
rest_properties.system_metadata = None
122121
rest_properties.default_deployment_template = {"asset_id": template_asset_id}
123-
122+
124123
rest_object = Mock(spec=ModelVersionData)
125124
rest_object.id = "/subscriptions/sub/resourceGroups/rg/providers/Microsoft.MachineLearningServices/workspaces/ws/models/test-model/versions/1"
126125
rest_object.properties = rest_properties
127-
126+
128127
# Mock system_data
129128
mock_system_data = Mock()
130129
mock_system_data.created_by = "test_user"
131130
mock_system_data.created_at = None
132131
mock_system_data.last_modified_by = None
133132
mock_system_data.last_modified_at = None
134133
rest_object.system_data = mock_system_data
135-
134+
136135
model = Model._from_rest_object(rest_object)
137-
136+
138137
assert model.default_deployment_template is not None
139138
assert isinstance(model.default_deployment_template, DefaultDeploymentTemplate)
140139
assert model.default_deployment_template.asset_id == template_asset_id
141140

142141
def test_model_from_rest_object_with_default_deployment_template_object(self) -> None:
143142
"""Test Model._from_rest_object() with default_deployment_template as object."""
144143
template_asset_id = "azureml://registries/test-registry/deploymenttemplates/template1/versions/1"
145-
144+
146145
# Create mock REST object
147146
rest_properties = Mock(spec=ModelVersionDetails)
148147
rest_properties.description = "Test model"
@@ -155,26 +154,26 @@ def test_model_from_rest_object_with_default_deployment_template_object(self) ->
155154
rest_properties.job_name = None
156155
rest_properties.intellectual_property = None
157156
rest_properties.system_metadata = None
158-
157+
159158
# Create template object with asset_id attribute
160159
template_obj = Mock()
161160
template_obj.asset_id = template_asset_id
162161
rest_properties.default_deployment_template = template_obj
163-
162+
164163
rest_object = Mock(spec=ModelVersionData)
165164
rest_object.id = "/subscriptions/sub/resourceGroups/rg/providers/Microsoft.MachineLearningServices/workspaces/ws/models/test-model/versions/1"
166165
rest_object.properties = rest_properties
167-
166+
168167
# Mock system_data
169168
mock_system_data = Mock()
170169
mock_system_data.created_by = "test_user"
171170
mock_system_data.created_at = None
172171
mock_system_data.last_modified_by = None
173172
mock_system_data.last_modified_at = None
174173
rest_object.system_data = mock_system_data
175-
174+
176175
model = Model._from_rest_object(rest_object)
177-
176+
178177
assert model.default_deployment_template is not None
179178
assert isinstance(model.default_deployment_template, DefaultDeploymentTemplate)
180179
assert model.default_deployment_template.asset_id == template_asset_id
@@ -192,21 +191,21 @@ def test_model_from_rest_object_without_default_deployment_template(self) -> Non
192191
rest_properties.stage = "Production"
193192
rest_properties.job_name = None
194193
rest_properties.intellectual_property = None
195-
194+
196195
rest_object = Mock(spec=ModelVersion)
197196
rest_object.id = "/subscriptions/sub/resourceGroups/rg/providers/Microsoft.MachineLearningServices/workspaces/ws/models/test-model/versions/1"
198197
rest_object.properties = rest_properties
199-
198+
200199
# Mock system_data
201200
mock_system_data = Mock()
202201
mock_system_data.created_by = "test_user"
203202
mock_system_data.created_at = None
204203
mock_system_data.last_modified_by = None
205204
mock_system_data.last_modified_at = None
206205
rest_object.system_data = mock_system_data
207-
206+
208207
model = Model._from_rest_object(rest_object)
209-
208+
210209
assert model.default_deployment_template is None
211210
assert model.stage == "Production"
212211

@@ -222,13 +221,13 @@ def test_model_with_stage_and_default_deployment_template(self) -> None:
222221
stage="Production",
223222
default_deployment_template=template,
224223
)
225-
224+
226225
assert model.stage == "Production"
227226
assert model.default_deployment_template is not None
228-
227+
229228
# Serialize to REST object
230229
rest_object = model._to_rest_object()
231-
230+
232231
# Note: When default_deployment_template is present, it uses ModelVersionDetails
233232
# which doesn't support stage in the v2021_10_01_dataplanepreview API
234233
# This is expected behavior - stage is only supported in workspace operations
@@ -239,7 +238,7 @@ def test_model_yaml_with_default_deployment_template(self, tmp_path: Path) -> No
239238
# Create a dummy model file
240239
model_file = tmp_path / "model.pkl"
241240
model_file.write_text("dummy model")
242-
241+
243242
yaml_content = f"""
244243
name: test-model
245244
version: "1"
@@ -250,9 +249,9 @@ def test_model_yaml_with_default_deployment_template(self, tmp_path: Path) -> No
250249
"""
251250
yaml_file = tmp_path / "model_with_template.yml"
252251
yaml_file.write_text(yaml_content)
253-
252+
254253
model = load_model(source=yaml_file)
255-
254+
256255
assert model.name == "test-model"
257256
assert model.version == "1"
258257
assert model.default_deployment_template is not None

sdk/ml/azure-ai-ml/tests/model/unittests/test_model_schema.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def test_model_with_default_deployment_template_from_yaml(self, tmp_path: Path)
9393
# Create a dummy model file
9494
model_file = tmp_path / "model.pkl"
9595
model_file.write_text("dummy model")
96-
96+
9797
yaml_content = f"""
9898
$schema: https://azuremlschemas.azureedge.net/latest/model.schema.json
9999
name: model_with_default_template
@@ -106,9 +106,9 @@ def test_model_with_default_deployment_template_from_yaml(self, tmp_path: Path)
106106
"""
107107
yaml_file = tmp_path / "model_with_template.yml"
108108
yaml_file.write_text(yaml_content)
109-
109+
110110
model = load_model(yaml_file)
111-
111+
112112
assert model.default_deployment_template is not None
113113
assert model.default_deployment_template.asset_id is not None
114114
assert "test-registry" in model.default_deployment_template.asset_id
@@ -118,21 +118,21 @@ def test_model_with_default_deployment_template_to_rest_object(self) -> None:
118118
"""Test Model._to_rest_object() with default_deployment_template."""
119119
from azure.ai.ml.entities._assets.default_deployment_template import DefaultDeploymentTemplate
120120
from azure.ai.ml._restclient.v2021_10_01_dataplanepreview.models import ModelVersionData
121-
121+
122122
template = DefaultDeploymentTemplate(
123123
asset_id="azureml://registries/test-registry/deploymenttemplates/template1/versions/1"
124124
)
125-
125+
126126
model = Model(
127127
name="test-model",
128128
version="1",
129129
path="./model.pkl",
130130
description="Test model with deployment template",
131131
default_deployment_template=template,
132132
)
133-
133+
134134
rest_object = model._to_rest_object()
135-
135+
136136
# Should return ModelVersionData when default_deployment_template is present
137137
assert isinstance(rest_object, ModelVersionData)
138138
assert rest_object.properties.default_deployment_template is not None
@@ -159,9 +159,9 @@ def test_model_with_default_deployment_template_from_rest_object(self) -> None:
159159
},
160160
"systemData": {},
161161
}
162-
162+
163163
from_rest_model = Model._from_rest_object(ModelVersionData.deserialize(rest_model_with_template))
164-
164+
165165
assert from_rest_model.default_deployment_template is not None
166166
assert from_rest_model.default_deployment_template.asset_id is not None
167167
assert "test-registry" in from_rest_model.default_deployment_template.asset_id
@@ -170,21 +170,21 @@ def test_model_with_default_deployment_template_from_rest_object(self) -> None:
170170
def test_model_with_default_deployment_template_to_dict(self) -> None:
171171
"""Test Model._to_dict() with default_deployment_template."""
172172
from azure.ai.ml.entities._assets.default_deployment_template import DefaultDeploymentTemplate
173-
173+
174174
template = DefaultDeploymentTemplate(
175175
asset_id="azureml://registries/test-registry/deploymenttemplates/template1/versions/1"
176176
)
177-
177+
178178
model = Model(
179179
name="test-model",
180180
version="1",
181181
path="./model.pkl",
182182
description="Test model with deployment template",
183183
default_deployment_template=template,
184184
)
185-
185+
186186
model_dict = model._to_dict()
187-
187+
188188
assert "default_deployment_template" in model_dict
189189
assert model_dict["default_deployment_template"] is not None
190190
assert "asset_id" in model_dict["default_deployment_template"]

sdk/ml/azure-ai-ml/tests/online_services/unittests/test_default_deployment_template.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Unit tests for default_deployment_template entity."""
2+
23
import pytest
34

45
from azure.ai.ml.entities._assets.default_deployment_template import DefaultDeploymentTemplate
@@ -13,20 +14,20 @@ def test_default_deployment_template_creation_with_asset_id(self) -> None:
1314
"""Test creating a DefaultDeploymentTemplate with asset_id."""
1415
asset_id = "azureml://registries/test-registry/deploymenttemplates/template1/versions/1"
1516
template = DefaultDeploymentTemplate(asset_id=asset_id)
16-
17+
1718
assert template.asset_id == asset_id
1819

1920
def test_default_deployment_template_asset_id_none(self) -> None:
2021
"""Test creating a DefaultDeploymentTemplate with None asset_id."""
2122
template = DefaultDeploymentTemplate(asset_id=None)
22-
23+
2324
assert template.asset_id is None
2425

2526
def test_default_deployment_template_asset_id_property(self) -> None:
2627
"""Test DefaultDeploymentTemplate asset_id property."""
2728
asset_id = "azureml://registries/my-registry/deploymenttemplates/my-template/versions/2"
2829
template = DefaultDeploymentTemplate(asset_id=asset_id)
29-
30+
3031
# Verify we can read the property
3132
assert template.asset_id is not None
3233
assert "my-registry" in template.asset_id

0 commit comments

Comments
 (0)