Skip to content
Snippets Groups Projects
Commit f74a6129 authored by Dariusz Kędzierski's avatar Dariusz Kędzierski
Browse files

Add comments to json_report_parser.py

parent 5ce6f29f
No related branches found
No related tags found
2 merge requests!456Release candidate v1 24,!246API tests execution time reports
#!/usr/bin/python3
""" Parse json file generated by pytest benchmarks and create htm report file
for files exceeding expected threshold print information to the console
"""
import os
from sys import exit
from json import dumps, load
def get_request_from_yaml(path_to_yaml):
""" Extract request parameters from given yaml file
Parameters:
- path_to_yaml - path to yaml file
Returns:
- string with request parameters
"""
import yaml
yaml_document = None
with open(path_to_yaml, "r") as yaml_file:
......@@ -17,14 +26,20 @@ def get_request_from_yaml(path_to_yaml):
return ""
def make_class_path_dict(root_dir):
import os
""" Scan root dir for files with given pattern and construct dictionary
with keys as path with replaced ., -, / characters and values as file path
Parameters:
- root_dir - dir to scan for files
Returns:
- dict class_name -> path
"""
from fnmatch import fnmatch
pattern = "*.tavern.yaml"
ret = {}
for path, subdirs, files in os.walk(root_dir):
for path, _, files in os.walk(root_dir):
for name in files:
if fnmatch(name, pattern):
test_path = os.path.join(path, name)
......@@ -32,6 +47,13 @@ def make_class_path_dict(root_dir):
return ret
def class_to_path(class_name, class_to_path_dic):
""" Return path to test file basing on class name
Parameters:
- class_name - test to find,
- class_to_path_dic - dict with class -> path key/values
Return:
- path to test file
"""
from fnmatch import fnmatch
for c, p in class_to_path_dic.items():
if fnmatch(c, "*" + class_name):
......@@ -71,7 +93,7 @@ if __name__ == '__main__':
for benchmark in json_data['benchmarks']:
if float(benchmark['stats']['mean']) > args.time_threshold:
ofile.write(" <tr><td>{}<br/>Parameters: {}</td><td bgcolor=\"red\">{:.4f}</td></tr>\n".format(benchmark['name'], get_request_from_yaml(class_to_path(benchmark['name'][5:], class_to_path_dic)), benchmark['stats']['mean']))
above_treshold.append((benchmark['name'], benchmark['stats']['mean'], get_request_from_yaml(class_to_path(benchmark['name'][5:], class_to_path_dic))))
above_treshold.append((benchmark['name'], "{:.4f}".format(benchmark['stats']['mean']), get_request_from_yaml(class_to_path(benchmark['name'][5:], class_to_path_dic))))
else:
ofile.write(" <tr><td>{}</td><td>{:.4f}</td></tr>\n".format(benchmark['name'], benchmark['stats']['mean']))
ofile.write(" </table>\n")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment