-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtester.py
40 lines (30 loc) · 860 Bytes
/
tester.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
# tester.py
# Test a job script as if being run by a posdouv setup
import inspect
import sys
job_filename = sys.argv[1]
job_args = sys.argv[2:]
job_file = open(job_filename, 'r')
x = compile(job_file.read(), job_filename, 'exec')
job_file.close()
exec(x)
# find job_worker() and suck all the source starting with it
job_worker_lines = inspect.findsource(job_worker)
job_worker_str = ''.join(job_worker_lines[0][job_worker_lines[1]:])
# initialize the job
if job_init(job_args):
print 'job_init() failed'
sys.exit(1)
job_globals = job_get_globals()
nof_tasks = 0
while 1:
# get an argument for a task
arg = job_get_arg(nof_tasks)
if arg == None: break
# execute the task
result = job_worker(arg)
# add the result
job_add_result(nof_tasks, result)
nof_tasks = nof_tasks + 1
# job is done
job_finish()