Skip to content

Commit

Permalink
Fixes: templates, name parsing, uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
savex committed Mar 16, 2018
1 parent 5069fae commit 64146d1
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 1,730 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
jinja2
six
python-subunit
testtools

3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
]

dependencies = [
'six',
'jinja2',
'six',
'python-subunit',
'testtools'
]

Expand Down
37 changes: 18 additions & 19 deletions tempest_parser/manager/importers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from subunit.test_results import TestByTestResult
from subunit.filters import run_tests_from_stream
from testtools import StreamToExtendedDecorator
from testtools import PlaceHolder

CSV_OWN = 1
CSV_XUNIT = 2
Expand Down Expand Up @@ -158,10 +157,10 @@ def parse(self):
verification = data['verifications'].keys()[0]

# iterate through test cases and add up results
for _test_value in data['tests'].values():
_splitted_test_name = _test_value['name'].rsplit('.', 1)
_class_name = _splitted_test_name[0]
_test_name = _splitted_test_name[1]
for _test_name, _test_value in data['tests'].items():
_class_name, _test_name, _uuid, _options = \
self.tm.split_test_name(_test_name)

_test_value_results = _test_value['by_verification'][verification]
_status = self._parse_status(_test_value_results['status'])
_duration = _test_value_results['duration'] + 's'
Expand All @@ -170,20 +169,20 @@ def parse(self):
'traceback'] if 'traceback' in _test_value_results else ''

# parsing tags
if _test_value['tags'][0].find('(') > -1:
_tag = _test_value['tags'][0].split(']')[0]
_tags = '[{}]'.format(_tag)
_option = _test_value['tags'][0].split('(')[1]
_options = '({})'.format(_option)
else:
_tags = '[{}]'.format(','.join(_test_value['tags']))
_options = ''
# if _test_value['tags'][0].find('(') > -1:
# _tag = _test_value['tags'][0].split(']')[0]
# _tags = '[{}]'.format(_tag)
# _option = _test_value['tags'][0].split('(')[1]
# _options = '({})'.format(_option)
# else:
# _tags = '[{}]'.format(','.join(_test_value['tags']))
# _options = ''

self.tm.add_result_for_test(
_execution_name,
_class_name,
_test_name,
_tags,
_uuid,
_options,
_status,
_duration,
Expand Down Expand Up @@ -342,14 +341,14 @@ def __init__(self, name, tm):
def _on_test(self, test, status, start_time, stop_time, tags, details):
print(' '*6, end='\r')
_test_name = "none"
_uuid = ""
_test_options = ""
_id = test.id()
if _id.startswith("setUpClass"):
_, _class_name, _ = self.tm.split_test_name(_id)
_class_name, _, _, _ = self.tm.split_test_name(_id)
else:
_class_name, _test_name, _test_options = self.tm.split_test_name(
_id
)
_class_name, _test_name, _uuid, _test_options = \
self.tm.split_test_name(_id)

_status = self._parse_status(status)

Expand All @@ -365,7 +364,7 @@ def _on_test(self, test, status, start_time, stop_time, tags, details):
self._execution_name,
_class_name,
_test_name,
tags,
_uuid,
_test_options,
_status,
stop_time - start_time,
Expand Down
3 changes: 2 additions & 1 deletion tempest_parser/manager/structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
# class names will be as a key
# "class_name": "",
"test_name": "",
"uuid": "",
"test_options": "",
"set_name": "",
"tags": "",
"results": {}
}

Expand Down
110 changes: 53 additions & 57 deletions tempest_parser/manager/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,21 @@ def _load_from_folder(self, folder):

return _tests

# In case we'll need to list all of the tests in tempest and mark which ones was executed,
# we have this list of all tests
# It produced by ./run_tempest.sh -- --list >tests.list
# In case we'll need to list all of the tests in tempest
# and mark which ones was executed, we have list of all tests
# It produced by ./tempest run --list-tests >all_tests_tag_<N>.list
def _all_tests_file_preload(self, resource_file):
_tests = {}

