Revision: cbcbe81388df
Author: Pekka Klärck
Date: Thu Nov 17 13:39:51 2011
Log: Separated building TagStatistics to separate TagStatisticsBuilder
http://code.google.com/p/robotframework/source/detail?r=cbcbe81388df
Modified:
/src/robot/model/statistics.py
/src/robot/model/tagstatistics.py
/utest/model/test_statistics.py
=======================================
--- /src/robot/model/statistics.py Thu Nov 17 12:53:04 2011
+++ /src/robot/model/statistics.py Thu Nov 17 13:39:51 2011
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from .tagstatistics import TagStatistics
+from .tagstatistics import TagStatisticsBuilder
from .suitestatistics import SuiteStatisticsBuilder
from .totalstatistics import TotalStatistics
from .visitor import SuiteVisitor
@@ -24,11 +24,12 @@
tag_stat_exclude=None, tag_stat_combine=None,
tag_doc=None,
tag_stat_link=None):
suite_builder = SuiteStatisticsBuilder(suite_stat_level)
- self.tags = TagStatistics(suite.criticality, tag_stat_include,
- tag_stat_exclude, tag_stat_combine,
- tag_doc, tag_stat_link)
- suite.visit(StatisticsBuilder(suite_builder, self.tags))
+ tag_builder = TagStatisticsBuilder(suite.criticality,
tag_stat_include,
+ tag_stat_exclude,
tag_stat_combine,
+ tag_doc, tag_stat_link)
+ suite.visit(StatisticsBuilder(suite_builder, tag_builder))
self.suite = suite_builder.root
+ self.tags = tag_builder.stats
self.total = TotalStatistics(self.suite)
def visit(self, visitor):
=======================================
--- /src/robot/model/tagstatistics.py Tue Nov 15 14:04:09 2011
+++ /src/robot/model/tagstatistics.py Thu Nov 17 13:39:51 2011
@@ -21,15 +21,29 @@
class TagStatistics(object):
+ def __init__(self, combined_stats):
+ self.tags = utils.NormalizedDict(ignore=['_'])
+ self.combined = combined_stats
+
+ def visit(self, visitor):
+ visitor.visit_tag_statistics(self)
+
+ def __iter__(self):
+ return iter(sorted(self.tags.values() + self.combined))
+
+ def __len__(self):
+ return len(self.tags) + len(self.combined)
+
+
+class TagStatisticsBuilder(object):
+
def __init__(self, criticality, include=None, exclude=None,
combine=None,
docs=None, links=None):
# TODO: Check argument names
- self.tags = utils.NormalizedDict(ignore=['_'])
self._include = TagPatterns(include)
self._exclude = TagPatterns(exclude)
self._info = TagStatInfo(criticality, docs, links)
- self.combined = [self._info.get_combined_stat(pattern, name)
- for pattern, name in combine or []]
+ self.stats = TagStatistics(self._info.get_combined_stats(combine))
def add_test(self, test):
self._add_tags_to_statistics(test)
@@ -38,9 +52,9 @@
def _add_tags_to_statistics(self, test):
for tag in test.tags:
if self._is_included(tag):
- if tag not in self.tags:
- self.tags[tag] = self._info.get_stat(tag)
- self.tags[tag].add_test(test)
+ if tag not in self.stats.tags:
+ self.stats.tags[tag] = self._info.get_stat(tag)
+ self.stats.tags[tag].add_test(test)
def _is_included(self, tag):
if self._include and not self._include.match(tag):
@@ -48,19 +62,10 @@
return not self._exclude.match(tag)
def _add_to_combined_statistics(self, test):
- for comb in self.combined:
+ for comb in self.stats.combined:
if comb.match(test.tags):
comb.add_test(test)
- def visit(self, visitor):
- visitor.visit_tag_statistics(self)
-
- def __iter__(self):
- return iter(sorted(self.tags.values() + self.combined))
-
- def __len__(self):
- return len(self.tags) + len(self.combined)
-
class TagStatInfo(object):
@@ -74,6 +79,9 @@
self._criticality.tag_is_critical(tag),
self._criticality.tag_is_non_critical(tag))
+ def get_combined_stats(self, combined=None):
+ return [self.get_combined_stat(*comb) for comb in combined or []]
+
def get_combined_stat(self, pattern, name=None):
name = name or pattern
return CombinedTagStat(pattern, name, self._get_doc(name),
=======================================
--- /utest/model/test_statistics.py Thu Nov 17 00:50:59 2011
+++ /utest/model/test_statistics.py Thu Nov 17 13:39:51 2011
@@ -1,9 +1,9 @@
import unittest
from robot.model import Criticality
-from robot.utils.asserts import assert_equals, assert_none, fail
+from robot.utils.asserts import assert_equals, assert_none
from robot.model.statistics import Statistics
-from robot.model.tagstatistics import TagStatistics, TagStatLink,
TagStatInfo
+from robot.model.tagstatistics import TagStatisticsBuilder, TagStatLink
from robot.result import TestSuite, TestCase
from robot import utils
@@ -130,19 +130,19 @@
def test_include(self):
for incl, tags in self._incl_excl_data:
- stats = TagStatistics(Criticality(), incl, [])
- stats.add_test(TestCase(status='PASS', tags=tags))
+ builder = TagStatisticsBuilder(Criticality(), incl, [])
+ builder.add_test(TestCase(status='PASS', tags=tags))
expected = [tag for tag in tags
if incl == [] or any(utils.matches(tag, i) for i
in incl)]
- assert_equals([s.name for s in stats], sorted(expected))
+ assert_equals([s.name for s in builder.stats],
sorted(expected))
def test_exclude(self):
for excl, tags in self._incl_excl_data:
- stats = TagStatistics(Criticality(), [], excl)
- stats.add_test(TestCase(status='PASS', tags=tags))
+ builder = TagStatisticsBuilder(Criticality(), [], excl)
+ builder.add_test(TestCase(status='PASS', tags=tags))
expected = [tag for tag in tags
if not any(utils.matches(tag, e) for e in excl)]
- assert_equals([s.name for s in stats], sorted(expected))
+ assert_equals([s.name for s in builder.stats],
sorted(expected))
def test_include_and_exclude(self):
for incl, excl, tags, exp in [
@@ -154,25 +154,25 @@
(['t1','t2','t3','not'], ['t2','t0'],
['t0','t1','t2','t3','x'], ['t1','t3'] )
]:
- stats = TagStatistics(Criticality(), incl, excl)
- stats.add_test(TestCase(status='PASS', tags=tags))
- assert_equals([s.name for s in stats], exp),
+ builder = TagStatisticsBuilder(Criticality(), incl, excl)
+ builder.add_test(TestCase(status='PASS', tags=tags))
+ assert_equals([s.name for s in builder.stats], exp),
def test_len(self):
- stats = TagStatistics(Criticality())
- assert_equals(len(stats), 0)
- stats.add_test(TestCase())
- assert_equals(len(stats), 0)
- stats.add_test(TestCase(tags=['a']))
- assert_equals(len(stats), 1)
- stats.add_test(TestCase(tags=['A', 'B']))
- assert_equals(len(stats), 2)
+ builder = TagStatisticsBuilder(Criticality())
+ assert_equals(len(builder.stats), 0)
+ builder.add_test(TestCase())
+ assert_equals(len(builder.stats), 0)
+ builder.add_test(TestCase(tags=['a']))
+ assert_equals(len(builder.stats), 1)
+ builder.add_test(TestCase(tags=['A', 'B']))
+ assert_equals(len(builder.stats), 2)
def test_len_with_combine(self):
- stats = TagStatistics(Criticality(), combine=[('x*', 'title')])
- assert_equals(len(stats), 1)
- stats.add_test(TestCase(tags=['xxx', 'yyy']))
- assert_equals(len(stats), 3)
+ builder = TagStatisticsBuilder(Criticality(),
combine=[('x*', 'title')])
+ assert_equals(len(builder.stats), 1)
+ builder.add_test(TestCase(tags=['xxx', 'yyy']))
+ assert_equals(len(builder.stats), 3)
def test_combine_with_name(self):
for comb_tags, expected_name in [
@@ -183,10 +183,10 @@
([('3*', '')], '3*' ),
([('4NOT5', 'Some new name')], 'Some new name')
]:
- stats = TagStatistics(Criticality(), combine=comb_tags)
- assert_equals(bool(stats), expected_name != '')
+ builder = TagStatisticsBuilder(Criticality(),
combine=comb_tags)
+ assert_equals(bool(builder.stats), expected_name != '')
if expected_name:
- assert_equals([s.name for s in stats], [expected_name])
+ assert_equals([s.name for s in builder.stats],
[expected_name])
def test_is_combined_with_and_statements(self):
for comb_tags, test_tags, expected_count in [
@@ -203,9 +203,9 @@
self._verify_combined_statistics(comb_tags, test_tags,
expected_count)
def _verify_combined_statistics(self, comb_tags, test_tags,
expected_count):
- stats = TagStatistics(Criticality(), combine=[(comb_tags, 'name')])
- stats._add_to_combined_statistics(TestCase(tags=test_tags))
- assert_equals([s.total for s in stats if s.combined],
[expected_count])
+ builder = TagStatisticsBuilder(Criticality(),
combine=[(comb_tags, 'name')])
+ builder._add_to_combined_statistics(TestCase(tags=test_tags))
+ assert_equals([s.total for s in builder.stats if s.combined],
[expected_count])
def test_is_combined_with_not_statements(self):
for comb_tags, test_tags, expected_count in [
@@ -231,9 +231,9 @@
self._verify_combined_statistics(comb_tags, test_tags,
expected_count)
def test_combine_with_same_name_as_existing_tag(self):
- stats = TagStatistics(Criticality(), combine=[('x*', 'name')])
- stats.add_test(TestCase(tags=['name', 'another']))
- assert_equals([(s.name, s.combined) for s in stats],
+ builder = TagStatisticsBuilder(Criticality(),
combine=[('x*', 'name')])
+ builder.add_test(TestCase(tags=['name', 'another']))
+ assert_equals([(s.name, s.combined) for s in builder.stats],
[('name', 'x*'), ('another', ''), ('name', '')])
def test_combine(self):
@@ -251,14 +251,14 @@
(['nonex'], [['t1'],['t1,t2'],[]], [])
]:
# 1) Create tag stats
- tagstats = TagStatistics(Criticality(crit_tags),
- combine=[(t, '') for t in comb_tags])
+ builder = TagStatisticsBuilder(Criticality(crit_tags),
+ combine=[(t, '') for t in
comb_tags])
all_tags = []
for tags in tests_tags:
- tagstats.add_test(TestCase(status='PASS', tags=tags),)
+ builder.add_test(TestCase(status='PASS', tags=tags),)
all_tags.extend(tags)
# 2) Actual values
- names = [stat.name for stat in tagstats]
+ names = [stat.name for stat in builder.stats]
# 3) Expected values
exp_crit = []; exp_noncr = []
for tag in utils.normalize_tags(all_tags):
@@ -271,12 +271,12 @@
assert_equals(names, exp_names)
def test_sorting(self):
- stats = TagStatistics(Criticality(['c2', 'c1'], ['n*']),
- combine=[('c*', ''), ('xxx', 'a title')])
- stats.add_test(TestCase(tags=['c1', 'c2', 't1']))
- stats.add_test(TestCase(tags=['c1', 'n2', 't2']))
- stats.add_test(TestCase(tags=['n1', 'n2', 't1', 't3']))
- assert_equals([(s.name, s.info, s.total) for s in stats],
+ builder = TagStatisticsBuilder(Criticality(['c2', 'c1'], ['n*']),
+ combine=[('c*', ''), ('xxx', 'a
title')])
+ builder.add_test(TestCase(tags=['c1', 'c2', 't1']))
+ builder.add_test(TestCase(tags=['c1', 'n2', 't2']))
+ builder.add_test(TestCase(tags=['n1', 'n2', 't1', 't3']))
+ assert_equals([(s.name, s.info, s.total) for s in builder.stats],
[('c1', 'critical', 2), ('c2', 'critical', 1),
('n1', 'non-critical', 1), ('n2', 'non-critical',
2),
('a title', 'combined', 0), ('c*', 'combined', 2),