22import os
33import time
44import unittest
5-
65from subprocess import Popen , PIPE
76
7+ from smartdispatch .utils import get_slurm_cluster_name
8+
89pbs_string = """\
910 #!/usr/bin/env /bin/bash
1011
2223nvidia-smi
2324"""
2425
25- sbatch_string = """\
26- #!/usr/bin/env -i /bin/zsh
27-
28- #SBATCH --job-name=arrayJob
29- #SBATCH --output=arrayJob_%A_%a.out
30- #SBATCH --time=01:00:00
31- {}
32-
33- ######################
34- # Begin work section #
35- ######################
36-
37- echo "My SLURM_ARRAY_JOB_ID:" $SLURM_ARRAY_JOB_ID
38- echo "My SLURM_ARRAY_TASK_ID: " $SLURM_ARRAY_TASK_ID
39- nvidia-smi
40- """
41-
4226# Checking which cluster is running the tests first
43- process = Popen ("sacctmgr list cluster" , stdout = PIPE , stderr = PIPE , shell = True )
44- stdout , _ = process .communicate ()
45- stdout = stdout .decode ()
46- cluster = stdout .splitlines ()[2 ].strip ().split (' ' )[0 ]
27+ cluster = get_slurm_cluster_name ()
4728to_skip = cluster in ['graham' , 'cedar' ]
4829message = "Test does not run on cluster {}" .format (cluster )
4930
@@ -53,14 +34,14 @@ def tearDown(self):
5334 for file_name in (glob ('*.out' ) + ["test.pbs" ]):
5435 os .remove (file_name )
5536
56- def _test_param (self , param_array , command , flag , string = pbs_string , output_array = None ):
37+ def _test_param (self , param_array , command_template , flag , string = pbs_string , output_array = None ):
5738 output_array = output_array or param_array
5839 for param , output in zip (param_array , output_array ):
59- com = pbs_string .format (
60- string .format (command .format (param ))
40+ param_command = pbs_string .format (
41+ string .format (command_template .format (param ))
6142 )
6243 with open ("test.pbs" , "w" ) as text_file :
63- text_file .write (com )
44+ text_file .write (param_command )
6445 process = Popen ("sbatch test.pbs" , stdout = PIPE , stderr = PIPE , shell = True )
6546 stdout , _ = process .communicate ()
6647 stdout = stdout .decode ()
0 commit comments