@@ -86,33 +86,35 @@ def test_run(
8686 # Mock the exit code of the subprocesses being run
8787 mock_subprocess .return_value = 0
8888
89- # Mock 'build_image' return values
90- built_images = [
91- f"{ dst if dst else def_dst } /{ image [0 ]} :{ tags [0 ] if tags else def_tags [0 ]} "
92- for image in images
93- ]
89+ # Construct images that will be generated at the different stages of the process
90+ built_images : list [str ] = []
91+ other_tags : list [str ] = []
92+ images_to_push : list [str ] = []
93+ for image in images :
94+ built_image = (
95+ f"{ dst if dst else def_dst } /{ image [0 ]} :{ tags [0 ] if tags else def_tags [0 ]} "
96+ )
97+ built_images .append (built_image )
98+ images_to_push .append (built_image )
99+ for tag in (tags if tags else def_tags )[1 :]:
100+ new_tag = f"{ image .split (':' )[0 ]} :{ tag } "
101+ other_tags .append (new_tag )
102+ images_to_push .append (new_tag )
103+
104+ # Mock the return values of 'build_image' and 'tag_iamge'
94105 mock_build .side_effect = built_images
106+ mock_tag .side_effect = other_tags
95107
96- # Mock all the return values when tagging the images
97- all_tags = [
98- f"{ image .split (':' )[0 ]} :{ tag } "
99- for image in built_images
100- for tag in (tags if tags else def_tags )
101- ]
102- mock_tag .side_effect = all_tags
103-
104- # Mock the push function
108+ # Mock the push and cleanup functions
105109 mock_push .return_value = True
106-
107- # Mock the cleanup function
108110 mock_clean .return_value = True
109111
110112 # Run the function with the command
111113 run ()
112114
113- # Check that the functions were called with the correct flags
115+ # Check that 'build_image' was called with the correct arguments
114116 assert mock_build .call_count == len (images )
115- expected_calls = (
117+ expected_build_calls = (
116118 call (
117119 image = image ,
118120 tag = tags [0 ] if tags else def_tags [0 ],
@@ -125,4 +127,15 @@ def test_run(
125127 )
126128 for image in images
127129 )
128- mock_build .assert_has_calls (expected_calls , any_order = True )
130+ mock_build .assert_has_calls (expected_build_calls , any_order = True )
131+
132+ if other_tags :
133+ expected_tag_calls = (
134+ call (
135+ image_path = image ,
136+ tags = other_tags ,
137+ dry_run = dry_run if dry_run else def_dry_run ,
138+ )
139+ for image in built_images
140+ )
141+ mock_tag .assert_has_calls (expected_tag_calls , any_order = True )
0 commit comments