2 new revisions:

Revision: 6a0ee303beb3
Author:   Janne Härkönen <[email protected]>
Date:     Fri Nov 11 01:36:26 2011
Log:      test cleanup
http://code.google.com/p/robotframework/source/detail?r=6a0ee303beb3

Revision: 8422a7ce2e80
Author:   Janne Härkönen <[email protected]>
Date:     Fri Nov 11 01:36:55 2011
Log:      statistics: handle test inclusion in stats, cleanup
http://code.google.com/p/robotframework/source/detail?r=8422a7ce2e80

==============================================================================
Revision: 6a0ee303beb3
Author:   Janne Härkönen <[email protected]>
Date:     Fri Nov 11 01:36:26 2011
Log:      test cleanup
http://code.google.com/p/robotframework/source/detail?r=6a0ee303beb3

Modified:
 /utest/model/test_statistics.py

=======================================
--- /utest/model/test_statistics.py     Thu Nov 10 06:42:09 2011
+++ /utest/model/test_statistics.py     Fri Nov 11 01:36:26 2011
@@ -1,9 +1,11 @@
 import unittest
-from robot.model.critical import Critical
-
-from robot.utils.asserts import *
-from robot.model.statistics import *
+
+from robot.model.critical import Critical
+from robot.utils.asserts import assert_equals, assert_none, fail
+from robot.model.statistics import (Statistics, TagStatistics, TagStatLink,
+                                    TagStatInfo)
 from robot.result import TestSuite, TestCase
+from robot import utils


def verify_stat(stat, name, passed, failed, critical=None, non_crit=None, id=None):
@@ -15,7 +17,7 @@
     if non_crit is not None:
         assert_equals(stat.non_critical, non_crit)
     if id:
-        assert_equal(stat.id, id)
+        assert_equals(stat.id, id)

def verify_suite(suite, name, id, crit_pass, crit_fail, all_pass=None, all_fail=None):
     verify_stat(suite.critical, name, crit_pass, crit_fail, id=id)
@@ -97,6 +99,10 @@
         verify_stat(tags.stats['t3'], 't3', 0, 2, False, False)


