| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
# Compare actual and expected event handler command lines. |
| 4 |
|
| 5 |
import os |
| 6 |
import sys |
| 7 |
from subprocess import Popen, PIPE |
| 8 |
|
| 9 |
args = dict([arg.split('=', 1) for arg in sys.argv[1:]]) |
| 10 |
|
| 11 |
workflow = os.environ['CYLC_WORKFLOW_ID'] |
| 12 |
proc = Popen(['cylc', 'cat-log', '-m', 'p', '-f', 'a', workflow, '//1/foo'], |
| 13 |
stdout=PIPE, stdin=open(os.devnull)) |
| 14 |
alog = proc.communicate()[0].decode().strip() |
| 15 |
proc.wait() |
| 16 |
for line in open(alog): |
| 17 |
if 'STDOUT' in line: |
| 18 |
submit_time, _, job_id = line.split(' ') |
| 19 |
break |
| 20 |
|
| 21 |
del args['start_time'] # must exist, but value unreliable |
| 22 |
|
| 23 |
desired_args = { |
| 24 |
'workflow_title': 'a test workflow', |
| 25 |
'job_id': job_id.strip(), |
| 26 |
'point': '1', |
| 27 |
'URL': 'http://cheesy.peas', |
| 28 |
'title': 'a task called foo', |
| 29 |
'fish': 'trout', |
| 30 |
'submit_num': '1', |
| 31 |
'try_num': '1', |
| 32 |
'job_runner_name': 'background', |
| 33 |
'id': '1/foo', |
| 34 |
'finish_time': 'None', |
| 35 |
'workflow_size': 'large', |
| 36 |
'workflow': workflow, |
| 37 |
'message': 'cheesy peas', |
| 38 |
'platform_name': 'localhost', |
| 39 |
'event': 'custom', |
| 40 |
'submit_time': submit_time, |
| 41 |
'name': 'foo' |
| 42 |
} |
| 43 |
|
| 44 |
try: |
| 45 |
assert args == desired_args |
| 46 |
except AssertionError: |
| 47 |
msg = "" |
| 48 |
for key, value in desired_args.items(): |
| 49 |
if args[key] != value: |
| 50 |
msg += f"\nkey, args[key], value are: {key, args[key], value}" |
| 51 |
raise AssertionError(msg) |
| 52 |
|
| 53 |
print('OK: command line checks out') |