1
1
import pytest
2
+ from pathlib import Path
2
3
from test_utilities .utils import _PYTEST_TIMEOUT_METHOD
3
4
4
- from azure .ai .ml import MLClient , load_component
5
- from azure .core .exceptions import HttpResponseError
5
+ from azure .ai .ml import MLClient , load_component , Input , load_model
6
+ from azure .ai .ml .dsl import pipeline
7
+ from azure .ai .ml .constants import AssetTypes
8
+ from azure .core .exceptions import HttpResponseError , ResourceNotFoundError
9
+ from azure .core .polling import LROPoller
6
10
7
11
from .._util import _DSL_TIMEOUT_SECOND
8
12
12
16
@pytest .mark .usefixtures ("enable_pipeline_private_preview_features" , "recorded_test" )
13
17
@pytest .mark .timeout (timeout = _DSL_TIMEOUT_SECOND , method = _PYTEST_TIMEOUT_METHOD )
14
18
@pytest .mark .e2etest
15
- @pytest .mark .skip (reason = "not able to re-record" )
16
19
@pytest .mark .pipeline_test
17
20
class TestDSLPipelineOnRegistry (AzureRecordedTestCase ):
21
+ @pytest .mark .skip (reason = "not able to re-record" )
18
22
def test_pipeline_job_create_with_registered_component_on_registry (
19
23
self ,
20
24
registry_client : MLClient ,
21
25
) -> None :
22
- from azure .ai .ml .dsl import pipeline
23
-
24
26
local_component = load_component ("./tests/test_configs/components/basic_component_code_local_path.yml" )
25
27
try :
26
28
created_component = registry_client .components .get (local_component .name , version = local_component .version )
@@ -35,3 +37,105 @@ def sample_pipeline():
35
37
pipeline_job = sample_pipeline ()
36
38
assert registry_client .jobs .validate (pipeline_job ).passed
37
39
# TODO: add test for pipeline job create with registered component on registry after support is ready on canary
40
+
41
+ @pytest .mark .skip (reason = "request body still exits when re-record and will raise error "
42
+ "'Unable to find a record for the request' in playback mode" )
43
+ def test_pipeline_with_local_component_and_registry_model_as_input (self , registry_client : MLClient , client : MLClient ):
44
+ # get dataset
45
+ test_data = Input (
46
+ type = AssetTypes .URI_FILE ,
47
+ path = "./tests/test_configs/pipeline_jobs/job_with_registry_model_as_input/data/sample1.csv"
48
+ )
49
+
50
+ # load_component
51
+ score_func = load_component ("./tests/test_configs/pipeline_jobs/job_with_registry_model_as_input/score.yml" )
52
+
53
+ pipeline_score_model = Input (
54
+ type = 'mlflow_model' ,
55
+ path = 'azureml://registries/testFeed/models/iris_model/versions/1'
56
+ )
57
+
58
+ @pipeline ()
59
+ def score_pipeline_with_registry_model (model_input , test_data ):
60
+ score = score_func (model_input = model_input , test_data = test_data )
61
+ score_duplicate = score_func (model_input = pipeline_score_model , test_data = test_data )
62
+
63
+ pipeline_job = score_pipeline_with_registry_model (
64
+ model_input = pipeline_score_model ,
65
+ test_data = test_data
66
+ )
67
+ pipeline_job .settings .default_compute = "cpu-cluster"
68
+ pipeline_job = client .jobs .create_or_update (pipeline_job )
69
+ cancel_poller = client .jobs .begin_cancel (pipeline_job .name )
70
+ assert isinstance (cancel_poller , LROPoller )
71
+
72
+ @pytest .mark .skip (reason = "request body still exits when re-record and will raise error "
73
+ "'Unable to find a record for the request' in playback mode" )
74
+ def test_pipeline_with_local_component_and_registry_model_as_input_with_model_input (
75
+ self ,
76
+ registry_client : MLClient ,
77
+ client : MLClient ):
78
+ # get dataset
79
+ test_data = Input (
80
+ type = AssetTypes .URI_FILE ,
81
+ path = "./tests/test_configs/pipeline_jobs/job_with_registry_model_as_input/data/sample1.csv"
82
+ )
83
+
84
+ # load_component
85
+ score_func = load_component ("./tests/test_configs/pipeline_jobs/job_with_registry_model_as_input/score.yml" )
86
+
87
+ model_path = Path ("./tests/test_configs/model/model_iris.yml" )
88
+ model_entity = load_model (model_path )
89
+ try :
90
+ pipeline_score_model = registry_client .models .get (name = model_entity .name , version = model_entity .version )
91
+ except ResourceNotFoundError :
92
+ model_entity = registry_client .models .create_or_update (model_entity )
93
+ pipeline_score_model = registry_client .models .get (name = model_entity .name , version = model_entity .version )
94
+
95
+ @pipeline ()
96
+ def score_pipeline_with_registry_model (model_input , test_data ):
97
+ score = score_func (model_input = model_input , test_data = test_data )
98
+ score_duplicate = score_func (model_input = pipeline_score_model , test_data = test_data )
99
+
100
+ pipeline_job = score_pipeline_with_registry_model (
101
+ model_input = pipeline_score_model , test_data = test_data
102
+ )
103
+ pipeline_job .settings .default_compute = "cpu-cluster"
104
+ pipeline_job = client .jobs .create_or_update (pipeline_job )
105
+ cancel_poller = client .jobs .begin_cancel (pipeline_job .name )
106
+ assert isinstance (cancel_poller , LROPoller )
107
+
108
+ @pytest .mark .skip (reason = "request body still exits when re-record and will raise error "
109
+ "'Unable to find a record for the request' in playback mode" )
110
+ def test_pipeline_with_registry_component_and_model_as_input (self , registry_client : MLClient , client : MLClient ):
111
+ # get dataset
112
+ test_data = Input (
113
+ type = AssetTypes .URI_FILE ,
114
+ path = "./tests/test_configs/pipeline_jobs/job_with_registry_model_as_input/data/sample1.csv"
115
+ )
116
+
117
+ # load_component
118
+ score_component_name = "v2_dsl_score_component"
119
+ component_version = "0.0.8"
120
+ score_func = registry_client .components .get (
121
+ name = score_component_name , version = component_version
122
+ )
123
+
124
+ pipeline_score_model = Input (
125
+ type = 'mlflow_model' ,
126
+ path = 'azureml://registries/testFeed/models/iris_model/versions/1'
127
+ )
128
+
129
+ @pipeline ()
130
+ def score_pipeline_with_registry_model (model_input , test_data ):
131
+ score = score_func (model_input = model_input , test_data = test_data )
132
+ score_duplicate = score_func (model_input = pipeline_score_model , test_data = test_data )
133
+
134
+ pipeline_job = score_pipeline_with_registry_model (
135
+ model_input = pipeline_score_model ,
136
+ test_data = test_data
137
+ )
138
+ pipeline_job .settings .default_compute = "cpu-cluster"
139
+ pipeline_job = client .jobs .create_or_update (pipeline_job )
140
+ cancel_poller = client .jobs .begin_cancel (pipeline_job .name )
141
+ assert isinstance (cancel_poller , LROPoller )
0 commit comments