Пример #1
0
def test_job_length_depends(tmp_dir):
    file = tmp_dir / "test.txt"
    file.write_text("test")
    assert file.exists()
    job = Job([Command("echo", creates="test.txt")],
              directory=tmp_dir,
              use_dependencies=True)
    assert len(job) == 0
Пример #2
0
def test_dependencies(tmp_dir):
    command = Command(cmd="echo contents > {creates}", creates="test")
    jobs = [Job([command], directory=Path(tmp_dir), use_dependencies=True)]
    create_file = tmp_dir / "test"
    create_file.write_text("success")

    run_bash_jobs(jobs, tmp_dir)
    assert "success" in create_file.read_text()

    jobs[0].use_dependencies = False
    run_bash_jobs(jobs, tmp_dir)
    assert "contents" in create_file.read_text()
Пример #3
0
def test_dependencies_list(tmp_dir):
    commands = [
        Command(cmd=f"echo contents{i} > {{creates}}", creates=f"test{i}")
        for i in range(5)
    ]
    jobs = [Job(commands, directory=Path(tmp_dir), use_dependencies=True)]
    create_files = [tmp_dir / f"test{i}" for i in range(5)]

    create_files[1].write_text("success")

    run_bash_jobs(jobs, tmp_dir)
    for i in range(5):
        if i == 1:
            assert "success" in create_files[i].read_text()
        else:
            assert f"contents{i}" in create_files[i].read_text()
Пример #4
0
def test_job_length():
    job = Job([Command("echo")])
    assert len(job) == 1
Пример #5
0
 def _create_jobs(command: str) -> Iterator[Job]:
     yield Job([Command(command)])
Пример #6
0
def test_dry_run(tmp_dir):
    command = Command(cmd="echo contents > {creates}", creates="test")
    jobs = [Job([command], directory=Path(tmp_dir))]
    create_file = tmp_dir / "test"
    run_bash_jobs(jobs, tmp_dir, dry_run=True)
    assert not create_file.exists()
Пример #7
0
def test_default_files(scheduler, expected):
    assert create_scheduler_file(scheduler,
                                 Job([Command("echo 1")])) == expected
Пример #8
0
#SBATCH --time 1:00
SLURM_ARRAY_TASK_ID=0

cd "$SLURM_SUBMIT_DIR"


COMMAND=( \\
"echo 1" \\
)

${COMMAND[$SLURM_ARRAY_TASK_ID]}
"""


@pytest.mark.parametrize("job, result", [
    (Job([Command("echo 1")]), '( \\\n"echo 1" \\\n)'),
    (
        Job([Command("echo 1"), Command("echo 2")]),
        '( \\\n"echo 1" \\\n"echo 2" \\\n)',
    ),
],
                         ids=["single", "list"])
def test_jobs_as_bash_array(job, result):
    assert job.as_bash_array() == result


@pytest.mark.parametrize('scheduler, expected', [('pbs', DEFAULT_PBS),
                                                 ('slurm', DEFAULT_SLURM)],
                         ids=["PBS", "SLURM"])
def test_default_files(scheduler, expected):
    assert create_scheduler_file(scheduler,