def test_3(self, check_requirements_mock): check_requirements_mock.return_value = None scripts = [pytest.helpers.get_py_script(i, 1) for i in range(3)] [s.write() for s in scripts] paths = [s.path for s in scripts] task = SlurmTask(paths, max_array_size=1) runscript = task._create_runscript() logf = runscript.path.replace(".script", ".log") jobsf = runscript.path.replace(".script", ".jobs") with open(jobsf, "r") as f_in: jobs = [l.strip() for l in f_in] pytest.helpers.unlink(paths + [jobsf]) assert runscript.shebang == "#!/bin/bash" assert runscript.content == [ "#SBATCH --export=ALL", "#SBATCH --job-name=pyjob", "#SBATCH -n 1", "#SBATCH --workdir=" + os.getcwd(), "#SBATCH --array=1-3%1", "#SBATCH -o {}".format(logf), 'script=$(awk "NR==$SLURM_ARRAY_TASK_ID" {})'.format(jobsf), 'log=$(echo $script | sed "s/\\.${script##*.}/\\.log/")', "$script > $log 2>&1", ] assert jobs == paths
def test_5(self, check_requirements_mock): check_requirements_mock.return_value = None scripts = [pytest.helpers.get_py_script(i, 1) for i in range(1)] [s.write() for s in scripts] paths = [s.path for s in scripts] task = SlurmTask(paths, processes=5) runscript = task._create_runscript() pytest.helpers.unlink(paths) assert runscript.shebang == "#!/bin/bash" assert runscript.content == [ "#SBATCH --export=ALL", "#SBATCH --job-name=pyjob", "#SBATCH -n 5", "#SBATCH --workdir=" + os.getcwd(), "#SBATCH -o " + paths[0].replace(".py", ".log"), paths[0], ]