Пример #1
0
def test_creates_substitution():
    cmd = "test {var1} {creates}"
    creates = "test.out"
    variables = {"var1": "1.0"}
    command = Command(cmd=cmd, creates=creates, variables=variables)
    assert command.cmd == [cmd.format(creates=creates, **variables)]
    assert str(command) == cmd.format(creates=creates, **variables)
Пример #2
0
def test_requires_substitution():
    cmd = "test {var1} {requires}"
    requires = "test.in"
    variables = {"var1": "1.0"}
    command = Command(cmd=cmd, requires=requires, variables=variables)
    assert command.cmd == [cmd.format(requires=requires, **variables)]
    assert str(command) == cmd.format(requires=requires, **variables)
Пример #3
0
def test_command_equality():
    """Test that equality compares classes not just values."""
    class Subcommand(Command):
        def __init__(self, cmd):
            super().__init__(cmd)

    assert Subcommand("test") != Command("test")
Пример #4
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
Пример #5
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()
Пример #6
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()
Пример #7
0
def test_command_substitution():
    cmd = "test {var1}"
    variables = {"var1": "1.0"}
    command = Command(cmd=cmd, variables=variables)
    assert command.cmd == [cmd.format(**variables)]
    assert str(command) == cmd.format(**variables)
Пример #8
0
def test_command_simple():
    cmd = "test"
    command = Command(cmd=cmd)
    assert command.cmd == [cmd]
    assert str(command) == cmd
Пример #9
0
def test_default_files(scheduler, expected):
    assert create_scheduler_file(scheduler,
                                 Job([Command("echo 1")])) == expected
Пример #10
0
def test_get_variables_empty():
    result = Command("test").get_variables()
    assert result == set()
Пример #11
0
def test_get_variables(variables):
    format_string = "{" + "}{".join(variables) + "}"
    result = Command(format_string, {i: None
                                     for i in variables}).get_variables()
    print(format_string)
    assert sorted(set(variables)) == sorted(result)
Пример #12
0
 def _create_jobs(command: str) -> Iterator[Job]:
     yield Job([Command(command)])
Пример #13
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()
Пример #14
0
def test_hashable_command():
    cmd = "test"
    command = Command(cmd=cmd)
    assert hash(command) == hash((cmd, ))
    cmd_dict = {command: "Success"}
    assert cmd_dict.get(command) == "Success"
Пример #15
0
def test_command_init():
    Command("test")
    with pytest.raises(ValueError):
        Command("{test}")
    with pytest.raises(ValueError):
        Command("{test1} {test2}", variables={"test1": ""})
Пример #16
0
def test_uniqueify_command():
    cmd_list = [Command(cmd="test") for _ in range(5)]
    unique_commands = uniqueify(cmd_list)
    assert len(unique_commands) == 1
Пример #17
0
def test_job_length():
    job = Job([Command("echo")])
    assert len(job) == 1
Пример #18
0
def test_cmd_list():
    command = Command(cmd=["test"] * 5)
    assert command.cmd == ["test"] * 5
    assert str(command) == " && ".join(["test"] * 5)
Пример #19
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,