2 new revisions:

Revision: cd411291b202
Author:   Pekka Klärck
Date:     Mon Nov 14 12:02:55 2011
Log: TagStatistics: Moved criticality and combines into TagStatInfo. Also c...
http://code.google.com/p/robotframework/source/detail?r=cd411291b202

Revision: ba31896e5526
Author:   Pekka Klärck
Date:     Mon Nov 14 13:07:07 2011
Log: TagStatistics: TagStats don't need to store tests anymore. That was ne...
http://code.google.com/p/robotframework/source/detail?r=ba31896e5526

==============================================================================
Revision: cd411291b202
Author:   Pekka Klärck
Date:     Mon Nov 14 12:02:55 2011
Log: TagStatistics: Moved criticality and combines into TagStatInfo. Also consistently use match and not matches as method name.
http://code.google.com/p/robotframework/source/detail?r=cd411291b202

Modified:
 /src/robot/model/tagstatistics.py
 /utest/model/test_statistics.py

=======================================
--- /src/robot/model/tagstatistics.py   Mon Nov 14 09:10:30 2011
+++ /src/robot/model/tagstatistics.py   Mon Nov 14 12:02:55 2011
@@ -23,21 +23,15 @@

def __init__(self, criticality, include=None, exclude=None, combine=None,
                  docs=None, links=None):
-        self._criticality = criticality
         self.stats = utils.NormalizedDict(ignore=['_'])
+        self._info = TagStatInfo(criticality, combine, docs, links)
         self._include = TagPatterns(include)
         self._exclude = TagPatterns(exclude)
-        self._info = TagStatInfo(docs or [], links or [])
-        self._combine = self._create_combined(combine or [])
-
-    def _create_combined(self, combines):
- combines = [CombinedTag(pattern, name) for pattern, name in combines]
-        for comb in combines:
-            self.stats[comb.name] = TagStat(comb.name,
-                                            self._info.get_doc(comb.name),
- self._info.get_links(comb.name),
-                                            combined=comb.pattern)
-        return combines
+        for tag in self._info.combined_tags:
+            self.stats[tag.name] = TagStat(tag.name,
+                                           self._info.get_doc(tag.name),
+                                           self._info.get_links(tag.name),
+                                           combined=tag.pattern)

     def add_test(self, test):
         self._add_tags_statistics(test)
@@ -51,8 +45,8 @@
                 self.stats[tag] = TagStat(tag,
                                           self._info.get_doc(tag),
                                           self._info.get_links(tag),
- self._criticality.tag_is_critical(tag), - self._criticality.tag_is_non_critical(tag))
+                                          self._info.is_critical(tag),
+                                          self._info.is_non_critical(tag))
             self.stats[tag].add_test(test)

     def _is_included(self, tag):
@@ -61,7 +55,7 @@
         return not self._exclude.match(tag)

     def _add_combined_statistics(self, test):
-        for comb in self._combine:
+        for comb in self._info.combined_tags:
             if comb.match(test.tags):
                 self.stats[comb.name].add_test(test)

@@ -77,9 +71,30 @@
             stat.tests.sort()


+class TagStatInfo(object):
+
+    def __init__(self, criticality, combines=None, docs=None, links=None):
+        self.criticality = criticality
+ self.combined_tags = [CombinedTag(*comb) for comb in combines or []]
+        self.docs = [TagStatDoc(*doc) for doc in docs or []]
+        self.links = [TagStatLink(*link) for link in links or []]
+
+    def is_critical(self, tag):
+        return self.criticality.tag_is_critical(tag)
+
+    def is_non_critical(self, tag):
+        return self.criticality.tag_is_non_critical(tag)
+
+    def get_doc(self, tag):
+        return ' & '.join(doc.text for doc in self.docs if doc.match(tag))
+
+    def get_links(self, tag):
+ return [link.get_link(tag) for link in self.links if link.match(tag)]
+
+
 class CombinedTag(object):

-    def __init__(self, pattern, name):
+    def __init__(self, pattern, name=None):
         self.pattern = pattern
         self._matcher = TagPatterns(pattern)
         self.name = name or pattern
@@ -88,27 +103,14 @@
         return self._matcher.match(tags)


-class TagStatInfo(object):
-
-    def __init__(self, docs, links):
-        self._docs = [TagStatDoc(*doc) for doc in docs]
-        self._links = [TagStatLink(*link) for link in links]
-
-    def get_doc(self, tag):
- return ' & '.join(doc.text for doc in self._docs if doc.matches(tag))
-
-    def get_links(self, tag):
- return [link.get_link(tag) for link in self._links if link.matches(tag)]
-
-
 class TagStatDoc(object):

     def __init__(self, pattern, doc):
+        self._matcher = TagPatterns(pattern)
         self.text = doc
-        self._pattern = TagPatterns(pattern)
-
-    def matches(self, tag):
-        return self._pattern.match(tag)
+
+    def match(self, tag):
+        return self._matcher.match(tag)


 class TagStatLink(object):
@@ -119,7 +121,7 @@
         self._link = link
         self._title = title.replace('_', ' ')

-    def matches(self, tag):
+    def match(self, tag):
         return self._regexp.match(tag) is not None

     def get_link(self, tag):
=======================================
--- /utest/model/test_statistics.py     Mon Nov 14 09:10:30 2011
+++ /utest/model/test_statistics.py     Mon Nov 14 12:02:55 2011
@@ -358,8 +358,8 @@

     def test_tag_stat_links_with_valid_tags(self):
         values = [('1', '2', '3'), ('tag', 'foo.html', 'bar')]
-        tag_stat_links = TagStatInfo([], values)
-        assert_equals(len(tag_stat_links._links), 2)
+        tag_stat_links = TagStatInfo(Criticality(), links=values)
+        assert_equals(len(tag_stat_links.links), 2)


 if __name__ == "__main__":

==============================================================================
Revision: ba31896e5526
Author:   Pekka Klärck
Date:     Mon Nov 14 13:07:07 2011
Log: TagStatistics: TagStats don't need to store tests anymore. That was needed in 2.5 and earlier when details by tags in reports were written based on them.
http://code.google.com/p/robotframework/source/detail?r=ba31896e5526

Modified:
 /src/robot/model/statistics.py
 /src/robot/model/stats.py
 /src/robot/model/tagstatistics.py
 /utest/model/test_statistics.py

=======================================
--- /src/robot/model/statistics.py      Mon Nov 14 09:10:30 2011
+++ /src/robot/model/statistics.py      Mon Nov 14 13:07:07 2011
@@ -27,7 +27,6 @@
                                   tag_stat_exclude, tag_stat_combine,
                                   tag_doc, tag_stat_link)
self.suite = StatisticsBuilder(self.tags, suite_stat_level).build(suite)
-        self.tags.sort()
         self.total = TotalStatistics(self.suite)

     def visit(self, visitor):
=======================================
--- /src/robot/model/stats.py   Mon Nov 14 08:22:28 2011
+++ /src/robot/model/stats.py   Mon Nov 14 13:07:07 2011
@@ -75,7 +75,6 @@
         self.critical = critical
         self.non_critical = non_critical
         self.combined = combined
-        self.tests = []

     @property
     def attrs(self):
@@ -96,10 +95,6 @@
     def _link_str(self):
return ':::'.join(':'.join([title, url]) for url, title in self.links)

-    def add_test(self, test):
-        Stat.add_test(self, test)
-        self.tests.append(test)
-
     def __cmp__(self, other):
         return cmp(other.critical, self.critical) \
             or cmp(other.non_critical, self.non_critical) \
=======================================
--- /src/robot/model/tagstatistics.py   Mon Nov 14 12:02:55 2011
+++ /src/robot/model/tagstatistics.py   Mon Nov 14 13:07:07 2011
@@ -65,11 +65,6 @@
     def __iter__(self):
         return iter(sorted(self.stats.values()))

-    def sort(self):
-        # TODO: Is this needed?
-        for stat in self.stats.values():
-            stat.tests.sort()
-

 class TagStatInfo(object):

=======================================
--- /utest/model/test_statistics.py     Mon Nov 14 12:02:55 2011
+++ /utest/model/test_statistics.py     Mon Nov 14 13:07:07 2011
@@ -195,8 +195,7 @@
stats = TagStatistics(Criticality(), combine=[(comb_tags, 'name')])
             test = TestCase(tags=test_tags)
             stats._add_combined_statistics(test)
