@@ -215,14 +215,15 @@ def run_command(self, cmd, *args, **kwargs):
215215 status = io_loop .run_sync (spawner .poll , timeout = 5 )
216216 assert status == 1
217217
218- def run_spawner_script (db , io_loop , spawner , script , batch_re_list = None , ** kwargs ):
218+ def run_spawner_script (db , io_loop , spawner , script ,
219+ batch_script_re_list = None , spawner_kwargs = {}):
219220 """Run a spawner script and test that the output and behavior is as expected.
220221
221222 db: same as in this module
222223 io_loop: same as in this module
223224 spawner: the BatchSpawnerBase subclass to test
224225 script: list of (input_re_to_match, output)
225- batch_re_list : if given
226+ batch_script_re_list : if given, assert batch script matches all of these
226227 """
227228 # Create the expected scripts
228229 cmd_expectlist , out_list = zip (* script )
@@ -231,27 +232,28 @@ def run_spawner_script(db, io_loop, spawner, script, batch_re_list=None, **kwarg
231232
232233 class BatchDummyTestScript (spawner ):
233234 @gen .coroutine
234- def run_command (self , cmd , * args , ** kwargs ):
235+ def run_command (self , cmd , input = None , env = None ):
235236 # Test the input
236237 run_re = cmd_expectlist .pop (0 )
237238 if run_re :
238239 print ('run: "{}" [{}]' .format (cmd , run_re ))
239240 assert run_re .search (cmd ) is not None , \
240241 "Failed test: re={0} cmd={1}" .format (run_re , cmd )
241242 # Test the stdin - will only be the batch script. For
242- # each regular expression in batch_re_list , assert that
243+ # each regular expression in batch_script_re_list , assert that
243244 # each re in that list matches the batch script.
244- if batch_re_list and ' input' in kwargs :
245- batch_script = kwargs [ ' input' ]
246- for match_re in batch_re_list :
245+ if batch_script_re_list and input :
246+ batch_script = input
247+ for match_re in batch_script_re_list :
247248 assert match_re .search (batch_script ) is not None , \
248249 "Batch script does not match {}" .format (match_re )
249250 # Return expected output.
250251 out = out_list .pop (0 )
251252 print (' --> ' + out )
252253 return out
253254
254- spawner = new_spawner (db = db , spawner_class = BatchDummyTestScript , ** kwargs )
255+ spawner = new_spawner (db = db , spawner_class = BatchDummyTestScript ,
256+ ** spawner_kwargs )
255257 # Not running at beginning (no command run)
256258 status = io_loop .run_sync (spawner .poll , timeout = 5 )
257259 assert status == 1
@@ -272,30 +274,42 @@ def run_command(self, cmd, *args, **kwargs):
272274
273275
274276def test_torque (db , io_loop ):
275- script = [
276- (re .compile ('sudo.*qsub' ), str (testjob )),
277- (re .compile ('sudo.*qstat' ), '<job_state>R</job_state><exec_host>{}/1</exec_host>' .format (testhost )),
278- (re .compile ('sudo.*qstat' ), '<job_state>R</job_state>' + testhost ),
279- (re .compile ('sudo.*qdel' ), 'STOP' ),
280- (re .compile ('sudo.*qstat' ), '' ),
277+ spawner_kwargs = { }
278+ batch_script_re_list = [
279+ re .compile (r'singleuser_command' ),
281280 ]
282- batch_re_list = [
283- re .compile ('singleuser_command' )
281+ script = [
282+ (re .compile (r'sudo.*qsub' ), str (testjob )),
283+ (re .compile (r'sudo.*qstat' ), '<job_state>R</job_state><exec_host>{}/1</exec_host>' .format (testhost )),
284+ (re .compile (r'sudo.*qstat' ), '<job_state>R</job_state>' + testhost ),
285+ (re .compile (r'sudo.*qdel' ), 'STOP' ),
286+ (re .compile (r'sudo.*qstat' ), '' ),
284287 ]
285288 from .. import TorqueSpawner
286- run_spawner_script (db , io_loop , TorqueSpawner , script , batch_re_list )
289+ run_spawner_script (db , io_loop , TorqueSpawner , script ,
290+ batch_script_re_list = batch_script_re_list ,
291+ spawner_kwargs = spawner_kwargs )
287292
288293
289294def test_slurm (db , io_loop ):
290- script = [
291- (re .compile ('sudo.*sbatch' ), str (testjob )),
292- (re .compile ('sudo.*squeue' ), 'RUNNING ' + testhost ),
293- (re .compile ('sudo.*squeue' ), 'RUNNING ' + testhost ),
294- (re .compile ('sudo.*scancel' ), 'STOP' ),
295- (re .compile ('sudo.*squeue' ), '' ),
295+ spawner_kwargs = {
296+ 'req_nprocs' : '5' ,
297+ 'req_memory' : '5678' ,
298+ 'req_options' : 'some_option_asdf' ,
299+ }
300+ batch_script_re_list = [
301+ re .compile (r'srun.*singleuser_command' ),
302+ re .compile (r'#SBATCH\s+--cpus-per-task=5' ),
303+ re .compile (r'#SBATCH\s+some_option_asdf' ),
296304 ]
297- batch_re_list = [
298- re .compile ('srun.*singleuser_command' )
305+ script = [
306+ (re .compile (r'sudo.*sbatch' ), str (testjob )),
307+ (re .compile (r'sudo.*squeue' ), 'RUNNING ' + testhost ),
308+ (re .compile (r'sudo.*squeue' ), 'RUNNING ' + testhost ),
309+ (re .compile (r'sudo.*scancel' ), 'STOP' ),
310+ (re .compile (r'sudo.*squeue' ), '' ),
299311 ]
300312 from .. import SlurmSpawner
301- run_spawner_script (db , io_loop , SlurmSpawner , script , batch_re_list )
313+ run_spawner_script (db , io_loop , SlurmSpawner , script ,
314+ batch_script_re_list = batch_script_re_list ,
315+ spawner_kwargs = spawner_kwargs )
0 commit comments