Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show and scan: add JSON option and metadata #2558

Merged
merged 16 commits into from
Feb 6, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Tailor tests to account for arbitary floats with regex
  • Loading branch information
sadielbartholomew committed Jan 29, 2018
commit 5cb878b37586c1174713bf531be4dc4b13916a36
4 changes: 2 additions & 2 deletions tests/authentication/02-state-totals.t
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ cmp_json_ok 'scan-j.out' 'scan-j.out' <<__END__
"tasks-by-state":{
"failed":[
[
1516968607.0,
"<FLOAT_REPLACED>",
"foo",
"1"
]
Expand All @@ -153,7 +153,7 @@ cmp_json_ok 'scan-j.out' 'scan-j.out' <<__END__
"custom_metadata":"something_custom"
},
"owner":"${USER}",
"update-time":1516968608.1505351,
"update-time":"<FLOAT_REPLACED>",
"name":"${SUITE_NAME}"
}
]
Expand Down
4 changes: 2 additions & 2 deletions tests/authentication/03-full-read.t
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ cmp_json_ok 'scan-j.out' 'scan-j.out' <<__END__
"tasks-by-state":{
"failed":[
[
1516968607.0,
"<FLOAT_REPLACED>",
"foo",
"1"
]
Expand All @@ -153,7 +153,7 @@ cmp_json_ok 'scan-j.out' 'scan-j.out' <<__END__
"custom_metadata":"something_custom"
},
"owner":"${USER}",
"update-time":1516968608.1505351,
"update-time":"<FLOAT_REPLACED>",
"name":"${SUITE_NAME}"
}
]
Expand Down
4 changes: 2 additions & 2 deletions tests/authentication/04-shutdown.t
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ cmp_json_ok 'scan-j.out' 'scan-j.out' <<__END__
"tasks-by-state":{
"failed":[
[
1516968607.0,
"<FLOAT_REPLACED>",
"foo",
"1"
]
Expand All @@ -152,7 +152,7 @@ cmp_json_ok 'scan-j.out' 'scan-j.out' <<__END__
"custom_metadata":"something_custom"
},
"owner":"${USER}",
"update-time":1516968608.1505351,
"update-time":"<FLOAT_REPLACED>",
"name":"${SUITE_NAME}"
}
]
Expand Down
4 changes: 2 additions & 2 deletions tests/authentication/05-full-control.t
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ cmp_json_ok 'scan-j.out' 'scan-j.out' <<__END__
"tasks-by-state":{
"failed":[
[
1516968607.0,
"<FLOAT_REPLACED>",
"foo",
"1"
]
Expand All @@ -151,7 +151,7 @@ cmp_json_ok 'scan-j.out' 'scan-j.out' <<__END__
"custom_metadata":"something_custom"
},
"owner":"${USER}",
"update-time":1516968608.1505351,
"update-time":"<FLOAT_REPLACED>",
"name":"${SUITE_NAME}"
}
]
Expand Down
14 changes: 7 additions & 7 deletions tests/authentication/06-suite-override.t
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ cmp_json_ok 'scan-j.out' 'scan-j.out' <<__END__
"tasks-by-state":{
"failed":[
[
1516968607.0,
"<FLOAT_REPLACED>",
"foo",
"1"
]
Expand All @@ -134,14 +134,14 @@ cmp_json_ok 'scan-j.out' 'scan-j.out' <<__END__
]
]
},
"meta":{
"URL":"",
"group":"",
"description":"Stalls when the first task fails.\nSuite overrides global authentication settings.",
"title":"Authentication test suite."
"meta": {
"URL": "",
"group": "",
"description": "Stalls when the first task fails.\nSuite overrides global authentication settings.",
"title": "Authentication test suite."
},
"owner":"${USER}",
"update-time":1516968608.1505351,
"update-time":"<FLOAT_REPLACED>",
"name":"${SUITE_NAME}"
}
]
Expand Down
4 changes: 2 additions & 2 deletions tests/authentication/07-sha-hash.t
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ cmp_json_ok 'scan-j.out' 'scan-j.out' <<__END__
"tasks-by-state":{
"failed":[
[
1516968607.0,
"<FLOAT_REPLACED>",
"foo",
"1"
]
Expand All @@ -154,7 +154,7 @@ cmp_json_ok 'scan-j.out' 'scan-j.out' <<__END__
"custom_metadata":"something_custom"
},
"owner":"${USER}",
"update-time":1516968608.1505351,
"update-time":"<FLOAT_REPLACED>",
"name":"${SUITE_NAME}"
}
]
Expand Down
46 changes: 26 additions & 20 deletions tests/lib/bash/test_header
Original file line number Diff line number Diff line change
Expand Up @@ -218,35 +218,41 @@ cmp_ok() {

cmp_json_ok() {
run_ok "$1" python -c "import sys
import re
import json
from cylc.task_state import TASK_STATUSES_ORDERED

# no need for try/except as get traceback anyway in stderr
# Load data; no need for JSON object try/except as get stderr traceback anyway
output = json.load(open(sys.argv[1], 'r'))
if sys.argv[2]:
expected_output = json.load(open(sys.argv[2], 'r'))
else:
expected_output = json.load(sys.stdin)
output = json.load(open(sys.argv[1], 'r'))

# convert unicode for useful stderr - '^?*?^' chosen as arbitrary placeholder
def process(some_output):
if isinstance(some_output, unicode):
return str(some_output.encode('utf-8')).replace('\'', '^?*?^')
if isinstance(some_output, list):
return [process(item) for item in some_output]
if isinstance(some_output, dict):
return dict((process(key), process(value)) for key, value in
some_output.items())
return some_output

# check for match; if different process for convenient stderr lifting -> tests
if output == expected_output:
# Replace arbitary time floats in JSON structures for effective comparison
def float_repl(some_output, marker):
new_output = re.sub(r'((\'|\")update-time(\'|\")\s*:\s*)\d*\.\d*',
r'\1' + marker, str(some_output))
# Deal with cylc scan TIME_FIELDS (see cylc.state_summary_mgr)
for status in TASK_STATUSES_ORDERED:
new_regex = (r'((\'|\")%s(\'|\")\s*:\s*\[\n*\s*\[\n*\s*)\d*\.\d*' %
status)
new_output = re.sub(new_regex, r'\1' + marker, str(new_output))
return new_output

# Unicode (u'...') for 'loaded' outputs; double-quoted strings for 'dumps'
u_marker = \"u'<FLOAT_REPLACED>'\"
s_marker = '\"<FLOAT_REPLACED>\"'

# Check for match; if different, process for easy stderr lifting -> tests
if float_repl(output, u_marker) == float_repl(expected_output, u_marker):
sys.exit(0)
else:
# Python's return always includes single quotes; JSON needs double
print_string = '%s\n not equal to \n%s' % (
str(process(output)).replace('\'', '\"'),
str(process(expected_output)).replace('\'', '\"'))
sys.exit(print_string.replace('^?*?^', '\''))" "$2" "${3:-}"
sys.exit('LOADED:\n%s\n!=\n%s\n OR DUMPED:\n%s\n!=\n%s' % (
float_repl(output, u_marker), float_repl(expected_output, u_marker),
float_repl(json.dumps(output, indent=4), s_marker),
float_repl(json.dumps(expected_output, indent=4),
s_marker)))" "$2" "${3:-}"
}

contains_ok() {
Expand Down