@@ -108,16 +108,14 @@ def test_cache_docker_image(
108108 ] # Ensure all path checks return True
109109 mock_run .return_value = subprocess .CompletedProcess (args = ["cmd" ], returncode = 0 , stderr = "" )
110110 result = manager .cache_docker_image ("docker.io/hello-world" , "image.tar.gz" )
111- mock_run .assert_called_once_with (
112- (
113- f"srun --export=ALL --partition={ slurm_system .default_partition } enroot "
114- f"import -o { slurm_system .install_path } /image.tar.gz docker://docker.io/hello-world"
115- ),
116- shell = True ,
117- check = True ,
118- capture_output = True ,
119- text = True ,
120- )
111+
112+ assert mock_run .call_count == 1
113+ actual_command = mock_run .call_args [0 ][0 ]
114+ assert f"srun --export=ALL --partition={ slurm_system .default_partition } " in actual_command
115+ assert "--job-name=CloudAI_install_docker_image_" in actual_command
116+ assert f"enroot import -o { slurm_system .install_path } /image.tar.gz docker://docker.io/hello-world" in actual_command
117+ assert mock_run .call_args [1 ] == {"shell" : True , "check" : True , "capture_output" : True , "text" : True }
118+
121119 assert result .success
122120 assert result .message == f"Docker image cached successfully at { slurm_system .install_path } /image.tar.gz."
123121
@@ -215,17 +213,25 @@ def test_docker_import_with_extra_system_config(slurm_system: SlurmSystem, accou
215213 res = manager .cache_docker_image ("docker.io/hello-world" , "docker_image.sqsh" )
216214 assert res .success
217215
218- command = f"srun --export=ALL --partition={ slurm_system .default_partition } "
219- if slurm_system .account :
220- command += f" --account={ slurm_system .account } "
221- if slurm_system .gpus_per_node :
222- command += " --gres=gpu:1"
223- command += f" enroot import -o { slurm_system .install_path } /docker_image.sqsh docker://docker.io/hello-world"
224-
225- mock_run .assert_called_once_with (
226- command ,
227- shell = True ,
228- check = True ,
229- capture_output = True ,
230- text = True ,
216+ assert mock_run .call_count == 1
217+
218+ actual_command = mock_run .call_args [0 ][0 ]
219+
220+ expected_prefix = f"srun --export=ALL --partition={ slurm_system .default_partition } "
221+ assert expected_prefix in actual_command
222+
223+ if account :
224+ assert f"--account={ account } " in actual_command
225+ assert f"--job-name={ account } -CloudAI_install_docker_image." in actual_command
226+ else :
227+ assert "--job-name=CloudAI_install_docker_image_" in actual_command
228+
229+ if gpus_per_node :
230+ assert "--gres=gpu:1" in actual_command
231+
232+ assert (
233+ f"enroot import -o { slurm_system .install_path } /docker_image.sqsh docker://docker.io/hello-world"
234+ in actual_command
231235 )
236+
237+ assert mock_run .call_args [1 ] == {"shell" : True , "check" : True , "capture_output" : True , "text" : True }
0 commit comments