-            assert_equals(len(stats.stats['Name'].tests), expected_count,
-                          'comb: %s, test: %s' % (comb_tags, test_tags))
+            assert_equals(stats.stats['Name'].total, expected_count)

     def test_is_combined_with_not_statements(self):
         for comb_tags, test_tags, expected_count in [
@@ -223,17 +222,17 @@

     def test_combine(self):
         # This is more like an acceptance test than a unit test ...
-        for comb_tags, comb_matches, tests_tags, crit_tags in [
-                (['t1&t2'], [1], [['t1','t2','t3'],['t1','t3']], []),
- (['1&2&3'], [2], [['1','2','3'],['1','2','3','4']], ['1','2']), - (['1&2','1&3'], [1,2], [['1','2','3'],['1','3'],['1']], ['1']),
-                (['t*'], [3], [['t1','x','y'],['tee','z'],['t']], ['x']),
- (['t?&s'], [2], [['t1','s'],['tt','s','u'],['tee','s'],['s']], []), - (['t*&s','*'], [2,3], [['s','t','u'],['tee','s'],[],['x']], []),
-                (['tNOTs'], [1], [['t','u'],['t','s']], []),
-                (['tNOTs','t&s','tNOTsNOTu', 't&sNOTu'], [3,2,4,1],
+        for comb_tags, tests_tags, crit_tags in [
+                (['t1&t2'], [['t1','t2','t3'],['t1','t3']], []),
+                (['1&2&3'], [['1','2','3'],['1','2','3','4']], ['1','2']),
+                (['1&2','1&3'], [['1','2','3'],['1','3'],['1']], ['1']),
+                (['t*'], [['t1','x','y'],['tee','z'],['t']], ['x']),
+ (['t?&s'], [['t1','s'],['tt','s','u'],['tee','s'],['s']], []),
+                (['t*&s','*'], [['s','t','u'],['tee','s'],[],['x']], []),
+                (['tNOTs'], [['t','u'],['t','s']], []),
+                (['tNOTs','t&s','tNOTsNOTu', 't&sNOTu'],
[['t','u'],['t','s'],['s','t','u'],['t'],['t','v']], ['t']),
-                (['nonex'], [0], [['t1'],['t1,t2'],[]], [])
+                (['nonex'], [['t1'],['t1,t2'],[]], [])
                ]:
             # 1) Create tag stats
             tagstats = TagStatistics(Criticality(crit_tags),
@@ -243,21 +242,15 @@
                 tagstats.add_test(TestCase(status='PASS', tags=tags),)
                 all_tags.extend(tags)
             # 2) Actual values
-            names = [stat.name for stat in sorted(tagstats.stats.values())]
+            names = [stat.name for stat in tagstats]
             # 3) Expected values
-            exp_crit = []; exp_noncr = []; exp_comb = []
+            exp_crit = []; exp_noncr = []
             for tag in utils.normalize_tags(all_tags):
                 if tag in crit_tags:
                     exp_crit.append(tag)
                 else:
                     exp_noncr.append(tag)
-            for comb, count in zip(comb_tags, comb_matches):
-                exp_comb.append(comb)
-                try:
- assert_equals(len(tagstats.stats[comb].tests), count, comb)
-                except KeyError:
-                    fail("No key %s. Stats: %s" % (comb, tagstats.stats))
-            exp_names = exp_crit + sorted(exp_comb) + exp_noncr
+            exp_names = exp_crit + sorted(comb_tags) + exp_noncr
             # 4) Verify names (match counts were already verified)
             assert_equals(names, exp_names)

@@ -267,14 +260,12 @@
         statistics = Statistics(suite, 1, ['t*','smoke'], ['t3'],
                                 [('t1 & t2', ''), ('t? & smoke', ''),
('t1 NOT t2', ''), ('none & t1', 'a title')])
-        stats = sorted(statistics.tags.stats.values())
         expected = [('smoke', 4), ('a title', 0), ('t1 & t2', 3),
('t1 NOT t2', 2), ('t? & smoke', 4), ('t1', 5), ('t2', 3)]
-        names = [stat.name for stat in stats]
-        exp_names = [name for name, _ in expected]
-        assert_equals(names, exp_names)
+        assert_equals([stat.name for stat in statistics.tags],
+                      [name for name, _ in expected])
         for name, count in expected:
- assert_equals(len(statistics.tags.stats[name].tests), count, name)
+            assert_equals(statistics.tags.stats[name].total, count, name)


 class TestTagStatLink(unittest.TestCase):

Reply via email to