+class TestStatisticsVisitation(unittest.TestCase):
+    pass
+
+
 _incl_excl_data = [
     ([], []),
     ([], ['t1','t2']),
@@ -119,7 +125,7 @@
tagstats.add_test(TestCase(status='PASS', tags=tags), Critical())
             exp_keys = [tag for tag in sorted(tags)
                         if incl == [] or utils.matches_any(tag, incl)]
-            assert_equal(sorted(tagstats.stats.keys()),
+            assert_equals(sorted(tagstats.stats.keys()),
                          exp_keys, "Incls: %s " % incl)

     def test_exclude(self):
@@ -128,7 +134,7 @@
tagstats.add_test(TestCase(status='PASS', tags=tags), Critical())
             exp_keys = [tag for tag in sorted(tags)
                         if not utils.matches_any(tag, excl)]
-            assert_equal(sorted(tagstats.stats.keys()),
+            assert_equals(sorted(tagstats.stats.keys()),
                          exp_keys, "Excls: %s" % excl)

     def test_include_and_exclude(self):
@@ -143,7 +149,7 @@
               ]:
             tagstats = TagStatistics(incl, excl)
tagstats.add_test(TestCase(status='PASS', tags=tags), Critical())
-            assert_equal(sorted(tagstats.stats.keys()),
+            assert_equals(sorted(tagstats.stats.keys()),
                          exp, "Incls: %s, Excls: %s" % (incl, excl))

     def test_combine_with_name(self):
@@ -184,7 +190,6 @@
                           'comb: %s, test: %s' % (comb_tags, test_tags))

     def test_is_combined_with_not_statements(self):
-        stats = TagStatistics()
         for comb_tags, test_tags, expected_count in [
                 ('t1NOTt2', [], 0),
                 ('t1NOTt2', ['t1'], 1),
@@ -273,9 +278,9 @@
('^hello$', 'gopher://hello.world:8090/hello.html',
                            'Hello World'))]:
             link = TagStatLink(*arg)
-            assert_equal(exp[0], link._regexp.pattern)
-            assert_equal(exp[1], link._link)
-            assert_equal(exp[2], link._title)
+            assert_equals(exp[0], link._regexp.pattern)
+            assert_equals(exp[1], link._link)
+            assert_equals(exp[2], link._title)

     def test_valid_string_containing_patterns_is_parsed_correctly(self):
         for arg, exp_pattern in [('*', '^(.*)$'), ('f*r', '^f(.*)r$'),
@@ -283,11 +288,11 @@
('??', '^(..)$'), ('f???ar', '^f(...)ar$'),
                                  ('F*B?R*?', '^F(.*)B(.)R(.*)(.)$')]:
             link = TagStatLink(arg, 'some_url', 'some_title')
-            assert_equal(exp_pattern, link._regexp.pattern)
+            assert_equals(exp_pattern, link._regexp.pattern)

     def test_underscores_in_title_are_converted_to_spaces(self):
         link = TagStatLink('', '', 'my_name')
-        assert_equal(link._title, 'my name')
+        assert_equals(link._title, 'my name')

     def test_get_link_returns_correct_link_when_matches(self):
         for arg, exp in [(('smoke', 'http://tobacco.com', 'Lung_cancer'),
@@ -317,27 +322,27 @@
     def test_pattern_match(self):
         link = TagStatLink('f?o*r', 'http://foo/bar.html', 'FooBar')
         for tag in ['foobar', 'foor', 'f_ofoobarfoobar', 'fOoBAr']:
- assert_equal(link.get_link(tag), ('http://foo/bar.html', 'FooBar')) + assert_equals(link.get_link(tag), ('http://foo/bar.html', 'FooBar'))

     def test_pattern_substitution_with_one_match(self):
         link = TagStatLink('tag-*', 'http://tracker/?id=%1', 'Tracker')
         for id in ['1', '23', '456']:
             exp = ('http://tracker/?id=%s' % id, 'Tracker')
-            assert_equal(exp, link.get_link('tag-%s' % id))
+            assert_equals(exp, link.get_link('tag-%s' % id))

     def test_pattern_substitution_with_multiple_matches(self):
         link = TagStatLink('?-*', 'http://tracker/?id=%1-%2', 'Tracker')
         for id1, id2 in [('1', '2'), ('3', '45'), ('f', 'bar')]:
             exp = ('http://tracker/?id=%s-%s' % (id1, id2), 'Tracker')
-            assert_equal(exp, link.get_link('%s-%s' % (id1, id2)))
+            assert_equals(exp, link.get_link('%s-%s' % (id1, id2)))

     def test_pattern_substitution_with_multiple_substitutions(self):
         link = TagStatLink('?-?-*', '%3-%3-%1-%2-%3', 'Tracker')
- assert_equal(link.get_link('a-b-XXX'), ('XXX-XXX-a-b-XXX', 'Tracker')) + assert_equals(link.get_link('a-b-XXX'), ('XXX-XXX-a-b-XXX', 'Tracker'))

     def test_matches_are_ignored_in_pattern_substitution(self):
         link = TagStatLink('?-*-*-?', '%4-%2-%2-%4', 'Tracker')
- assert_equal(link.get_link('A-XXX-ABC-B'), ('B-XXX-XXX-B', 'Tracker')) + assert_equals(link.get_link('A-XXX-ABC-B'), ('B-XXX-XXX-B', 'Tracker'))


 class TestTagStatLinks(unittest.TestCase):
@@ -345,7 +350,7 @@
     def test_tag_stat_links_with_valid_tags(self):
         values = [('1', '2', '3'), ('tag', 'foo.html', 'bar')]
         tag_stat_links = TagStatInfo([], values)
-        assert_equal(len(tag_stat_links._links), 2)
+        assert_equals(len(tag_stat_links._links), 2)


 if __name__ == "__main__":

==============================================================================
Revision: 8422a7ce2e80
Author:   Janne Härkönen <[email protected]>
Date:     Fri Nov 11 01:36:55 2011
Log:      statistics: handle test inclusion in stats, cleanup
http://code.google.com/p/robotframework/source/detail?r=8422a7ce2e80

Modified:
 /src/robot/model/statistics.py
 /src/robot/result/testcase.py

=======================================
--- /src/robot/model/statistics.py      Wed Nov  9 06:47:58 2011
+++ /src/robot/model/statistics.py      Fri Nov 11 01:36:55 2011
@@ -16,6 +16,8 @@

 from robot import utils
 from robot.result.visitor import SuiteVisitor
+from robot.model.tags import TagPattern
+

 class StatisticsBuilder(SuiteVisitor):

@@ -41,9 +43,7 @@
             self._current_suite_stat = self._parents.pop(-1)

     def start_test(self, test):
-        self._current_suite_stat.all.add_test(test)
-        if test.critical == 'yes':
-            self._current_suite_stat.critical.add_test(test)
+        self._current_suite_stat.add_test(test)
         self._stats.tags.add_test(test, self._current_suite.critical)


@@ -71,7 +71,32 @@
         self.serialize(visitor)


-class Stat:
+class SuiteStatistics:
+
+    def __init__(self, suite, suite_stat_level=-1):
+        self.all = SuiteStat(suite)
+        self.critical = SuiteStat(suite)
+        self.suites = []
+        self._suite_stat_level = suite_stat_level
+
+    def add_test(self, test):
+        self.all.add_test(test)
+        if test.critical == 'yes':
+            self.critical.add_test(test)
+
+    def serialize(self, serializer):
+        serializer.start_suite_stats(self)
+        self._serialize(serializer, self._suite_stat_level)
+        serializer.end_suite_stats(self)
+
+    def _serialize(self, serializer, max_suite_level, suite_level=1):
+        self.all.serialize(serializer)
+        if max_suite_level < 0 or max_suite_level > suite_level:
+            for suite in self.suites:
+ suite._serialize(serializer, max_suite_level, suite_level+1)
+
+
+class Stat(object):

     def __init__(self, name=''):
         self.name = name
@@ -189,26 +214,6 @@
         serializer.total_stat(self)


-class SuiteStatistics:
-
-    def __init__(self, suite, suite_stat_level=-1):
-        self.all = SuiteStat(suite)
-        self.critical = SuiteStat(suite)
-        self.suites = []
-        self._suite_stat_level = suite_stat_level
-
-    def serialize(self, serializer):
-        serializer.start_suite_stats(self)
-        self._serialize(serializer, self._suite_stat_level)
-        serializer.end_suite_stats(self)
-
-    def _serialize(self, serializer, max_suite_level, suite_level=1):
-        self.all.serialize(serializer)
-        if max_suite_level < 0 or max_suite_level > suite_level:
-            for suite in self.suites:
- suite._serialize(serializer, max_suite_level, suite_level+1)
-
-
 class TagStatistics:

     def __init__(self, include=None, exclude=None, combine=None, docs=None,
@@ -248,7 +253,7 @@
                 self.stats[name] = TagStat(name, self._get_doc(name),
                                            self._get_links(name),
                                            combined=pattern)
-            if test.is_included([pattern], []):
+            if TagPattern(pattern).match(test.tags):
                 self.stats[name].add_test(test)

     def serialize(self, serializer):
=======================================
--- /src/robot/result/testcase.py       Thu Nov 10 06:42:09 2011
+++ /src/robot/result/testcase.py       Fri Nov 11 01:36:55 2011
@@ -37,7 +37,3 @@
     @property
     def is_passed(self):
         return self.status == 'PASS'
-
-    # TODO: Remove, move to where statistics are created.
-    def is_included(self, includes, excludes):
-        return self.tags.match(includes) and not self.tags.match(excludes)

Reply via email to