Skip to content

Commit

Permalink
Added 'detailed' option to switch messages/traces column on/off
Browse files Browse the repository at this point in the history
  • Loading branch information
osavatieiev committed Sep 14, 2016
1 parent d1df9fd commit c48dae9
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 29 deletions.
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from setuptools import setup, find_packages

here = os.path.abspath(os.path.dirname(__file__))
README = open(os.path.join(here, 'README.md')).read()
README = open(os.path.join(here, 'README')).read()

DATA = [
('etc', [f for f in glob.glob(os.path.join('etc', '*'))]),
Expand All @@ -18,13 +18,14 @@
]

entry_points = {
"console_scripts": "tparser = tempest_parser.tparser:main"
"console_scripts":
"tparser = tempest_parser.tparser:tempest_cli_parser_main"
}


setup(
name="TempestParser",
version="0.1.2",
version="0.2",
author="Alex Savatieiev",
author_email="[email protected]",
classifiers=[
Expand Down
3 changes: 2 additions & 1 deletion tempest_parser/etc/tempest-parser.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[ParserConfig]
default_test_list=res/all_tests_master_ad37b61.list
default_test_list=res/all_tests_master_ad37b61.list
default_detailed=false
59 changes: 39 additions & 20 deletions tempest_parser/reports/csv_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self, test_manager):
self._total_executions = sorted(self._tests["executions"].keys())
return

def generate_to_file(self, filename):
def generate_to_file(self, filename, detailed=False):
# clear file content if any
try:
remove_file(filename)
Expand All @@ -40,8 +40,11 @@ def generate_to_file(self, filename):
_date_prepared = _date_prepared.replace('/', '\n')
_date_prepared = _date_prepared.replace(' ', '\n')
csv_header += '"' + _date_prepared + '",'
csv_header += '"' + os.path.basename(_execution) + '",'
_result_columns += 2
if detailed:
csv_header += '"' + os.path.basename(_execution) + '",'
_result_columns += 2
else:
_result_columns += 1

append_line_to_file(filename, csv_header)
_tests_counter = 0
Expand All @@ -61,7 +64,11 @@ def generate_to_file(self, filename):
# iterate tests
for _test in self._tests['tests'][class_name]:
_tests_counter += 1
_test_line = str(_tests_counter) + ',' + _test['test_name'] + _test['test_options'] + ','
_test_line = str(_tests_counter) + \
',' + \
_test['test_name'] + \
_test['test_options'] + \
','
# iterate results
_results = ""

Expand All @@ -75,23 +82,35 @@ def generate_to_file(self, filename):
for _execution in self._total_executions:
if _execution != 'required':
if _execution in _test['results']:
_results += _test['results'][_execution]['result'] + ','
# new template has no 'time' mark, just comment it out
# _results += _test['results'][_execution]['time'] + ','
_results += _test['results'][_execution][
'result'] + ','
if detailed:
# new template has no 'time' mark,
# just comment it out
# _results += _
# test['results'][_execution]['time'] + ','

# check if there is a fail
_tmp_result = _test['results'][_execution]['result']
if _tmp_result == 'FAIL':
_trace = copy(_test['results'][_execution]['trace'])
_trace = _trace.replace('"', '\'')
_results += '\"' + _test['results'][_execution]['message'] + '\x0a' \
+ _trace + '\"' + ','
elif _tmp_result == 'SKIP':
_message = copy(_test['results'][_execution]['message']).replace("\'", '\'')
_results += '\"' + _message + '\"' + ','
# check if there is a fail
_tmp_result = _test['results'][_execution][
'result']
if _tmp_result == 'FAIL':
_trace = copy(
_test['results'][_execution]['trace'])
_trace = _trace.replace('"', '\'')
_results += \
'\"' + _test['results'][_execution][
'message'] + '\x0a' + _trace + \
'\"' + ','
elif _tmp_result == 'SKIP':
_message = \
copy(_test['results'][_execution]
['message']).replace("\'", '\'')
_results += '\"' + _message + '\"' + ','
else:
_results += ','
else:
if detailed:
_results += ',' + ','
else:
_results += ','
else:
_results += ',' + ','
# _results += ','
append_line_to_file(filename, _test_line + _results)
7 changes: 4 additions & 3 deletions tempest_parser/reports/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ class _TMPLBase(_Base):
def tmpl(self):
pass

def __call__(self, results):
def __call__(self, results, detailed=False):
data = self.common_data()
data.update({
"executions": {},
"detailed": detailed,
"tests": results['tests']
})

Expand Down Expand Up @@ -108,8 +109,8 @@ def __init__(self, report, target):
self.report = report
self.target = target

def __call__(self, payload):
payload = self.report(payload)
def __call__(self, payload, detailed=False):
payload = self.report(payload, detailed)

if isinstance(self.target, six.string_types):
self._wrapped_dump(payload)
Expand Down
6 changes: 6 additions & 0 deletions tempest_parser/templates/tempest_trending_report.html
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,11 @@
<div class="label {{ status_description[STATUS_SKIP] | lower }}">{{ totals[execution][STATUS_SKIP] }}</div>
<div class="label {{ status_description[STATUS_NA] | lower }}">{{ totals[execution][STATUS_NA] }}</div>
</td>
{% if detailed %}
<td class="textlabel">
Notes
</td>
{% endif %}
{%- endfor -%}
</tr>
<tr class="headers">
Expand All @@ -198,7 +200,9 @@
<td>Required vs Added</td>
{% for execution in executions if execution != 'required' %}
<td>{{ executions[execution]['date'] }}</td>
{% if detailed %}
<td>{{ executions[execution]['filename'] }}</td>
{% endif %}
{%- endfor -%}
{% set counter = 1 %}
</tr>
Expand All @@ -224,7 +228,9 @@
{% for execution in executions if execution != 'required' %}
{% if test['results'].has_key(execution) %}
<td class="status {{ test['results'][execution]['result'] | lower }}">{{ test['results'][execution]['result'] }}</td>
{% if detailed %}
<td class="tracemessage">{{ test['results'][execution]['message'] }}<br>{{ test['results'][execution]['trace'] }}</td>
{% endif %}
{% else %}
<td class="status blank"></td>
<td class="status blank"></td>
Expand Down
19 changes: 17 additions & 2 deletions tempest_parser/tparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ def tempest_cli_parser_main():
help="file with tempest results (CSV/LOG/XML/JSON) or folder full of these files"
)

