brunhilda 2.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. brunhilda/__init__.py +7 -0
  2. brunhilda/brunhilda.py +103 -0
  3. brunhilda/data.py +107 -0
  4. brunhilda/exception.py +9 -0
  5. brunhilda/html_feature_summary_output.py +187 -0
  6. brunhilda/html_index_output.py +19 -0
  7. brunhilda/html_issue_list_output.py +22 -0
  8. brunhilda/html_output.py +119 -0
  9. brunhilda/html_req_summary_output.py +74 -0
  10. brunhilda/html_result_output.py +45 -0
  11. brunhilda/html_test_plan_output.py +38 -0
  12. brunhilda/html_test_summary_output.py +44 -0
  13. brunhilda/html_trace_output.py +17 -0
  14. brunhilda/html_user_stories_summary.py +79 -0
  15. brunhilda/junit_result_output.py +69 -0
  16. brunhilda/loader.py +79 -0
  17. brunhilda/output.py +44 -0
  18. brunhilda/parser.py +138 -0
  19. brunhilda/rel_path.py +25 -0
  20. brunhilda/reporter.py +323 -0
  21. brunhilda/result.py +711 -0
  22. brunhilda/tag_filter.py +209 -0
  23. brunhilda/templates/header.html.jinja2 +40 -0
  24. brunhilda/templates/index.html.jinja2 +28 -0
  25. brunhilda/templates/issue-list.html.jinja2 +139 -0
  26. brunhilda/templates/summary-features.html.jinja2 +294 -0
  27. brunhilda/templates/summary-req.html.jinja2 +141 -0
  28. brunhilda/templates/summary-test.html.jinja2 +162 -0
  29. brunhilda/templates/summary-user-stories.html.jinja2 +121 -0
  30. brunhilda/templates/summary.html.jinja2 +326 -0
  31. brunhilda/templates/template.html.jinja2 +304 -0
  32. brunhilda/templates/template.junit.jinja2 +52 -0
  33. brunhilda/templates/test-plan.html.jinja2 +93 -0
  34. brunhilda/templates/themes/base.css +1177 -0
  35. brunhilda/templates/trace.html.jinja2 +240 -0
  36. brunhilda/tests/__init__.py +0 -0
  37. brunhilda/tests/test_tag_filter.py +218 -0
  38. brunhilda-2.4.0.dist-info/LICENSE +19 -0
  39. brunhilda-2.4.0.dist-info/METADATA +493 -0
  40. brunhilda-2.4.0.dist-info/RECORD +42 -0
  41. brunhilda-2.4.0.dist-info/WHEEL +5 -0
  42. brunhilda-2.4.0.dist-info/top_level.txt +1 -0
brunhilda/__init__.py ADDED
@@ -0,0 +1,7 @@
1
+ from .brunhilda import BRunhilda
2
+ from .result import BRunhildaTestResult
3
+ from .loader import BRunhildaTestLoader
4
+ from .reporter import Reporter
5
+
6
+ __version__ = '2.4.0'
7
+ __all__ = ["BRunhilda", "BRunhildaTestResult", "BRunhildaTestLoader", "Reporter"]
brunhilda/brunhilda.py ADDED
@@ -0,0 +1,103 @@
1
+ import sys
2
+ import unittest
3
+ from unittest.suite import TestSuite
4
+
5
+ from .loader import iter_suite
6
+ from .result import BRunhildaTestResult, EMPTY
7
+ from .html_result_output import HtmlResultOutput
8
+ from .junit_result_output import JUnitResultOutput
9
+
10
+ __unittest = True
11
+
12
+
13
+ class BRunhilda(unittest.TextTestRunner):
14
+ """
15
+ A test runner class that displays results in textual form.
16
+ It prints out the names of tests as they are run, errors as they
17
+ occur, and a summary of the results at the end of the test run.
18
+ """
19
+
20
+ def __init__(self, stream=sys.stderr,
21
+ descriptions=True,
22
+ verbosity=1,
23
+ failfast=False,
24
+ buffer=False,
25
+ warnings=None,
26
+ name="",
27
+ dut="",
28
+ extra_data_output="extra",
29
+ user_data=None):
30
+ super().__init__(stream=stream,
31
+ descriptions=descriptions,
32
+ verbosity=verbosity,
33
+ failfast=failfast,
34
+ buffer=buffer,
35
+ warnings=warnings)
36
+ self.name = name
37
+ self.dut = dut
38
+ self.user_data = user_data
39
+ self.extra_data_output = extra_data_output
40
+
41
+ def dryrun(self, suite: TestSuite) -> BRunhildaTestResult:
42
+ """
43
+ Executes a dry run of the test suite. Creates the same artifacts as a normal run but without
44
+ actually executing the tests.
45
+
46
+ :param suite: test suite
47
+ :return: test result
48
+ """
49
+ result = self._makeResult()
50
+ result.startTestRun()
51
+
52
+ for test in iter_suite(suite):
53
+ result.startTest(test)
54
+ result.last_result = EMPTY # override since we do not execute the test
55
+ result.stopTest(test)
56
+
57
+ result.stopTestRun()
58
+ return result
59
+
60
+ def _makeResult(self):
61
+ return BRunhildaTestResult(self.stream,
62
+ self.descriptions,
63
+ self.verbosity,
64
+ self.name,
65
+ self.dut,
66
+ extra_data_path=self.extra_data_output,
67
+ user_data=self.user_data)
68
+
69
+ def save_html_report(self, result, output_path):
70
+ """
71
+ Prints the HTML report of the last result
72
+ """
73
+ try:
74
+ result.print(HtmlResultOutput(), output_path)
75
+ except Exception as ex:
76
+ print(ex)
77
+
78
+ def save_junit_report(self, result, output_path):
79
+ """
80
+ Prints the jUnit report of the last result
81
+ """
82
+ try:
83
+ result.print(JUnitResultOutput(), output_path)
84
+ except Exception as ex:
85
+ print(ex)
86
+
87
+ def save_issues(self, result, output_path):
88
+ """
89
+ Serializes issues from the last result.
90
+ """
91
+ try:
92
+ result.serialize_issues(output_path)
93
+ except Exception as ex:
94
+ print(ex)
95
+
96
+ def save_tests(self, result, output_path):
97
+ """
98
+ Serializes executed tests from the last result.
99
+ """
100
+ try:
101
+ result.serialize_tests(output_path)
102
+ except Exception as ex:
103
+ print(ex)
brunhilda/data.py ADDED
@@ -0,0 +1,107 @@
1
+ from dataclasses import dataclass
2
+
3
+
4
+ try:
5
+ from typing import Literal
6
+ except ImportError: # pragma: no cover
7
+ from typing_extensions import Literal
8
+
9
+ Result = Literal['PASSED', 'FAILED', 'ERRORED', 'JUSTIFIED', 'SKIPPED', 'UNEXPECTED-SUCCESS', 'EXPECTED-FAILURE', 'EMPTY']
10
+
11
+
12
+ @dataclass(eq=True, unsafe_hash=True)
13
+ class ResultsSummary:
14
+ passed: int
15
+ failed: int
16
+ errored: int
17
+ skipped: int
18
+ justified: int
19
+ expected_failures: int
20
+ unexpected_successes: int
21
+ not_executed: int
22
+
23
+ @property
24
+ def total(self) -> int:
25
+ return (self.passed
26
+ + self.failed
27
+ + self.errored
28
+ + self.skipped
29
+ + self.justified
30
+ + self.expected_failures
31
+ + self.unexpected_successes
32
+ + self.not_executed)
33
+
34
+ @property
35
+ def pct_passed(self) -> float:
36
+ return (self.passed / self.total * 100.0) if (self.total != 0) else 0.0
37
+
38
+ @property
39
+ def pct_failed(self) -> float:
40
+ return (self.failed / self.total * 100.0) if (self.total != 0) else 0.0
41
+
42
+ @property
43
+ def pct_errored(self) -> float:
44
+ return (self.errored / self.total * 100.0) if (self.total != 0) else 0.0
45
+
46
+ @property
47
+ def pct_skipped(self) -> float:
48
+ return (self.skipped / self.total * 100.0) if (self.total != 0) else 0.0
49
+
50
+ @property
51
+ def pct_justified(self) -> float:
52
+ return (self.justified / self.total * 100.0) if (self.total != 0) else 0.0
53
+
54
+ @property
55
+ def pct_expected_failures(self) -> float:
56
+ return (self.expected_failures / self.total * 100.0) if (self.total != 0) else 0.0
57
+
58
+ @property
59
+ def pct_unexpected_successes(self) -> float:
60
+ return (self.unexpected_successes / self.total * 100.0) if (self.total != 0) else 0.0
61
+
62
+ def __add__(self, result: Result):
63
+ result = str(result).upper().replace(' ', '-').replace('_', '-').strip()
64
+
65
+ if result == 'PASSED':
66
+ self.passed += 1
67
+ elif result == 'ERRORED':
68
+ self.errored += 1
69
+ elif result == 'FAILED':
70
+ self.failed += 1
71
+ elif result == 'JUSTIFIED':
72
+ self.justified += 1
73
+ elif result == 'SKIPPED':
74
+ self.skipped += 1
75
+ elif result == 'EXPECTED-FAILURE':
76
+ self.expected_failures += 1
77
+ elif result == 'UNEXPECTED-SUCCESS':
78
+ self.unexpected_successes += 1
79
+ elif result == 'EMPTY':
80
+ self.not_executed += 1
81
+ else:
82
+ raise ValueError(f'Unknown result "{result}".')
83
+
84
+ return self
85
+
86
+
87
+ class Summary:
88
+ def __init__(self):
89
+ self.results = ResultsSummary(0, 0, 0, 0, 0, 0, 0, 0)
90
+ self.execution = {}
91
+ self.levels = {}
92
+
93
+ @property
94
+ def result(self) -> Result:
95
+ if self.results.errored > 0:
96
+ # if there is at least one error -> error
97
+ return 'ERRORED'
98
+ elif (self.results.failed > 0) or (self.results.unexpected_successes > 0):
99
+ # if there is at least one fail or unexpected success and no error -> fail
100
+ return 'FAILED'
101
+ elif (self.results.passed > 0) or (self.results.justified > 0) or (self.results.expected_failures > 0):
102
+ # otherwise if there are passed, justified or expected failures -> passed
103
+ return 'PASSED'
104
+ elif self.results.skipped > 0:
105
+ return 'SKIPPED'
106
+ else:
107
+ return 'EMPTY'
brunhilda/exception.py ADDED
@@ -0,0 +1,9 @@
1
+ class PackageException(Exception):
2
+ ERROR_CODE = -1
3
+
4
+ def __init__(self, message: str = ""):
5
+ self.message = message
6
+
7
+
8
+ class ArgumentException(PackageException):
9
+ ERROR_CODE = 1
@@ -0,0 +1,187 @@
1
+ from copy import deepcopy
2
+ from typing import Dict, Optional, OrderedDict, List, Set
3
+
4
+ from .html_output import HtmlOutput
5
+ from .data import Summary
6
+
7
+ class HtmlFeatureSummaryOutput(HtmlOutput):
8
+ """
9
+ """
10
+
11
+ def _flatten_tests(self, testsuite: Dict) -> List:
12
+ """
13
+ Converts test-suite into list of tests.
14
+
15
+ If there are sub-tests in the test, it puts individual sub-tests to the list.
16
+ :param testsuite: testsuite
17
+ :return: list of tests
18
+ """
19
+ flat_tests = []
20
+
21
+ for test_run in testsuite.values():
22
+ for test in test_run:
23
+ test_ = deepcopy(test)
24
+ test_['parameters'] = {}
25
+ test_['subtest_id'] = ''
26
+ test_['subtests'] = []
27
+
28
+ if 'subtests' in test and test['subtests']:
29
+ for subtest in test['subtests']:
30
+ subtest_ = deepcopy(test_)
31
+
32
+ if ('parameters' in subtest) and subtest['parameters']:
33
+ parameters = subtest['parameters']
34
+ subtest_['parameters'] = parameters
35
+ subtest_['subtest_id'] = ','.join(f'{parameter}:{value}' for parameter, value in parameters.items())
36
+
37
+ subtest_['result'] = subtest['result']
38
+ subtest_['subtests'] = [] # clear the subtests, now the test is the subtest actually
39
+ flat_tests.append(subtest_)
40
+ else:
41
+ flat_tests.append(test_)
42
+
43
+ return flat_tests
44
+
45
+ def _covers_param(self, test: Dict, parameter: str, values: List[str]) -> bool:
46
+ """
47
+ Test if the test parameters contains parameter with the given value or value wildcard matches the value in the test.
48
+
49
+ :param test: test
50
+ :param parameter: name of the parameter
51
+ :param values: list of parameter values
52
+ :return: Test result - True or False
53
+ """
54
+ if (parameter in test['parameters']):
55
+ if str(test['parameters'][parameter]) in values:
56
+ return True
57
+ elif any(value.endswith('*') and test['parameters'][parameter].startswith(value[:-1]) for value in values):
58
+ return True
59
+
60
+ return False
61
+
62
+ def _result(self, results: Set[str]) -> str:
63
+ if not results:
64
+ res = 'EMPTY'
65
+ elif any(r == 'ERRORED' for r in results):
66
+ res = 'ERRORED'
67
+ elif any(r == 'UNEXPECTED-SUCCESS' for r in results):
68
+ res = 'UNEXPECTED-SUCCESS'
69
+ elif any(r == 'FAILED' for r in results):
70
+ res = 'FAILED'
71
+ elif all(r == 'EXPECTED-FAILURE' for r in results):
72
+ res = 'EXPECTED-FAILURE'
73
+ elif all(r == 'SKIPPED' for r in results):
74
+ res = 'SKIPPED'
75
+ elif any(r == 'JUSTIFIED' for r in results):
76
+ res = 'JUSTIFIED'
77
+ else:
78
+ res = 'PASSED'
79
+
80
+ return res
81
+
82
+ def print(self, name: str,
83
+ features: Dict,
84
+ testsuite: Dict,
85
+ test_plan_paths: Optional[Dict[str, str]] = None) -> str:
86
+ """
87
+ Prints summary of features to HTML document.
88
+
89
+ :param name: name of the generated report
90
+ :param features: collected features
91
+ :param testsuite: suite of the executed tests
92
+ :param test_plan_path: path to the test plans
93
+ :return: HTML string
94
+ :rtype: str
95
+ """
96
+ entries = OrderedDict()
97
+ all_tests = self._flatten_tests(testsuite)
98
+ unlinked_tests = deepcopy(all_tests)
99
+ summary = Summary()
100
+
101
+ for group in features:
102
+ entries[group] = []
103
+
104
+ for feature_group in features[group]:
105
+ for feature_name in feature_group:
106
+ requirement_tests = {}
107
+ order = feature_group[feature_name]['order']
108
+ links = feature_group[feature_name]['link']
109
+ entry = {'group': group, 'name': feature_name, 'order': order, 'result': '', 'links': {}}
110
+ feature_results = set()
111
+
112
+ for link in links:
113
+ params = links[link]
114
+ entry['links'][link] = {}
115
+
116
+ for index, test in enumerate(all_tests):
117
+ test_case_id = test['test_id'] + test['subtest_id']
118
+
119
+ for requirement in test['requirements']:
120
+ if requirement not in requirement_tests:
121
+ requirement_tests[requirement] = []
122
+
123
+ if requirement.startswith(link) and (test_case_id not in requirement_tests[requirement]):
124
+ if params:
125
+ for parameter in params:
126
+ test_group = test['test_id'] + f' {parameter}:{params[parameter]}'
127
+
128
+ if test_group not in entry['links'][link]:
129
+ entry['links'][link][test_group] = {
130
+ 'tests': [],
131
+ 'level': test['level'],
132
+ 'results': set(),
133
+ }
134
+
135
+ if self._covers_param(test, parameter, params[parameter]):
136
+ test_case = deepcopy(test)
137
+ requirement_tests[requirement].append(test_case_id)
138
+ if test_case not in entry['links'][link][test_group]['tests']:
139
+ entry['links'][link][test_group]['tests'].append(test_case)
140
+ entry['links'][link][test_group]['results'].add(test_case['result'])
141
+ feature_results.add(test_case['result'])
142
+ unlinked_tests[index] = None
143
+ else:
144
+ test_group = test['test_id']
145
+
146
+ if test_group not in entry['links'][link]:
147
+ entry['links'][link][test_group] = {
148
+ 'tests': [],
149
+ 'level': test['level'],
150
+ 'results': set(),
151
+ }
152
+
153
+ test_case = deepcopy(test)
154
+ requirement_tests[requirement].append(test_case_id)
155
+ if test_case not in entry['links'][link][test_group]['tests']:
156
+ entry['links'][link][test_group]['tests'].append(test_case)
157
+ entry['links'][link][test_group]['results'].add(test_case['result'])
158
+ feature_results.add(test_case['result'])
159
+ unlinked_tests[index] = None
160
+
161
+
162
+
163
+ entry['result'] = self._result(feature_results).lower()
164
+ summary.results += self._result(feature_results)
165
+ entries[group].append(entry)
166
+
167
+ # remove empty test groups
168
+ for group in entries:
169
+ for entry in entries[group]:
170
+ for link in entry['links']:
171
+ for test_group in list(entry['links'][link].keys()):
172
+ if not entry['links'][link][test_group]['tests'] and len(entry['links'][link]) > 1:
173
+ del entry['links'][link][test_group]
174
+ else:
175
+ entry['links'][link][test_group]['result'] = self._result(entry['links'][link][test_group]['results']).lower()
176
+
177
+ # add not linked tests refereeing to empty feature
178
+ unlinked_tests = list(filter(lambda test: test is not None, unlinked_tests))
179
+ # entries['Not linked'] = [{'group': '', 'name': '', 'order': '', 'links': {'': unlinked_tests}}]
180
+
181
+ template = self.load_template('summary-features.html.jinja2')
182
+ rendered = template.render(name=name,
183
+ preamble=self._include_preamble,
184
+ features=entries,
185
+ summary=summary,
186
+ test_plan_paths=test_plan_paths)
187
+ return rendered
@@ -0,0 +1,19 @@
1
+ from typing import List, Union, Tuple
2
+ from .html_output import HtmlOutput
3
+
4
+ class HtmlIndexOutput(HtmlOutput):
5
+ """
6
+ """
7
+
8
+ def print(self, name: str, outputs: List[Tuple], preamble: Union[List[str], str, None] = None) -> str:
9
+ """
10
+ Prints index with all outputs
11
+
12
+ :param name: name of the generated report
13
+ :param outputs: list of the generated outputs in a format [(path, title), ...]
14
+ :param preamble: path or multiple paths to the HTML document to be used as a document preamble
15
+ :return: HTML string
16
+ """
17
+ template = self.load_template('index.html.jinja2')
18
+ rendered = template.render(name=name, outputs=outputs, preamble=self._include_preamble)
19
+ return rendered
@@ -0,0 +1,22 @@
1
+ from typing import Dict
2
+ from .html_output import HtmlOutput
3
+
4
+
5
+ class HtmlIssueListOutput(HtmlOutput):
6
+ def print(self, name: str, issues: Dict, user_data: Dict[str, str] = None):
7
+ """
8
+ Prints issue list
9
+
10
+ :param name: name of the generated report file
11
+ :param issues: BRunhilda issues
12
+ :param user_data: additional data passed by a user
13
+ :return: HTML string
14
+ :rtype: str
15
+ """
16
+ template = self.load_template('issue-list.html.jinja2')
17
+ rendered = template.render(name=name,
18
+ preamble=self._include_preamble,
19
+ reports=issues,
20
+ user_data=user_data,
21
+ document_path=self.path)
22
+ return rendered
@@ -0,0 +1,119 @@
1
+ import colorama
2
+ from typing import Union, Sequence
3
+ from docutils.core import publish_parts
4
+
5
+ from .output import Output
6
+
7
+ class HtmlOutput(Output):
8
+ def __init__(self, preamble: Union[Sequence[str], str, None] = None, path='output.html'):
9
+ """
10
+ :param preamble: path or multiple paths to file(s) to include as a preamble
11
+ :param path: output path where to create the HTML output
12
+ """
13
+ self._include_preamble = ''
14
+ self.path = path
15
+
16
+ if preamble:
17
+ if not isinstance(preamble, (list, tuple, set)):
18
+ preamble = [preamble]
19
+
20
+ for p in preamble:
21
+ with open(p, encoding='utf-8') as f:
22
+ self._include_preamble += f.read()
23
+
24
+ def _format_doc(self, description):
25
+ """
26
+ This method formats python docstring to HTML.
27
+ :param str description: python docstring of the method or class
28
+ :return: HTML string representation.
29
+ """
30
+ if not isinstance(description, str):
31
+ return ""
32
+ else:
33
+ description = description.strip('\n') # description without first and last new line
34
+ lines = description.split('\n')
35
+ indent = len(lines[0]) - len(lines[0].lstrip()) # number of spaces from the left
36
+ lines = [line.rstrip() for line in lines] # cut out trailing spaces
37
+ lines = [line[indent:] for line in lines] # cut out leading spaces
38
+ description = '\n'.join(lines) # join to string again
39
+ description = description.replace("–", "-") # TODO - use &ndash to be correct
40
+ description = description.replace(" *.", " \*.")
41
+ return publish_parts(description, writer_name='html')['html_body'] # convert from RST to HTML
42
+
43
+ def _format_logging(self, text):
44
+ """
45
+ Wraps output of the python logging into HTML spans with the severity classes.
46
+ """
47
+ formatting = {
48
+ "DEBUG": '<span class="log log--debug">',
49
+ "INFO": '<span class="log log--info">',
50
+ "WARNING": '<span class="log log--warning">',
51
+ "ERROR": '<span class="log log--error">',
52
+ "CRITICAL": '<span class="log log--critical">',
53
+ }
54
+
55
+ lines = text.split('\n')
56
+ for i in range(len(lines)):
57
+ for f in formatting:
58
+ # Currently only by te occurrence of the keyword in the string, is there a better way?
59
+ if f in lines[i]:
60
+ lines[i] = f'{formatting[f]}{lines[i]}</span>'
61
+ return '\n'.join(lines)
62
+
63
+ def _format_terminal(self, text):
64
+ """
65
+ Converts colorama terminal output into HTML string with the classes.
66
+ """
67
+ formatting = {
68
+ colorama.Fore.BLACK: '<span class="fore fore--black">',
69
+ colorama.Fore.RED: '<span class="fore fore--red">',
70
+ colorama.Fore.GREEN: '<span class="fore fore--green">',
71
+ colorama.Fore.YELLOW: '<span class="fore fore--yellow">',
72
+ colorama.Fore.BLUE: '<span class="fore fore--blue">',
73
+ colorama.Fore.MAGENTA: '<span class="fore fore--magenta">',
74
+ colorama.Fore.CYAN: '<span class="fore fore--cyan">',
75
+ colorama.Fore.WHITE: '<span class="fore fore--white">',
76
+ colorama.Back.BLACK: '<span class="back back--black">',
77
+ colorama.Back.RED: '<span class="back back--red">',
78
+ colorama.Back.GREEN: '<span class="back back--green">',
79
+ colorama.Back.YELLOW: '<span class="back back--yellow">',
80
+ colorama.Back.BLUE: '<span class="back back--blue">',
81
+ colorama.Back.MAGENTA: '<span class="back back--magenta">',
82
+ colorama.Back.CYAN: '<span class="back back--cyan">',
83
+ colorama.Back.WHITE: '<span class="back back--white">',
84
+ colorama.Style.DIM: '<span class="style style--dim">',
85
+ colorama.Style.BRIGHT: '<span class="style style--bright">',
86
+ colorama.Style.NORMAL: '<span class="style style--normal">',
87
+ }
88
+
89
+ CSI = '\033[' # this is start of the ASCII escape sequences
90
+ start = 0
91
+ opened = [] # list of opened tags
92
+
93
+ while start >= 0:
94
+ pos = text.find(CSI, start) # nex loc of the CSI
95
+ end = text.find('m', pos) + 1 # CSI ends with 'm'
96
+ esc = text[pos:end] # whole escape sequence, e.g. '\033[30m' for BACK
97
+
98
+ if esc in formatting:
99
+ opened.append(formatting[esc])
100
+ text = text.replace(esc, formatting[esc])
101
+ elif esc in (colorama.Style.RESET_ALL, colorama.Fore.RESET, colorama.Back.RESET):
102
+ n = len(opened) # number of currently opened spans
103
+
104
+ # check which spans will be reopened because they are not reset
105
+ if esc == colorama.Style.RESET_ALL:
106
+ opened = []
107
+ elif esc == colorama.Fore.RESET:
108
+ opened = [op for op in opened if "fore" not in op]
109
+ elif esc == colorama.Back.RESET:
110
+ opened = [op for op in opened if "back" not in op]
111
+
112
+ # close all open spans and reopen not reset spans
113
+ text = text.replace(esc, ''.join(['</span>'] * n + opened))
114
+ else:
115
+ # remove unknown formating
116
+ text = text.replace(esc, '')
117
+
118
+ start = pos
119
+ return text
@@ -0,0 +1,74 @@
1
+ from copy import deepcopy
2
+ from typing import Dict, List, Optional
3
+
4
+ from .data import Summary
5
+ from .html_output import HtmlOutput
6
+
7
+
8
+ class HtmlReqSummaryOutput(HtmlOutput):
9
+ """
10
+ """
11
+
12
+ def print(self, name: str,
13
+ testsuite: Dict,
14
+ requirements: List[str],
15
+ summary: Summary,
16
+ issue_list_path: Optional[str] = None,
17
+ test_plan_paths: Optional[Dict[str, str]] = None,
18
+ user_data: Dict[str, str] = None) -> str:
19
+ """
20
+ Prints requirements summary to HTML document.
21
+
22
+ :param name: name of the generated report
23
+ :param testsuite: suite of the executed tests
24
+ :param requirements: list of all requirements
25
+ :param summary: summary for the test suite
26
+ :param issue_list_path: path to the issue list
27
+ :param test_plan_path: path to the issue list
28
+ :param user_data: additional data passed by a user
29
+ :return: HTML string
30
+ :rtype: str
31
+ """
32
+ entries = []
33
+ count = 0
34
+
35
+ for requirement in requirements:
36
+ levels = {}
37
+ passed = 0
38
+ count = 0
39
+
40
+ for test_run in testsuite.values():
41
+ for test in test_run:
42
+ if ('requirements' in test) and (requirement in test['requirements']):
43
+ level = test['level']
44
+ result = test['result'].upper()
45
+ count += 1
46
+
47
+ if result in ('PASSED', 'JUSTIFIED'):
48
+ passed += 1
49
+
50
+ if level not in levels:
51
+ levels[level] = []
52
+
53
+ levels[level].append(deepcopy(test))
54
+
55
+ for level in levels:
56
+ for test in levels[level]:
57
+ test['coverage_ratio'] = (100 / count) if (count > 0) else 0
58
+
59
+ entries.append({
60
+ 'name': requirement,
61
+ 'levels': levels,
62
+ 'count': count,
63
+ 'pass_ratio': (passed / count) * 100 if (count != 0) else 0,
64
+ })
65
+
66
+ template = self.load_template('summary-req.html.jinja2')
67
+ rendered = template.render(name=name,
68
+ preamble=self._include_preamble,
69
+ summary=summary,
70
+ requirements=entries,
71
+ issue_list_path=issue_list_path,
72
+ test_plan_paths=test_plan_paths,
73
+ user_data=user_data)
74
+ return rendered