24
24
"r-workflow-step-00000000-0000-0000-0000-{id:012d}"
25
25
)
26
26
27
- # Pickle files (representing each 'Table')
28
- _WORKFLOW_PICKLE_FILE : str = "workflow.pickle"
29
- _RUNNING_WORKFLOW_PICKLE_FILE : str = "running-workflow.pickle"
30
- _RUNNING_WORKFLOW_STEP_PICKLE_FILE : str = "running-workflow-step.pickle"
31
- _INSTANCE_PICKLE_FILE : str = "instance.pickle"
32
- _TASK_PICKLE_FILE : str = "task.pickle"
27
+ # Pickle files (for each 'Table')
28
+ _PICKLE_DIRECTORY : str = "tests/pickle-files"
29
+ _WORKFLOW_PICKLE_FILE : str = f"{ _PICKLE_DIRECTORY } /workflow.pickle"
30
+ _RUNNING_WORKFLOW_PICKLE_FILE : str = f"{ _PICKLE_DIRECTORY } /running-workflow.pickle"
31
+ _RUNNING_WORKFLOW_STEP_PICKLE_FILE : str = (
32
+ f"{ _PICKLE_DIRECTORY } /running-workflow-step.pickle"
33
+ )
34
+ _INSTANCE_PICKLE_FILE : str = f"{ _PICKLE_DIRECTORY } /instance.pickle"
35
+ _TASK_PICKLE_FILE : str = f"{ _PICKLE_DIRECTORY } /task.pickle"
33
36
34
37
35
38
class UnitTestAPIAdapter (APIAdapter ):
@@ -46,45 +49,46 @@ class UnitTestAPIAdapter(APIAdapter):
46
49
def __init__ (self ):
47
50
super ().__init__ ()
48
51
# Safely initialise the pickle files
52
+ if not os .path .exists (_PICKLE_DIRECTORY ):
53
+ os .makedirs (_PICKLE_DIRECTORY )
49
54
UnitTestAPIAdapter .mp_lock .acquire ()
50
- with open (f"tests/{ _WORKFLOW_PICKLE_FILE } " , "wb" ) as pickle_file :
51
- Pickler (pickle_file ).dump ({})
52
- with open (f"tests/{ _RUNNING_WORKFLOW_PICKLE_FILE } " , "wb" ) as pickle_file :
53
- Pickler (pickle_file ).dump ({})
54
- with open (f"tests/{ _RUNNING_WORKFLOW_STEP_PICKLE_FILE } " , "wb" ) as pickle_file :
55
- Pickler (pickle_file ).dump ({})
56
- with open (f"tests/{ _INSTANCE_PICKLE_FILE } " , "wb" ) as pickle_file :
57
- Pickler (pickle_file ).dump ({})
58
- with open (f"tests/{ _TASK_PICKLE_FILE } " , "wb" ) as pickle_file :
59
- Pickler (pickle_file ).dump ({})
55
+ for file in [
56
+ _WORKFLOW_PICKLE_FILE ,
57
+ _RUNNING_WORKFLOW_PICKLE_FILE ,
58
+ _RUNNING_WORKFLOW_STEP_PICKLE_FILE ,
59
+ _INSTANCE_PICKLE_FILE ,
60
+ _TASK_PICKLE_FILE ,
61
+ ]:
62
+ with open (file , "wb" ) as pickle_file :
63
+ Pickler (pickle_file ).dump ({})
60
64
UnitTestAPIAdapter .mp_lock .release ()
61
65
62
66
def create_workflow (self , * , workflow_definition : Dict [str , Any ]) -> str :
63
67
UnitTestAPIAdapter .mp_lock .acquire ()
64
- with open (f"tests/ { _WORKFLOW_PICKLE_FILE } " , "rb" ) as pickle_file :
68
+ with open (_WORKFLOW_PICKLE_FILE , "rb" ) as pickle_file :
65
69
workflow = Unpickler (pickle_file ).load ()
66
70
67
71
next_id : int = len (workflow ) + 1
68
72
workflow_definition_id : str = _WORKFLOW_DEFINITION_ID_FORMAT .format (id = next_id )
69
73
workflow [workflow_definition_id ] = workflow_definition
70
74
71
- with open (f"tests/ { _WORKFLOW_PICKLE_FILE } " , "wb" ) as pickle_file :
75
+ with open (_WORKFLOW_PICKLE_FILE , "wb" ) as pickle_file :
72
76
Pickler (pickle_file ).dump (workflow )
73
77
UnitTestAPIAdapter .mp_lock .release ()
74
78
75
79
return {"id" : workflow_definition_id }
76
80
77
81
def get_workflow (self , * , workflow_id : str ) -> Dict [str , Any ]:
78
82
UnitTestAPIAdapter .mp_lock .acquire ()
79
- with open (f"tests/ { _WORKFLOW_PICKLE_FILE } " , "rb" ) as pickle_file :
83
+ with open (_WORKFLOW_PICKLE_FILE , "rb" ) as pickle_file :
80
84
workflow = Unpickler (pickle_file ).load ()
81
85
UnitTestAPIAdapter .mp_lock .release ()
82
86
83
87
return {"workflow" : workflow [workflow_id ]} if workflow_id in workflow else {}
84
88
85
89
def get_workflow_by_name (self , * , name : str , version : str ) -> Dict [str , Any ]:
86
90
UnitTestAPIAdapter .mp_lock .acquire ()
87
- with open (f"tests/ { _WORKFLOW_PICKLE_FILE } " , "rb" ) as pickle_file :
91
+ with open (_WORKFLOW_PICKLE_FILE , "rb" ) as pickle_file :
88
92
workflow = Unpickler (pickle_file ).load ()
89
93
UnitTestAPIAdapter .mp_lock .release ()
90
94
@@ -96,15 +100,15 @@ def get_workflow_by_name(self, *, name: str, version: str) -> Dict[str, Any]:
96
100
97
101
def create_running_workflow (self , * , workflow_id : str ) -> str :
98
102
UnitTestAPIAdapter .mp_lock .acquire ()
99
- with open (f"tests/ { _RUNNING_WORKFLOW_PICKLE_FILE } " , "rb" ) as pickle_file :
103
+ with open (_RUNNING_WORKFLOW_PICKLE_FILE , "rb" ) as pickle_file :
100
104
running_workflow = Unpickler (pickle_file ).load ()
101
105
102
106
next_id : int = len (running_workflow ) + 1
103
107
running_workflow_id : str = _RUNNING_WORKFLOW_ID_FORMAT .format (id = next_id )
104
108
record = {"done" : False , "success" : False , "workflow" : workflow_id }
105
109
running_workflow [running_workflow_id ] = record
106
110
107
- with open (f"tests/ { _RUNNING_WORKFLOW_PICKLE_FILE } " , "wb" ) as pickle_file :
111
+ with open (_RUNNING_WORKFLOW_PICKLE_FILE , "wb" ) as pickle_file :
108
112
Pickler (pickle_file ).dump (running_workflow )
109
113
UnitTestAPIAdapter .mp_lock .release ()
110
114
@@ -114,20 +118,20 @@ def set_running_workflow_done(
114
118
self , * , running_workflow_id : str , success : bool
115
119
) -> None :
116
120
UnitTestAPIAdapter .mp_lock .acquire ()
117
- with open (f"tests/ { _RUNNING_WORKFLOW_PICKLE_FILE } " , "rb" ) as pickle_file :
121
+ with open (_RUNNING_WORKFLOW_PICKLE_FILE , "rb" ) as pickle_file :
118
122
running_workflow = Unpickler (pickle_file ).load ()
119
123
120
124
assert running_workflow_id in running_workflow
121
125
running_workflow [running_workflow_id ]["done" ] = True
122
126
running_workflow [running_workflow_id ]["success" ] = success
123
127
124
- with open (f"tests/ { _RUNNING_WORKFLOW_PICKLE_FILE } " , "wb" ) as pickle_file :
128
+ with open (_RUNNING_WORKFLOW_PICKLE_FILE , "wb" ) as pickle_file :
125
129
Pickler (pickle_file ).dump (running_workflow )
126
130
UnitTestAPIAdapter .mp_lock .release ()
127
131
128
132
def get_running_workflow (self , * , running_workflow_id : str ) -> Dict [str , Any ]:
129
133
UnitTestAPIAdapter .mp_lock .acquire ()
130
- with open (f"tests/ { _RUNNING_WORKFLOW_PICKLE_FILE } " , "rb" ) as pickle_file :
134
+ with open (_RUNNING_WORKFLOW_PICKLE_FILE , "rb" ) as pickle_file :
131
135
running_workflow = Unpickler (pickle_file ).load ()
132
136
UnitTestAPIAdapter .mp_lock .release ()
133
137
@@ -139,7 +143,7 @@ def create_running_workflow_step(
139
143
self , * , running_workflow_id : str , step : str
140
144
) -> str :
141
145
UnitTestAPIAdapter .mp_lock .acquire ()
142
- with open (f"tests/ { _RUNNING_WORKFLOW_STEP_PICKLE_FILE } " , "rb" ) as pickle_file :
146
+ with open (_RUNNING_WORKFLOW_STEP_PICKLE_FILE , "rb" ) as pickle_file :
143
147
running_workflow_step = Unpickler (pickle_file ).load ()
144
148
145
149
next_id : int = len (running_workflow_step ) + 1
@@ -154,7 +158,7 @@ def create_running_workflow_step(
154
158
}
155
159
running_workflow_step [running_workflow_step_id ] = record
156
160
157
- with open (f"tests/ { _RUNNING_WORKFLOW_STEP_PICKLE_FILE } " , "wb" ) as pickle_file :
161
+ with open (_RUNNING_WORKFLOW_STEP_PICKLE_FILE , "wb" ) as pickle_file :
158
162
Pickler (pickle_file ).dump (running_workflow_step )
159
163
UnitTestAPIAdapter .mp_lock .release ()
160
164
@@ -164,7 +168,7 @@ def get_running_workflow_step(
164
168
self , * , running_workflow_step_id : str
165
169
) -> Dict [str , Any ]:
166
170
UnitTestAPIAdapter .mp_lock .acquire ()
167
- with open (f"tests/ { _RUNNING_WORKFLOW_STEP_PICKLE_FILE } " , "rb" ) as pickle_file :
171
+ with open (_RUNNING_WORKFLOW_STEP_PICKLE_FILE , "rb" ) as pickle_file :
168
172
running_workflow_step = Unpickler (pickle_file ).load ()
169
173
UnitTestAPIAdapter .mp_lock .release ()
170
174
@@ -178,22 +182,22 @@ def set_running_workflow_step_done(
178
182
self , * , running_workflow_step_id : str , success : bool
179
183
) -> None :
180
184
UnitTestAPIAdapter .mp_lock .acquire ()
181
- with open (f"tests/ { _RUNNING_WORKFLOW_STEP_PICKLE_FILE } " , "rb" ) as pickle_file :
185
+ with open (_RUNNING_WORKFLOW_STEP_PICKLE_FILE , "rb" ) as pickle_file :
182
186
running_workflow_step = Unpickler (pickle_file ).load ()
183
187
184
188
assert running_workflow_step_id in running_workflow_step
185
189
running_workflow_step [running_workflow_step_id ]["done" ] = True
186
190
running_workflow_step [running_workflow_step_id ]["success" ] = success
187
191
188
- with open (f"tests/ { _RUNNING_WORKFLOW_STEP_PICKLE_FILE } " , "wb" ) as pickle_file :
192
+ with open (_RUNNING_WORKFLOW_STEP_PICKLE_FILE , "wb" ) as pickle_file :
189
193
Pickler (pickle_file ).dump (running_workflow_step )
190
194
UnitTestAPIAdapter .mp_lock .release ()
191
195
192
196
def get_running_workflow_steps (
193
197
self , * , running_workflow_id : str
194
198
) -> List [Dict [str , Any ]]:
195
199
UnitTestAPIAdapter .mp_lock .acquire ()
196
- with open (f"tests/ { _RUNNING_WORKFLOW_STEP_PICKLE_FILE } " , "rb" ) as pickle_file :
200
+ with open (_RUNNING_WORKFLOW_STEP_PICKLE_FILE , "rb" ) as pickle_file :
197
201
running_workflow_step = Unpickler (pickle_file ).load ()
198
202
UnitTestAPIAdapter .mp_lock .release ()
199
203
@@ -206,7 +210,7 @@ def get_running_workflow_steps(
206
210
207
211
def create_instance (self , * , running_workflow_step_id : str ) -> Dict [str , Any ]:
208
212
UnitTestAPIAdapter .mp_lock .acquire ()
209
- with open (f"tests/ { _INSTANCE_PICKLE_FILE } " , "rb" ) as pickle_file :
213
+ with open (_INSTANCE_PICKLE_FILE , "rb" ) as pickle_file :
210
214
instances = Unpickler (pickle_file ).load ()
211
215
212
216
next_id : int = len (instances ) + 1
@@ -216,23 +220,23 @@ def create_instance(self, *, running_workflow_step_id: str) -> Dict[str, Any]:
216
220
}
217
221
instances [instance_id ] = record
218
222
219
- with open (f"tests/ { _INSTANCE_PICKLE_FILE } " , "wb" ) as pickle_file :
223
+ with open (_INSTANCE_PICKLE_FILE , "wb" ) as pickle_file :
220
224
Pickler (pickle_file ).dump (instances )
221
225
UnitTestAPIAdapter .mp_lock .release ()
222
226
223
227
return {"id" : instance_id }
224
228
225
229
def get_instance (self , * , instance_id : str ) -> Dict [str , Any ]:
226
230
UnitTestAPIAdapter .mp_lock .acquire ()
227
- with open (f"tests/ { _INSTANCE_PICKLE_FILE } " , "rb" ) as pickle_file :
231
+ with open (_INSTANCE_PICKLE_FILE , "rb" ) as pickle_file :
228
232
instances = Unpickler (pickle_file ).load ()
229
233
UnitTestAPIAdapter .mp_lock .release ()
230
234
231
235
return {} if instance_id not in instances else instances [instance_id ]
232
236
233
237
def create_task (self , * , instance_id : str ) -> Dict [str , Any ]:
234
238
UnitTestAPIAdapter .mp_lock .acquire ()
235
- with open (f"tests/ { _TASK_PICKLE_FILE } " , "rb" ) as pickle_file :
239
+ with open (_TASK_PICKLE_FILE , "rb" ) as pickle_file :
236
240
tasks = Unpickler (pickle_file ).load ()
237
241
238
242
next_id : int = len (tasks ) + 1
@@ -243,15 +247,15 @@ def create_task(self, *, instance_id: str) -> Dict[str, Any]:
243
247
}
244
248
tasks [task_id ] = record
245
249
246
- with open (f"tests/ { _TASK_PICKLE_FILE } " , "wb" ) as pickle_file :
250
+ with open (_TASK_PICKLE_FILE , "wb" ) as pickle_file :
247
251
Pickler (pickle_file ).dump (tasks )
248
252
UnitTestAPIAdapter .mp_lock .release ()
249
253
250
254
return {"id" : task_id }
251
255
252
256
def get_task (self , * , task_id : str ) -> Dict [str , Any ]:
253
257
UnitTestAPIAdapter .mp_lock .acquire ()
254
- with open (f"tests/ { _TASK_PICKLE_FILE } " , "rb" ) as pickle_file :
258
+ with open (_TASK_PICKLE_FILE , "rb" ) as pickle_file :
255
259
tasks = Unpickler (pickle_file ).load ()
256
260
UnitTestAPIAdapter .mp_lock .release ()
257
261
0 commit comments