Unverified Commit 0e8f32de authored by Jeffrey Booher-Kaeding's avatar Jeffrey Booher-Kaeding Committed by GitHub
Browse files

Merge pull request #10 from vstehle/for-jeffrey

Template and filter
parents cd007bb7 26e1667b
......@@ -32,6 +32,21 @@ $ ./parser.py --sort \
'group,descr,set guid,test set,sub set,guid,name,log' ...
### Filtering data
The `--filter` option allows to specify a python3 expression, which is used as a
filter. The expression is evaluated for each test; if it evaluates to True the
test is kept, otherwise it is omitted. The expression has access to the test
as dict "x".
Example command, which keeps only the failed tests:
``` {.sh}
$ ./parser.py --filter "x['result'] == 'FAILURE'" ...
Filtering takes place after the configuration rules, which are described below.
## Configuration file
It is possible to use a configuration file with command line option `--config
......@@ -97,6 +112,23 @@ Try it with:
$ ./parser.py --config sample.yaml ...
### Generating a configuration template
To ease the writing of yaml configurations, there is a `--template` option to
generate a configuration "template" from the results of a run:
``` {.sh}
$ ./parser.py --template template.yaml ...
This generated configuration can then be further edited manually.
* Tests with result "PASS" are omitted.
* The following tests fields are omitted from the generated rule "criteria":
"iteration", "start date" and "start time".
* The generated rule "criteria" "log" field is filtered to remove the leading
path before C filename.
## Notes
### Known Issues:
* "comment" is currently not implemented, as formatting is not currently consistent, should reflect the comments from the test.
......@@ -7,6 +7,7 @@ import argparse
import csv
import logging
import json
import re
from packaging import version
......@@ -314,6 +315,21 @@ def use_config(cross_check, filename):
apply_rules(cross_check, conf)
# Filter tests data
# Filter is a python expression, which is evaluated for each test
# When the expression evaluates to True, the test is kept
# Otherwise it is dropped
def filter_data(cross_check, Filter):
logging.debug(f"Filtering with `{Filter}'")
# This function "wraps" the filter and is called for each test
def function(x):
return eval(Filter)
return list(filter(function, cross_check))
# Sort tests data in-place
# sort_keys is a comma-separated list
# The first key has precedence, then the second, etc.
......@@ -359,6 +375,44 @@ def gen_yaml(cross_check, filename):
yaml.dump(cross_check, yamlfile, Dumper=Dumper)
# Generate yaml config template
# This is to help writing yaml config.
# We omit tests with result PASS.
# We omit some tests keys: iteration and dates.
# We remove the leading directory from C filename in log.
def gen_template(cross_check, filename):
assert('yaml' in sys.modules)
logging.debug(f'Generate {filename}')
omitted_keys = set(['iteration', 'start date', 'start time'])
t = []
i = 1
for x in cross_check:
if x['result'] == 'PASS':
r = {
'rule': f'Generated rule ({i})',
'criteria': {},
'update': {'result': 'TEMPLATE'},
for key, value in x.items():
if key in omitted_keys:
if key == 'log':
value = re.sub(r'^/.*/', '', value)
r['criteria'][key] = value
i += 1
with open(filename, 'w') as yamlfile:
yaml.dump(t, yamlfile, Dumper=Dumper)
# Combine or two databases db1 and db2 coming from ekl and seq files
# respectively into a single cross_check database
# Tests in db1, which were not meant to be run according to db2 have their
......@@ -447,6 +501,7 @@ def main():
'--debug', action='store_true', help='Turn on debug messages')
'--sort', help='Comma-separated list of keys to sort output on')
parser.add_argument('--filter', help='Python expression to filter results')
'log_file', nargs='?', default='sample.ekl',
help='Input .ekl filename')
......@@ -462,6 +517,8 @@ def main():
'--config', help='Input .yaml configuration filename')
parser.add_argument('--yaml', help='Output .yaml filename')
'--template', help='Output .yaml config template filename')
args = parser.parse_args()
......@@ -495,6 +552,10 @@ def main():
if 'config' in args and args.config is not None:
use_config(cross_check, args.config)
# Filter tests data, if requested
if args.filter is not None:
cross_check = filter_data(cross_check, args.filter)
# Sort tests data in-place, if requested
if args.sort is not None:
sort_data(cross_check, args.sort)
......@@ -558,8 +619,12 @@ def main():
if 'yaml' in args and args.yaml is not None:
gen_yaml(cross_check, args.yaml)
#command line argument 3&4, key are to support a key & value search.
#these will be displayed in CLI
# Generate yaml config template if requested
if 'template' in args and args.template is not None:
gen_template(cross_check, args.template)
# command line argument 3&4, key are to support a key & value search.
# these will be displayed in CLI
if args.find_key is not None and args.find_value is not None:
found = key_value_find(db1, args.find_key, args.find_value)
#print the dict
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment