@@ -92,12 +92,23 @@ def test_pipeline_create_and_update_with_config_injection(sagemaker_session_mock
92
92
PipelineDefinition = pipeline .definition (),
93
93
RoleArn = pipeline_role_arn ,
94
94
)
95
+
96
+ sagemaker_session_mock .sagemaker_client .update_pipeline .return_value = {
97
+ "PipelineArn" : "pipeline-arn" ,
98
+ "PipelineVersionId" : 2 ,
99
+ }
100
+
95
101
pipeline .update ()
96
102
sagemaker_session_mock .sagemaker_client .update_pipeline .assert_called_with (
97
103
PipelineName = "MyPipeline" ,
98
104
PipelineDefinition = pipeline .definition (),
99
105
RoleArn = pipeline_role_arn ,
100
106
)
107
+
108
+ sagemaker_session_mock .sagemaker_client .update_pipeline .return_value = {
109
+ "PipelineArn" : "pipeline-arn" ,
110
+ "PipelineVersionId" : 3 ,
111
+ }
101
112
pipeline .upsert ()
102
113
sagemaker_session_mock .sagemaker_client .update_pipeline .assert_called_with (
103
114
PipelineName = "MyPipeline" ,
@@ -207,6 +218,11 @@ def test_pipeline_update(sagemaker_session_mock, role_arn):
207
218
sagemaker_session = sagemaker_session_mock ,
208
219
)
209
220
assert not pipeline .steps
221
+
222
+ sagemaker_session_mock .sagemaker_client .update_pipeline .return_value = {
223
+ "PipelineArn" : "pipeline-arn" ,
224
+ "PipelineVersionId" : 1 ,
225
+ }
210
226
pipeline .update (role_arn = role_arn )
211
227
assert len (json .loads (pipeline .definition ())["Steps" ]) == 0
212
228
sagemaker_session_mock .sagemaker_client .update_pipeline .assert_called_with (
@@ -251,6 +267,11 @@ def test_pipeline_update(sagemaker_session_mock, role_arn):
251
267
)
252
268
assert len (pipeline .steps ) == 2
253
269
270
+ sagemaker_session_mock .sagemaker_client .update_pipeline .return_value = {
271
+ "PipelineArn" : "pipeline-arn" ,
272
+ "PipelineVersionId" : 2 ,
273
+ }
274
+
254
275
pipeline .update (role_arn = role_arn )
255
276
assert len (json .loads (pipeline .definition ())["Steps" ]) == 3
256
277
sagemaker_session_mock .sagemaker_client .update_pipeline .assert_called_with (
@@ -345,6 +366,11 @@ def test_pipeline_update_with_parallelism_config(sagemaker_session_mock, role_ar
345
366
role_arn = role_arn ,
346
367
parallelism_config = dict (MaxParallelExecutionSteps = 10 ),
347
368
)
369
+ sagemaker_session_mock .sagemaker_client .update_pipeline .return_value = {
370
+ "PipelineArn" : "pipeline-arn" ,
371
+ "PipelineVersionId" : 2 ,
372
+ }
373
+
348
374
pipeline .update (
349
375
role_arn = role_arn ,
350
376
parallelism_config = {"MaxParallelExecutionSteps" : 10 },
@@ -393,7 +419,8 @@ def _raise_does_already_exists_client_error(**kwargs):
393
419
)
394
420
395
421
sagemaker_session_mock .sagemaker_client .update_pipeline .return_value = {
396
- "PipelineArn" : "pipeline-arn"
422
+ "PipelineArn" : "pipeline-arn" ,
423
+ "PipelineVersionId" : 2 ,
397
424
}
398
425
sagemaker_session_mock .sagemaker_client .list_tags .return_value = {
399
426
"Tags" : [{"Key" : "dummy" , "Value" : "dummy_tag" }]
@@ -428,6 +455,7 @@ def _raise_does_already_exists_client_error(**kwargs):
428
455
sagemaker_session_mock .sagemaker_client .add_tags .assert_called_with (
429
456
ResourceArn = "pipeline-arn" , Tags = tags
430
457
)
458
+ assert pipeline .latest_pipeline_version_id == 2
431
459
432
460
433
461
def test_pipeline_upsert_create_unexpected_failure (sagemaker_session_mock , role_arn ):
@@ -476,18 +504,11 @@ def _raise_unexpected_client_error(**kwargs):
476
504
sagemaker_session_mock .sagemaker_client .add_tags .assert_not_called ()
477
505
478
506
479
- def test_pipeline_upsert_resourse_doesnt_exist (sagemaker_session_mock , role_arn ):
507
+ def test_pipeline_upsert_resource_doesnt_exist (sagemaker_session_mock , role_arn ):
480
508
481
509
# case 3: resource does not exist
482
510
sagemaker_session_mock .sagemaker_client .create_pipeline = Mock (name = "create_pipeline" )
483
511
484
- sagemaker_session_mock .sagemaker_client .update_pipeline .return_value = {
485
- "PipelineArn" : "pipeline-arn"
486
- }
487
- sagemaker_session_mock .sagemaker_client .list_tags .return_value = {
488
- "Tags" : [{"Key" : "dummy" , "Value" : "dummy_tag" }]
489
- }
490
-
491
512
tags = [
492
513
{"Key" : "foo" , "Value" : "abc" },
493
514
{"Key" : "bar" , "Value" : "xyz" },
@@ -542,6 +563,11 @@ def test_pipeline_describe(sagemaker_session_mock):
542
563
PipelineName = "MyPipeline" ,
543
564
)
544
565
566
+ pipeline .describe (pipeline_version_id = 5 )
567
+ sagemaker_session_mock .sagemaker_client .describe_pipeline .assert_called_with (
568
+ PipelineName = "MyPipeline" , PipelineVersionId = 5
569
+ )
570
+
545
571
546
572
def test_pipeline_start (sagemaker_session_mock ):
547
573
sagemaker_session_mock .sagemaker_client .start_pipeline_execution .return_value = {
@@ -568,6 +594,11 @@ def test_pipeline_start(sagemaker_session_mock):
568
594
PipelineName = "MyPipeline" , PipelineParameters = [{"Name" : "alpha" , "Value" : "epsilon" }]
569
595
)
570
596
597
+ pipeline .start (pipeline_version_id = 5 )
598
+ sagemaker_session_mock .sagemaker_client .start_pipeline_execution .assert_called_with (
599
+ PipelineName = "MyPipeline" , PipelineVersionId = 5
600
+ )
601
+
571
602
572
603
def test_pipeline_start_selective_execution (sagemaker_session_mock ):
573
604
sagemaker_session_mock .sagemaker_client .start_pipeline_execution .return_value = {
@@ -809,6 +840,29 @@ def test_pipeline_list_executions(sagemaker_session_mock):
809
840
assert executions ["NextToken" ] == "token"
810
841
811
842
843
+ def test_pipeline_list_versions (sagemaker_session_mock ):
844
+ sagemaker_session_mock .sagemaker_client .list_pipeline_versions .return_value = {
845
+ "PipelineVersionSummaries" : [Mock ()],
846
+ "NextToken" : "token" ,
847
+ }
848
+ pipeline = Pipeline (
849
+ name = "MyPipeline" ,
850
+ parameters = [ParameterString ("alpha" , "beta" ), ParameterString ("gamma" , "delta" )],
851
+ steps = [],
852
+ sagemaker_session = sagemaker_session_mock ,
853
+ )
854
+ versions = pipeline .list_pipeline_versions ()
855
+ assert len (versions ["PipelineVersionSummaries" ]) == 1
856
+ assert versions ["NextToken" ] == "token"
857
+
858
+ sagemaker_session_mock .sagemaker_client .list_pipeline_versions .return_value = {
859
+ "PipelineVersionSummaries" : [Mock (), Mock ()],
860
+ }
861
+ versions = pipeline .list_pipeline_versions (next_token = versions ["NextToken" ])
862
+ assert len (versions ["PipelineVersionSummaries" ]) == 2
863
+ assert "NextToken" not in versions
864
+
865
+
812
866
def test_pipeline_build_parameters_from_execution (sagemaker_session_mock ):
813
867
pipeline = Pipeline (
814
868
name = "MyPipeline" ,
0 commit comments