Skip to content

Commit 14c8742

Browse files
committed
totalstatistics: simplify after criticality removal
1 parent fe1d899 commit 14c8742

File tree

15 files changed

+61
-44
lines changed

15 files changed

+61
-44
lines changed

atest/robot/rebot/filter_by_names.robot

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ Run and check Tests
113113
Run Rebot ${params} ${INPUT FILE}
114114
Stderr Should Be Empty
115115
Should Contain Tests ${SUITE} @{tests}
116-
Should Be True ${SUITE.statistics.all.passed} == len(@{tests})
116+
Should Be True ${SUITE.statistics.passed} == len(@{tests})
117117
Check Stats
118118

119119
Check Stats
120-
Should Be True ${SUITE.statistics.all.failed} == 0
120+
Should Be True ${SUITE.statistics.failed} == 0
121121
Should Be Equal ${SUITE.starttime} ${NONE}
122122
Should Be Equal ${SUITE.endtime} ${NONE}
123123
Elapsed Time Should Be Valid ${SUITE.elapsedtime}
@@ -134,7 +134,7 @@ Run And Check Suites and Tests
134134
Run Suites ${params}
135135
Should Contain Suites ${SUITE.suites[0]} ${subsuite}
136136
Should Contain Tests ${SUITE} @{tests}
137-
Should Be True ${SUITE.statistics.all.passed} == len(@{tests})
137+
Should Be True ${SUITE.statistics.passed} == len(@{tests})
138138
Check Stats
139139

140140
Run Suites

atest/robot/standard_libraries/builtin/run_keyword_based_on_suite_stats.robot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Resource atest_resource.robot
55
*** Test Case ***
66
Run Keyword If All Tests Passed
77
${suite} = Get Test Suite Run Keyword If All Tests Passed When All Pass
8-
Should Be Equal As Integers ${suite.statistics.all.failed} 0
8+
Should Be Equal As Integers ${suite.statistics.failed} 0
99
Should Be Equal ${suite.teardown.kws[0].name} My Teardown
1010
Check Log Message ${suite.teardown.kws[0].kws[0].msgs[0]} Suite teardown message
1111

@@ -17,7 +17,7 @@ Run Keyword If All tests Passed Is not Executed When Any Test Fails
1717

1818
Run Keyword If Any Tests Failed
1919
${suite} = Get Test Suite Run Keyword If Any Tests Failed When Test Fails
20-
Should Be Equal As Integers ${suite.statistics.all.failed} 1
20+
Should Be Equal As Integers ${suite.statistics.failed} 1
2121
Should Be Equal ${suite.teardown.kws[0].name} My Teardown
2222
Check Log Message ${suite.teardown.kws[0].kws[0].msgs[0]} Suite teardown message
2323

atest/robot/tags/include_and_exclude_with_rebot.robot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ Run And Check Include And Exclude
154154
Run Rebot ${params} ${INPUT FILES}
155155
Stderr Should Be Empty
156156
Should Contain Tests ${SUITE} @{tests}
157-
Should Be True $SUITE.statistics.all.passed == len($tests)
158-
Should Be True $SUITE.statistics.all.failed == 0
157+
Should Be True $SUITE.statistics.passed == len($tests)
158+
Should Be True $SUITE.statistics.failed == 0
159159
Should Be Equal ${SUITE.starttime} ${{None if $params else $ORIG_START}}
160160
Should Be Equal ${SUITE.endtime} ${{None if $params else $ORIG_END}}
161161
Elapsed Time Should Be Valid ${SUITE.elapsedtime}

src/robot/libraries/BuiltIn.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,7 +2224,7 @@ def run_keyword_if_all_tests_passed(self, name, *args):
22242224
documentation for more details.
22252225
"""
22262226
suite = self._get_suite_in_teardown('Run Keyword If All Tests Passed')
2227-
if suite.statistics.all.failed == 0:
2227+
if suite.statistics.failed == 0:
22282228
return self.run_keyword(name, *args)
22292229

22302230
@run_keyword_variant(resolve=1)
@@ -2238,7 +2238,7 @@ def run_keyword_if_any_tests_failed(self, name, *args):
22382238
documentation for more details.
22392239
"""
22402240
suite = self._get_suite_in_teardown('Run Keyword If Any Tests Failed')
2241-
if suite.statistics.all.failed > 0:
2241+
if suite.statistics.failed > 0:
22422242
return self.run_keyword(name, *args)
22432243

22442244
def _get_suite_in_teardown(self, kwname):

src/robot/model/totalstatistics.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,33 @@ class TotalStatistics(object):
2424
def __init__(self, rpa=False):
2525
test_or_task = 'Tests' if not rpa else 'Tasks'
2626
#: Instance of :class:`~robot.model.stats.TotalStat` for all the tests.
27-
self.all = TotalStat('All ' + test_or_task)
27+
self._stat = TotalStat('All ' + test_or_task)
2828
self._rpa = rpa
2929

