-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
229 lines (207 loc) · 8.62 KB
/
test.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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
import json
import os
import subprocess
import time
from textwrap import dedent
import boto3
import pytest
from botocore.exceptions import ClientError
PROJECT = os.environ["PROJECT"]
VERSION = os.environ["VERSION"]
FLYTE_ADMIN_ENDPOINT = os.environ["FLYTE_ADMIN_ENDPOINT"]
FLYTE_CLIENT_ID = os.environ["FLYTE_CLIENT_ID"]
FLYTE_SECRET_PATH = os.environ["FLYTE_SECRET_PATH"]
DOMAIN = "development"
s3_client = boto3.resource("s3")
managed_buckets = {
"admin.lyte.latch.bio:81": "prod-ldata-managed",
}
@pytest.fixture
def bucket():
return managed_buckets[FLYTE_ADMIN_ENDPOINT]
@pytest.fixture
def inputs():
return [
".test/wf-core-deseq2/counts.csv",
".test/wf-core-deseq2/design.csv",
]
@pytest.fixture
def outputs(bucket):
return [
".test/wf-core-deseq2/output/Report.deseqreport",
".test/wf-core-deseq2/output/Data/dds.rds",
]
def _s3_obj_exists(bucket_name: str, res_path: str) -> bool:
obj = s3_client.Object(bucket_name, res_path)
try:
obj.load()
return True
except ClientError as e:
return False
def _rm_s3_obj(bucket_name: str, res_path: str):
s3_client.Object(bucket_name, res_path).delete()
def test_wf(bucket, inputs, outputs, capsys):
try:
for inpt in inputs:
assert _s3_obj_exists(bucket, inpt) is True, "Inputs do not exist."
for output in outputs:
if _s3_obj_exists(bucket, output) is True:
_rm_s3_obj(bucket, output)
_execution_file = json.dumps(
{
"inputs": {
"conditions_source": "table",
"conditions_table": {
"__proto": {
"scalar": {
"union": {
"type": {
"annotation": {
"annotations": {
"_tmp_hack_deseq2": "design_matrix",
"rules": [
{
"message": (
"Expected a CSV, TSV, or"
" XLSX file"
),
"regex": ".*\\.(csv|tsv|xlsx)$",
}
],
}
},
"blob": {},
"structure": {"tag": "FlyteFilePath"},
},
"value": {
"scalar": {
"blob": {
"metadata": {"type": {}},
"uri": f"s3://{bucket}/{inputs[1]}",
}
}
},
}
}
}
},
"count_table_gene_id_column": "gene_id",
"count_table_source": "single",
"design_formula": [
["Condition", "explanatory"],
],
"design_matrix_sample_id_column": {
"__proto": {
"scalar": {
"union": {
"type": {
"annotation": {
"annotations": {
"_tmp_hack_deseq2": "design_id_column"
}
},
"simple": "STRING",
"structure": {"tag": "str"},
},
"value": {
"scalar": {
"primitive": {"stringValue": "Sample"}
}
},
}
}
}
},
"output_location": {
"__proto": {
"scalar": {
"union": {
"type": {
"blob": {"dimensionality": "MULTIPART"},
"structure": {"tag": "FlyteDirectory"},
},
"value": {
"scalar": {
"blob": {
"metadata": {"type": {}},
"uri": f"s3://{bucket}/{'/'.join(inputs[0].split('/')[:-1])}/output",
}
}
},
}
}
}
},
"output_location_type": "custom",
"raw_count_table": {
"__proto": {
"scalar": {
"union": {
"type": {
"annotation": {
"annotations": {
"_tmp_hack_deseq2": "design_matrix",
"rules": [
{
"message": (
"Expected a CSV, TSV, or"
" XLSX file"
),
"regex": ".*\\.(csv|tsv|xlsx)$",
}
],
}
},
"blob": {},
"structure": {"tag": "FlyteFilePath"},
},
"value": {
"scalar": {
"blob": {
"metadata": {"type": {}},
"uri": f"s3://{bucket}/{inputs[0]}",
}
}
},
}
}
}
},
"report_name": "test",
},
"targetDomain": DOMAIN,
"targetProject": PROJECT,
"version": VERSION,
"workflow": "wf.__init__.deseq2_wf",
}
)
command = [
"/bin/flytectl",
"create",
"--admin.endpoint",
FLYTE_ADMIN_ENDPOINT,
"--admin.insecure",
"--admin.clientId",
FLYTE_CLIENT_ID,
"--admin.clientSecretLocation",
FLYTE_SECRET_PATH,
"execution",
"-p",
PROJECT,
"-d",
DOMAIN,
"--execFile",
"/dev/stdin",
]
with capsys.disabled():
print("Running the workflow with flytectl")
subprocess.run(command, input=_execution_file.encode("utf-8"), check=True)
print("", flush=True)
time.sleep(10 * 60)
for inpt in inputs:
assert _s3_obj_exists(bucket, inpt) is True
for output in outputs:
assert _s3_obj_exists(bucket, output) is True
finally:
for output in outputs:
_rm_s3_obj(bucket, output)