@@ -198,3 +198,49 @@ def test_getJobOutputFiles(numberOfNodes, outputContent, expectedContent):
198198
199199 os .remove (outputFile )
200200 os .remove (errorFile )
201+
202+
203+ def test_submitJob_cmd_generation (mocker ):
204+ """Test submitJob() command string generation for various kwargs"""
205+ slurm = SLURM ()
206+ # Mock subprocess.Popen to capture the command
207+ popen_mock = mocker .patch ("subprocess.Popen" )
208+ process_mock = popen_mock .return_value
209+ process_mock .communicate .return_value = ("Submitted batch job 1234\n " , "" )
210+ process_mock .returncode = 0
211+
212+ # Minimal kwargs
213+ kwargs = {
214+ "Executable" : "/bin/echo" ,
215+ "OutputDir" : "/tmp" ,
216+ "ErrorDir" : "/tmp" ,
217+ "Queue" : "testq" ,
218+ "SubmitOptions" : "" ,
219+ "JobStamps" : ["stamp1" ],
220+ "NJobs" : 1 ,
221+ }
222+ # Test default (WholeNode False)
223+ slurm .submitJob (** kwargs )
224+ cmd = popen_mock .call_args [0 ][0 ]
225+ assert "--cpus-per-task=1" in cmd
226+ assert "--exclusive" not in cmd
227+
228+ # Test WholeNode True disables --cpus-per-task and adds --exclusive
229+ kwargs ["WholeNode" ] = True
230+ slurm .submitJob (** kwargs )
231+ cmd = popen_mock .call_args [0 ][0 ]
232+ assert "--exclusive" in cmd
233+ assert "--cpus-per-task" not in cmd
234+
235+ # Test NumberOfProcessors
236+ kwargs ["WholeNode" ] = False
237+ kwargs ["NumberOfProcessors" ] = 8
238+ slurm .submitJob (** kwargs )
239+ cmd = popen_mock .call_args [0 ][0 ]
240+ assert "--cpus-per-task=8" in cmd
241+
242+ # Test NumberOfGPUs
243+ kwargs ["NumberOfGPUs" ] = 2
244+ slurm .submitJob (** kwargs )
245+ cmd = popen_mock .call_args [0 ][0 ]
246+ assert "--gpus-per-task=2" in cmd
0 commit comments