3030
def visit(self, visitor):
31-
visitor.visit_total_statistics(self)
31+
visitor.visit_total_statistics(self._stat)
3232

3333
def __iter__(self):
34-
yield self.all
34+
yield self._stat
35+
36+
@property
37+
def total(self):
38+
return self._stat.total
39+
40+
@property
41+
def passed(self):
42+
return self._stat.passed
43+
44+
@property
45+
def skipped(self):
46+
return self._stat.skipped
47+
48+
@property
49+
def failed(self):
50+
return self._stat.failed
51+
52+
def add_test(self, test):
53+
self._stat.add_test(test)
3554

3655
@property
3756
def message(self):
@@ -42,16 +61,16 @@ def message(self):
4261
"""
4362
# TODO: should this message be highlighted in console
4463
test_or_task = 'test' if not self._rpa else 'task'
45-
total, end, passed, failed, skipped = self._get_counts(self.all)
64+
total, end, passed, failed, skipped = self._get_counts()
4665
template = '%d %s%s, %d passed, %d failed'
4766
if skipped:
4867
return ((template + ', %d skipped')
4968
% (total, test_or_task, end, passed, failed, skipped))
5069
return template % (total, test_or_task, end, passed, failed)
5170

52-
def _get_counts(self, stat):
53-
ending = 's' if stat.total != 1 else ''
54-
return stat.total, ending, stat.passed, stat.failed, stat.skipped
71+
def _get_counts(self):
72+
ending = 's' if self.total != 1 else ''
73+
return self.total, ending, self.passed, self.failed, self.skipped
5574

5675

5776
class TotalStatisticsBuilder(SuiteVisitor):
@@ -62,7 +81,7 @@ def __init__(self, suite=None, rpa=False):
6281
suite.visit(self)
6382

6483
def add_test(self, test):
65-
self.stats.all.add_test(test)
84+
self.stats.add_test(test)
6685

6786
def visit_test(self, test):
6887
self.add_test(test)

src/robot/output/console/dotted.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ def report(self, suite):
7373
suite.visit(self)
7474
stats = suite.statistics
7575
self._stream.write("%s\nRun suite '%s' with %d %s%s in %s.\n\n"
76-
% ('=' * self._width, suite.name, stats.all.total,
76+
% ('=' * self._width, suite.name, stats.total,
7777
'test' if not suite.rpa else 'task',
78-
plural_or_not(stats.all.total),
78+
plural_or_not(stats.total),
7979
secs_to_timestr(suite.elapsedtime/1000.0)))
8080
self._stream.highlight(suite.status + 'ED', suite.status)
8181
self._stream.write('\n%s\n' % stats.message)

src/robot/reporting/jsmodelbuilders.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,7 @@ def _yield_metadata(self, suite):
9797

9898
def _get_statistics(self, suite):
9999
stats = suite.statistics # Access property only once
100-
return (stats.all.total,
101-
stats.all.passed,
102-
stats.all.failed,
103-
stats.all.skipped)
100+
return (stats.total, stats.passed, stats.failed, stats.skipped)
104101

105102

106103
class TestBuilder(_Builder):

src/robot/reporting/xunitwriter.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ def start_suite(self, suite):
5555
self._writer.start('testsuite', attrs)
5656

5757
def _get_stats(self, statistics):
58-
# TODO cleanup
59-
failures = statistics.all.failed
60-
skipped = statistics.all.skipped
61-
return str(statistics.all.total), str(failures), str(skipped)
58+
return (
59+
str(statistics.total),
60+
str(statistics.failed),
61+
str(statistics.skipped)
62+
)
6263

6364
def end_suite(self, suite):
6465
if suite is self._root_suite:

src/robot/result/executionresult.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ def statistics(self):
6363
result.configure(stat_config={'suite_stat_level': 2,
6464
'tag_stat_combine': 'tagANDanother'})
6565
stats = result.statistics
66-
print stats.total.critical.failed
67-
print stats.total.critical.passed
66+
print stats.total.failed
67+
print stats.total.passed
6868
print stats.tags.combined[0].total
6969
"""
7070
return Statistics(self.suite, rpa=self.rpa, **self._stat_config)
@@ -77,7 +77,7 @@ def return_code(self):
7777
but can be :func:`configured <configure>` to always return 0.
7878
"""
7979
if self._status_rc:
80-
return min(self.suite.statistics.all.failed, 250)
80+
return min(self.suite.statistics.failed, 250)
8181
return 0
8282

8383
def configure(self, status_rc=True, suite_config=None, stat_config=None):

src/robot/result/keywordremover.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def visit_keyword(self, keyword):
6363
class PassedKeywordRemover(_KeywordRemover):
6464

6565
def start_suite(self, suite):
66-
if not suite.statistics.all.failed:
66+
if not suite.statistics.failed:
6767
for keyword in suite.keywords:
6868
if not self._warning_or_error(keyword):
6969
self._clear_content(keyword)

0 commit comments

Comments
 (0)