parser.add_argument(
"-d",
"--detailed",
action="store_true",
help="Include messages column with tracebacks and other messages. "
"Default comes from config"
)

parser.add_argument(
"-i",
"--include-required",
Expand Down Expand Up @@ -103,6 +111,13 @@ def tempest_cli_parser_main():
_config_file_path = args.config_file
config = ParserConfigFile(_config_file_path)

# use config to set value for 'detailed' option
_config_detailed_default = config.get_detailed_column_default_value()
_args_detailed = args.detailed

do_detailed = _args_detailed if _args_detailed \
else _config_detailed_default

# Check for supplied folder/file to be exists
if not os.path.exists(args.filepath):
print("Error: Supplied path/file not exists, '{}'".format(args.filepath))
Expand Down Expand Up @@ -148,12 +163,12 @@ def tempest_cli_parser_main():
)
# call-n-render report
print("Generating HTML Trending report...")
trending_report(tests_manager.get_tests_list())
trending_report(tests_manager.get_tests_list(), detailed=do_detailed)

if args.csv_file is not None:
print("Generating CSV report...")
csv_reporter = CSVReporter(tests_manager)
csv_reporter.generate_to_file(args.csv_file)
csv_reporter.generate_to_file(args.csv_file, detailed=do_detailed)


if __name__ == '__main__':
Expand Down
12 changes: 12 additions & 0 deletions tempest_parser/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@


class ParserConfigFile:
_truth = ['true', '1', 't', 'y', 'yes', 'yeah', 'yup',
'certainly', 'uh-huh']

def __init__(self, filepath):
self.config_file_path = filepath

Expand All @@ -24,3 +27,12 @@ def get_all_tests_list_filepath(self):
return os.path.join(pkg_dir, _path)
else:
return _path

def get_detailed_column_default_value(self):
# value
_value = self.config.get(self.section_name, 'default_detailed')
# parse if
if _value.lower() in self._truth:
return True
else:
return False

0 comments on commit c48dae9

Please sign in to comment.