@@ -92,12 +92,23 @@ def test_pipeline_create_and_update_with_config_injection(sagemaker_session_mock
9292 PipelineDefinition = pipeline .definition (),
9393 RoleArn = pipeline_role_arn ,
9494 )
95+
96+ sagemaker_session_mock .sagemaker_client .update_pipeline .return_value = {
97+ "PipelineArn" : "pipeline-arn" ,
98+ "PipelineVersionId" : 2 ,
99+ }
100+
95101 pipeline .update ()
96102 sagemaker_session_mock .sagemaker_client .update_pipeline .assert_called_with (
97103 PipelineName = "MyPipeline" ,
98104 PipelineDefinition = pipeline .definition (),
99105 RoleArn = pipeline_role_arn ,
100106 )
107+
108+ sagemaker_session_mock .sagemaker_client .update_pipeline .return_value = {
109+ "PipelineArn" : "pipeline-arn" ,
110+ "PipelineVersionId" : 3 ,
111+ }
101112 pipeline .upsert ()
102113 sagemaker_session_mock .sagemaker_client .update_pipeline .assert_called_with (
103114 PipelineName = "MyPipeline" ,
@@ -207,6 +218,11 @@ def test_pipeline_update(sagemaker_session_mock, role_arn):
207218 sagemaker_session = sagemaker_session_mock ,
208219 )
209220 assert not pipeline .steps
221+
222+ sagemaker_session_mock .sagemaker_client .update_pipeline .return_value = {
223+ "PipelineArn" : "pipeline-arn" ,
224+ "PipelineVersionId" : 1 ,
225+ }
210226 pipeline .update (role_arn = role_arn )
211227 assert len (json .loads (pipeline .definition ())["Steps" ]) == 0
212228 sagemaker_session_mock .sagemaker_client .update_pipeline .assert_called_with (
@@ -251,6 +267,11 @@ def test_pipeline_update(sagemaker_session_mock, role_arn):
251267 )
252268 assert len (pipeline .steps ) == 2
253269
270+ sagemaker_session_mock .sagemaker_client .update_pipeline .return_value = {
271+ "PipelineArn" : "pipeline-arn" ,
272+ "PipelineVersionId" : 2 ,
273+ }
274+
254275 pipeline .update (role_arn = role_arn )
255276 assert len (json .loads (pipeline .definition ())["Steps" ]) == 3
256277 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
345366 role_arn = role_arn ,
346367 parallelism_config = dict (MaxParallelExecutionSteps = 10 ),
347368 )
369+ sagemaker_session_mock .sagemaker_client .update_pipeline .return_value = {
370+ "PipelineArn" : "pipeline-arn" ,
371+ "PipelineVersionId" : 2 ,
372+ }
373+
348374 pipeline .update (
349375 role_arn = role_arn ,
350376 parallelism_config = {"MaxParallelExecutionSteps" : 10 },
@@ -393,7 +419,8 @@ def _raise_does_already_exists_client_error(**kwargs):
393419 )
394420
395421 sagemaker_session_mock .sagemaker_client .update_pipeline .return_value = {
396- "PipelineArn" : "pipeline-arn"
422+ "PipelineArn" : "pipeline-arn" ,
423+ "PipelineVersionId" : 2 ,
397424 }
398425 sagemaker_session_mock .sagemaker_client .list_tags .return_value = {
399426 "Tags" : [{"Key" : "dummy" , "Value" : "dummy_tag" }]
@@ -428,6 +455,7 @@ def _raise_does_already_exists_client_error(**kwargs):
428455 sagemaker_session_mock .sagemaker_client .add_tags .assert_called_with (
429456 ResourceArn = "pipeline-arn" , Tags = tags
430457 )
458+ assert pipeline .latest_pipeline_version_id == 2
431459
432460
433461def test_pipeline_upsert_create_unexpected_failure (sagemaker_session_mock , role_arn ):
@@ -476,18 +504,11 @@ def _raise_unexpected_client_error(**kwargs):
476504 sagemaker_session_mock .sagemaker_client .add_tags .assert_not_called ()
477505
478506
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 ):
480508
481509 # case 3: resource does not exist
482510 sagemaker_session_mock .sagemaker_client .create_pipeline = Mock (name = "create_pipeline" )
483511
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-
491512 tags = [
492513 {"Key" : "foo" , "Value" : "abc" },
493514 {"Key" : "bar" , "Value" : "xyz" },
@@ -542,6 +563,11 @@ def test_pipeline_describe(sagemaker_session_mock):
542563 PipelineName = "MyPipeline" ,
543564 )
544565
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+
545571
546572def test_pipeline_start (sagemaker_session_mock ):
547573 sagemaker_session_mock .sagemaker_client .start_pipeline_execution .return_value = {
@@ -568,6 +594,11 @@ def test_pipeline_start(sagemaker_session_mock):
568594 PipelineName = "MyPipeline" , PipelineParameters = [{"Name" : "alpha" , "Value" : "epsilon" }]
569595 )
570596
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+
571602
572603def test_pipeline_start_selective_execution (sagemaker_session_mock ):
573604 sagemaker_session_mock .sagemaker_client .start_pipeline_execution .return_value = {
@@ -809,6 +840,29 @@ def test_pipeline_list_executions(sagemaker_session_mock):
809840 assert executions ["NextToken" ] == "token"
810841
811842
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+
812866def test_pipeline_build_parameters_from_execution (sagemaker_session_mock ):
813867 pipeline = Pipeline (
814868 name = "MyPipeline" ,
0 commit comments