# load all tests file
with open(resource_file) as tests_file:
for line in tests_file:
_search_res = line.partition('[')

_class_name, _test_name, _test_options = self.split_test_name(
line.replace("\n", ""))
_class_name, _test_name, _uuid, _test_options = \
self.split_test_name(line.replace("\n", ""))

self._test_item = deepcopy(structs._template_test_item)
self._test_item["test_name"] = _test_name
self._test_item["set_name"] = _search_res[1].replace("\n",
"") + \
_search_res[2].partition(']')[
0].replace("\n", "") + "]"
self._test_item["uuid"] = _uuid
self._test_item["results"][
self.required_execution_name] = dict(result="R", time='0s')

Expand All @@ -88,36 +83,43 @@ def _all_tests_file_preload(self, resource_file):

@staticmethod
def split_test_name(full_test_name):
def _dig_guid(raw_trailing):
return raw_trailing.split(']')[0]

def _dig_options(raw_options):
if len(raw_options) >= 2:
if len(raw_options[1]) > 0:
return raw_options[1]
return raw_options
__options = raw_options.split(']')[1:]
if len(__options) >= 2:
if len(__options[1]) > 0:
return __options[1]
return "".join(__options)

_first_name = full_test_name.split('.', 1)[0]

_class = ""
_test = ""
_guid = ""
_options = ""
if full_test_name.startswith("setUpClass") or \
full_test_name.startswith("tearDownClass"):
return (
full_test_name.split(" ")[0],
full_test_name.split("(")[1][:-1],
""
)
elif _first_name is "unittest2":
_class = full_test_name.split("(")[1][:-1]
elif _first_name.startswith("unittest2"):
# parse unittest fail
_name = full_test_name.split(".", 3)[3]
_class = _name.rsplit(".", 1)[0]
_test = _name.rsplit(".", 1)[1].split('[')[0]
_tmp = _name.rsplit(".", 1)[1].split(']')
return _class, _test, _dig_options(_tmp)
_name = full_test_name.split(".", 3)[3].rsplit(".", 1)
_tmp = _name[1]
_class = _name[0]
_test = _tmp.split('[')[0]
if ']' in _tmp:
_guid = _dig_guid(_tmp)
_options = _dig_options(_tmp)
elif _first_name.startswith("tempest") or \
_first_name.endswith("_tempest_plugin"):
_first_name.endswith("_tempest_plugin") or \
_first_name.endswith("_tempest_tests"):
_class = full_test_name.rsplit(".", 1)[0]
_test = full_test_name.rsplit(".", 1)[1].split('[')[0]
_tmp = full_test_name.rsplit(".", 1)[1].split(']')
_trailing = full_test_name.rsplit(".", 1)[1].split('[')[1]
_guid = _dig_guid(_trailing)
_options = _dig_options(_trailing)

return _class, _test, _dig_options(_tmp)
return None, None, None
return _class, _test, _guid, _options

@staticmethod
def split_test_name_from_speed(full_test_name):
Expand All @@ -134,21 +136,19 @@ def split_test_name_from_speed(full_test_name):
_options
)

def test_name_lookup(self, class_name, test_name, set_name, test_options):
def test_name_lookup(self, class_name, test_name, uuid, test_options):
_index = -1
_tests = self.tests_list["tests"]

if class_name in _tests:
for _test_index in range(0, _tests[class_name].__len__()):
if _tests[class_name][_test_index]["test_name"] == test_name \
and _tests[class_name][_test_index][
"test_options"] == test_options:
if set_name == '' or _tests[class_name][_test_index][
"set_name"] == '':
_indexed_test = _tests[class_name][_test_index]
if _indexed_test["test_name"] == test_name \
and _indexed_test["test_options"] == test_options:
if uuid == '' or _indexed_test["uuid"] == '':
_index = _test_index
break
elif _tests[class_name][_test_index][
"set_name"] == set_name:
elif _indexed_test["uuid"] == uuid:
_index = _test_index
break

Expand All @@ -167,14 +167,13 @@ def test_name_lookup_bare(self, class_name, test_name):
return _index

