-
Notifications
You must be signed in to change notification settings - Fork 4
/
example.py
147 lines (125 loc) · 3.47 KB
/
example.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
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
# example.py
import run
run.group("basics")
# run.add(
# "create_files",
# "touch output/a=[[a]]_b=[[b]]_c=[[c]].txt",
# {'a': [1, 2], 'b': [1, 2, 3], 'c': 0}
# )
run.add(
"create_files",
"touch [[file]]",
{"a": [1, 2], "b": [1, 2, 3], "c": 0, "file": "output/a=[[a]]_b=[[b]]_c=[[c]].txt"},
creates_file="[[file]]",
)
run.add(
"sum",
"echo $(([[a]] + [[b]]))",
{"a": [1, 2], "b": [1, 2, 3]},
stdout_file="output/[[a]]+[[b]].txt",
)
run.add(
"sum",
"echo $(([[a]] + [[b]]))",
{"a": [1, 2], "b": [3, 4]},
stdout_file="output/sums.txt",
stdout_res="[[a]] + [[b]] = [[stdout]]",
)
run.group("blobs")
res_name = {"+": "sum", "-": "diff", "*": "prod", "/": "quot"}
run.add(
"calculate",
"echo $(([[a]] [[operator]] [[b]]))",
{"a": [1, 2], "b": [3, 4], "operator": ["+", "-", "*", "/"]},
stdout_file=lambda args: "output/" + res_name[args["operator"]] + ".txt",
stdout_res="[[a]] [[operator]] [[b]] = [[stdout]]",
)
run.add(
"sum_of_squares",
"echo $(([[a]] * [[a]] + [[b]] * [[b]] + [[c]] * [[c]]))",
{
"a": lambda args: args["triple"]["a"],
"b": lambda args: args["triple"]["b"],
"c": lambda args: args["triple"]["c"],
"triple": [
{"a": a, "b": b, "c": c}
for a in range(0, 5)
for b in range(0, 5)
for c in range(0, 5)
if a + b + c == 4
],
"file": "output/sum_of_squares_[[a]]_[[b]]_[[c]].txt",
},
stdout_file="[[file]]",
)
run.add(
"better_sum_of_squares",
"echo $(([[a]] * [[a]] + [[b]] * [[b]] + [[c]] * [[c]]))",
{"a": list(range(0, 5)), "b": list(range(0, 5)), "c": list(range(0, 5))},
stdout_file="output/sum_of_squares_[[a]]_[[b]]_[[c]]_good.txt",
combinations_filter=lambda args: args["a"] + args["b"] + args["c"] == 4,
)
run.group("headers")
run.add(
"algo",
"algo [[input]]",
{"input": ["file1", "file2", "file3"]},
stdout_file="output.csv",
header_command="algo --only-header",
)
run.add(
"algos",
"[[algo]] [[input]]",
{"algo": ["algo1", "algo2"], "input": ["file1", "file2", "file3"]},
stdout_file="output_[[algo]].csv",
header_command="[[algo]] --only-header",
)
run.group("error_handling")
run.add(
"timeouts",
"timeout 2 sleep [[time]] && echo waking up",
{"time": [0, 1, 2, 3, 4]},
stdout_file="output/timeouts.txt",
allowed_return_codes=[0, 124],
stdout_res=lambda args: (
"sleeping [[time]]s -> [[stdout]]"
if args["stdout"] != ""
else "sleeping [[time]]s -> timeout"
),
)
run.add(
"timeouts",
"timeout 2 sleep [[time]] && echo waking up",
{"time": [0, 1, 2, 3, 4]},
stdout_file="output/timeouts.txt",
allowed_return_codes=[0, 124],
stdout_mod=lambda out, res: (
"sleeping [[time]]s -> [[stdout]]"
if res.returncode == 0
else "sleeping [[time]]s -> timeout"
),
)
run.group("calculations")
run.add(
"calculate_[[op_name]]",
"echo $(([[a]] [[operator]] [[b]]))",
{
"a": [1, 2],
"b": [3, 4],
"operator": ["+", "-", "*", "/"],
"op_name": lambda args: res_name[args["operator"]],
},
stdout_file="output/result_[[op_name]].txt",
stdout_res="[[a]] [[operator]] [[b]] = [[stdout]]",
)
run.group("")
run.run()
import glob
files = glob.glob("output/*.txt")
run.add(
"copy_files",
"cp [[file]] [[copy]]",
{"file": files, "copy": "[[file]].copy"},
creates_file="[[copy]]",
)
run.run()