-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_create.py
48 lines (40 loc) · 1.52 KB
/
test_create.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import re
import pytest
from hipercow import root
from hipercow import task_create as tc
from hipercow.configure import configure
from hipercow.task import TaskData, TaskStatus, task_status
from hipercow.util import transient_working_directory
def test_create_simple_task(tmp_path):
root.init(tmp_path)
r = root.open_root(tmp_path)
with transient_working_directory(tmp_path):
tid = tc.task_create_shell(r, ["echo", "hello world"])
assert re.match("^[0-9a-f]{32}$", tid)
path_data = (
tmp_path / "hipercow" / "py" / "tasks" / tid[:2] / tid[2:] / "data"
)
assert path_data.exists()
d = TaskData.read(root.open_root(tmp_path), tid)
assert isinstance(d, TaskData)
assert d.task_id == tid
assert d.method == "shell"
assert d.data == {"cmd": ["echo", "hello world"]}
assert d.path == "."
assert d.envvars == {}
def test_tasks_cannot_be_empty(tmp_path):
root.init(tmp_path)
r = root.open_root(tmp_path)
with pytest.raises(Exception, match="cannot be empty"):
with transient_working_directory(tmp_path):
tc.task_create_shell(r, [])
def test_submit_with_driver_if_configured(tmp_path, capsys):
root.init(tmp_path)
r = root.open_root(tmp_path)
configure(r, "example")
capsys.readouterr()
with transient_working_directory(tmp_path):
tid = tc.task_create_shell(r, ["echo", "hello world"])
str1 = capsys.readouterr().out
assert str1.startswith(f"submitting '{tid}'")
assert task_status(r, tid) == TaskStatus.SUBMITTED