def partial_class_name_lookup(self, class_name_short, test_name,
set_name=None, test_options=None):
uuid=None, test_options=None):
_list = []
_full_class_name = ""
_class_names = self.tests_list["tests"].keys()
for _class_name in _class_names:
if _class_name.endswith(class_name_short):
_index = self.test_name_lookup(_class_name, test_name,
set_name, test_options)
uuid, test_options)
if _index > -1:
_full_class_name = _class_name
_list.append(_full_class_name)
Expand All @@ -191,28 +190,25 @@ def add_execution(self, _execution):

def mark_slowest_test_in_execution_by_name(self, execution_name,
class_name, test_name,
set_name=None,
uuid=None,
test_options=None):
_index = self.test_name_lookup(class_name, test_name, set_name,
_index = self.test_name_lookup(class_name, test_name, uuid,
test_options)
if _index > -1:
# mark slowest tests
self.tests_list["tests"][class_name][_index]["results"][
execution_name]["slowest"] = True
else:
print(
"WARNING: Parsed slowest test not found in list: {0}, {1}, {2}".format(
execution_name,
class_name,
test_name
))
print("""
WARNING: Parsed slowest test not found in list: {0}, {1}, {2}
""".format(execution_name, class_name, test_name))

def add_fail_data_for_test(self, execution_name, class_name, test_name,
test_options, trace, message,
class_name_short=False, set_name=None):
if class_name == "setUpClass" or \
class_name == "tearDownClass":
# if this is a setUpClass situation, mark all tests with this result
class_name_short=False, uuid=None):
if class_name == "setUpClass" or class_name == "tearDownClass":
# if this is a setUpClass situation,
# mark all tests with this result
_tests = self.tests_list["tests"]
if test_name in _tests:
for _test_index in range(0, _tests[test_name].__len__()):
Expand All @@ -233,7 +229,7 @@ def add_fail_data_for_test(self, execution_name, class_name, test_name,
_index = self.test_name_lookup(
_full_class_name,
test_name,
set_name,
uuid,
test_options
)
if _index > -1:
Expand All @@ -250,7 +246,7 @@ def add_fail_data_for_test(self, execution_name, class_name, test_name,
message
))

def add_result_for_test(self, execution_name, class_name, test_name, tags,
def add_result_for_test(self, execution_name, class_name, test_name, uuid,
test_options, result, running_time,
message='', trace='', class_name_short=False,
test_name_bare=False):
Expand Down Expand Up @@ -290,7 +286,7 @@ def add_result_for_test(self, execution_name, class_name, test_name, tags,
_index = self.test_name_lookup(
_full_class_name,
test_name,
tags,
uuid,
test_options
)
if _index > -1:
Expand Down
3 changes: 2 additions & 1 deletion tempest_parser/parser/tempest_log_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ def parse_execution_list(self, _object_list):
except IndexError as e:
_full_name = _line_s

(_class_name, _test_name, _test_options) = self.test_mgr.split_test_name(_full_name)
(_class_name, _test_name, _uuid, _test_options) = \
self.test_mgr.split_test_name(_full_name)
_test_fail_head_found = True
elif _line_s.startswith("Details: "):
_line_s = _line_s.replace('"', '\'')
Expand Down
4 changes: 2 additions & 2 deletions tempest_parser/reports/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __call__(self, results, detailed=False):
def common_data(self):
return {
'report': self,

'counters': {'all_count': 1},
'STATUS_PASS': const.STATUS_PASS,
'STATUS_FAIL': const.STATUS_FAIL,
'STATUS_ERROR': const.STATUS_ERROR,
Expand Down Expand Up @@ -162,7 +162,7 @@ def _extend_data(self, data):
_dict = {
'test_class': test_class,
'test_name': test['test_name'],
'set_name': test['set_name'],
'uuid': test['uuid'],
'test_options': test['test_options'],
'trace_details': _trace_details,
'trace_additional': _trace_messages
Expand Down
Loading

0 comments on commit 64146d1

Please sign in to comment.