forked from It4innovations/hyperqueue
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_entries.py
More file actions
176 lines (140 loc) · 4.8 KB
/
Copy pathtest_entries.py
File metadata and controls
176 lines (140 loc) · 4.8 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import os
import pytest
from .conftest import HqEnv
from .utils import wait_for_job_state
from .utils.io import check_file_contents
from .utils.job import default_task_output
def test_entries_no_newline(hq_env: HqEnv):
hq_env.start_server()
hq_env.start_worker(cpus=2)
with open("input", "w") as f:
f.write("One\nTwo\nThree\nFour")
hq_env.command(
[
"submit",
"--each-line=input",
"--",
"bash",
"-c",
"echo $HQ_ENTRY",
]
)
wait_for_job_state(hq_env, 1, "FINISHED")
for i, test in enumerate(["One\n", "Two\n", "Three\n", "Four\n"]):
check_file_contents(default_task_output(job_id=1, task_id=i), test)
assert not os.path.isfile(default_task_output(job_id=1, task_id=4))
table = hq_env.command(["job", "info", "1"], as_table=True)
assert table.get_row_value("State").split("\n")[-1] == "FINISHED (4)"
def test_entries_with_newline(hq_env: HqEnv):
hq_env.start_server()
hq_env.start_worker(cpus=2)
with open("input", "w") as f:
f.write("One\nTwo\nThree\nFour\n")
hq_env.command(
[
"submit",
"--each-line=input",
"--",
"bash",
"-c",
"echo $HQ_ENTRY",
]
)
wait_for_job_state(hq_env, 1, "FINISHED")
for i, test in enumerate(["One\n", "Two\n", "Three\n", "Four\n"]):
check_file_contents(default_task_output(job_id=1, task_id=i), test)
assert not os.path.isfile(default_task_output(task_id=4))
table = hq_env.command(["job", "info", "1"], as_table=True)
assert table.get_row_value("State").split("\n")[-1] == "FINISHED (4)"
def test_entries_from_json_entry(hq_env: HqEnv):
hq_env.start_server()
hq_env.start_worker(cpus=2)
with open("input", "w") as f:
f.write('[123, {"x":\n[1,2,3]}, 2.5]')
hq_env.command(
[
"submit",
"--from-json=input",
"--",
"bash",
"-c",
"echo $HQ_ENTRY",
]
)
wait_for_job_state(hq_env, 1, "FINISHED")
for i, test in enumerate(["123\n", '{"x":[1,2,3]}\n', "2.5\n"]):
check_file_contents(default_task_output(job_id=1, task_id=i), test)
assert not os.path.isfile(default_task_output(task_id=3))
table = hq_env.command(["job", "info", "1"], as_table=True)
assert table.get_row_value("State").split("\n")[-1] == "FINISHED (3)"
def test_entries_invalid_from_json_entry(hq_env: HqEnv):
hq_env.start_server()
hq_env.start_worker(cpus=2)
with open("input", "w") as f:
f.write('{"x":\n[1,2,3]}')
with pytest.raises(
Exception,
match="The top element of the provided JSON file has to be an array",
):
hq_env.command(
[
"submit",
"--from-json=input",
"--",
"bash",
"-c",
"echo $HQ_ENTRY",
]
)
def test_each_line_with_array(hq_env: HqEnv):
hq_env.start_server()
hq_env.start_worker(cpus=2)
with open("input", "w") as f:
f.write("One\nTwo\nThree\nFour\nFive\nSix\nSeven")
hq_env.command(
[
"submit",
"--each-line=input",
"--array",
"2-4, 6",
"--",
"bash",
"-c",
"echo $HQ_ENTRY,$HQ_TASK_ID",
]
)
wait_for_job_state(hq_env, 1, "FINISHED")
for i, test in enumerate([None, None, "Three,2\n", "Four,3\n", "Five,4\n", None, "Seven,6\n"]):
filename = default_task_output(job_id=1, task_id=i)
if test is None:
assert not os.path.exists(filename)
else:
check_file_contents(filename, test)
table = hq_env.command(["job", "info", "1"], as_table=True)
assert table.get_row_value("State").split("\n")[-1] == "FINISHED (4)"
def test_json_with_array(hq_env: HqEnv):
hq_env.start_server()
hq_env.start_worker(cpus=2)
with open("input", "w") as f:
f.write('["One", "Two", "Three", "Four", "Five", "Six", "Seven"]')
hq_env.command(
[
"submit",
"--from-json=input",
"--array",
"2-3, 5, 6, 7, 1000",
"--",
"bash",
"-c",
"echo $HQ_ENTRY,$HQ_TASK_ID",
]
)
wait_for_job_state(hq_env, 1, "FINISHED")
for i, test in enumerate([None, None, '"Three",2\n', '"Four",3\n', None, '"Six",5\n', '"Seven",6\n']):
filename = default_task_output(job_id=1, task_id=i)
if test is None:
assert not os.path.exists(filename)
else:
check_file_contents(filename, test)
table = hq_env.command(["job", "info", "1"], as_table=True)
assert table.get_row_value("State").split("\n")[-1] == "FINISHED (4)"