Skip to content

Commit

Permalink
Extended task event handler args test.
Browse files Browse the repository at this point in the history
  • Loading branch information
hjoliver committed Nov 3, 2017
1 parent 0c05edf commit 36500b8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
41 changes: 32 additions & 9 deletions tests/events/39-task-event-template-all/bin/checkargs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,42 @@

# Compare actual and expected event handler command lines.

import os
import sys
import subprocess

start = ['SUITE:', 'JID:']
other = ['custom', '1', 'foo', '1', 'foo.1', 'background', 'cheesy peas', 'trout',
'a task called foo', 'http://cheesy.peas', 'a test suite', 'large']
one = len(sys.argv) >= 3
two = sys.argv[1].startswith(start[0])
thr = sys.argv[2].startswith(start[1])
fou = sys.argv[3:] == other
args = dict([arg.split('=') for arg in sys.argv[1:]])

if one and two and thr and fou:
suite = os.environ['CYLC_SUITE_NAME']
alog = subprocess.check_output(['cylc', 'cat-log', '-la', suite, 'foo.1'])
start_time, _, job_id = (subprocess.check_output(['grep', 'STDOUT', alog.strip()])).split(' ')

expected_args = {
'suite_title': 'a test suite',
'job_id': job_id.strip(),
'start_time': 'None',
'point': '1',
'URL': 'http://cheesy.peas',
'title': 'a task called foo',
'fish': 'trout',
'submit_num': '1',
'batch_sys_name': 'background',
'id': 'foo.1',
'finish_time': 'None',
'suite_size': 'large',
'suite': suite,
'message': 'cheesy peas',
'user@host': 'localhost',
'event': 'custom',
'submit_time': start_time,
'name': 'foo'
}


if args == expected_args:
print "OK: command line checks out"
sys.exit(0)
else:
print >> sys.stderr, 'ERROR: unexpected event handler command line.'
print >> sys.stderr, "EXPECTED:", expected_args
print >> sys.stderr, "RECEIVED:", args
sys.exit(1)
2 changes: 1 addition & 1 deletion tests/events/39-task-event-template-all/suite.rc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[[foo]]
script = cylc message -p CUSTOM "cheesy peas"
[[[events]]]
custom handler = checkargs SUITE:%(suite)s JID:%(batch_sys_job_id)s %(event)s %(point)s %(name)s %(submit_num)s %(id)s %(batch_sys_name)s %(message)s %(fish)s %(title)s %(URL)s %(suite_title)s %(suite_size)s
custom handler = checkargs suite=%(suite)s job_id=%(batch_sys_job_id)s event=%(event)s point=%(point)s name=%(name)s submit_num=%(submit_num)s id=%(id)s batch_sys_name=%(batch_sys_name)s message=%(message)s fish=%(fish)s title=%(title)s URL=%(URL)s suite_title=%(suite_title)s suite_size=%(suite_size)s submit_time=%(submit_time)s start_time=%(start_time)s finish_time=%(finish_time)s user@host=%(user@host)s
[[[meta]]]
title = "a task called foo"
URL = http://cheesy.peas
Expand Down

0 comments on commit 36500b8

Please sign in to comment.