2 new revisions:

Revision: b9cb586c2ce4
Author:   Pekka Klärck
Date:     Tue Nov 15 13:43:01 2011
Log: Stats: Cleaned up setting and getting attributes. No need to be overly...
http://code.google.com/p/robotframework/source/detail?r=b9cb586c2ce4

Revision: f1c518b61108
Author:   Pekka Klärck
Date:     Tue Nov 15 14:04:09 2011
Log:      TagStatLink: Simplified creating regexp pattern.
http://code.google.com/p/robotframework/source/detail?r=f1c518b61108

==============================================================================
Revision: b9cb586c2ce4
Author:   Pekka Klärck
Date:     Tue Nov 15 13:43:01 2011
Log: Stats: Cleaned up setting and getting attributes. No need to be overly fancy. For example, internal getters don't need to be properties.
http://code.google.com/p/robotframework/source/detail?r=b9cb586c2ce4

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

=======================================
--- /src/robot/model/stats.py   Mon Nov 14 15:56:32 2011
+++ /src/robot/model/stats.py   Tue Nov 15 13:43:01 2011
@@ -17,14 +17,19 @@

 class Stat(object):

-    def __init__(self, name=''):
+    def __init__(self, name):
         self.name = name
         self.passed = 0
         self.failed = 0

     @property
-    def _default_attrs(self):
-        return {'pass': str(self.passed), 'fail': str(self.failed)}
+    def attrs(self):
+        attrs = {'pass': str(self.passed), 'fail': str(self.failed)}
+        attrs.update(self._get_custom_attrs())
+        return attrs
+
+    def _get_custom_attrs(self):
+        return {}

     @property
     def total(self):
@@ -46,7 +51,7 @@
         return cmp(self.name, other.name)

     def __nonzero__(self):
-        return self.failed == 0
+        return not self.failed

     def visit(self, visitor):
         visitor.visit_stat(self)
@@ -58,11 +63,10 @@
     def __init__(self, suite):
         Stat.__init__(self, suite.longname)
         self.id = suite.id
-        self._attrs = {'name': suite.name, 'idx': suite.id}
-
-    @property
-    def attrs(self):
-        return dict(self._default_attrs, **self._attrs) # TODO: idx -> id
+        self._name = suite.name
+
+    def _get_custom_attrs(self):
+        return {'idx': self.id, 'name': self._name}  # TODO: isx -> id


 class TagStat(Stat):
@@ -71,20 +75,14 @@
     def __init__(self, name, doc='', links=None, critical=False,
                  non_critical=False, combined=''):
         Stat.__init__(self, name)
- # TODO: Do we need all these attrs or could they me only in self.attrs?
         self.doc = doc
- self.links = links or [] # TODO: Are both self.links and self._link_str needed?
+        self.links = links
         self.critical = critical
         self.non_critical = non_critical
         self.combined = combined

     @property
-    def attrs(self):
- return dict(self._default_attrs, info=self._info, links=self._link_str,
-                    doc=self.doc, combined=self.combined)
-
-    @property
-    def _info(self):
+    def info(self):
         if self.critical:
             return 'critical'
         if self.non_critical:
@@ -93,9 +91,12 @@
             return 'combined'
         return ''

-    @property
-    def _link_str(self):
- return ':::'.join(':'.join([title, url]) for url, title in self.links)
+    def _get_custom_attrs(self):
+        return {'doc': self.doc, 'links': self._get_links_as_string(),
+                'info': self.info, 'combined': self.combined}
+
+    def _get_links_as_string(self):
+ return ':::'.join('%s:%s' % (title, url) for url, title in self.links)

     def __cmp__(self, other):
         return cmp(other.critical, self.critical) \
@@ -121,7 +122,3 @@
         Stat.__init__(self, name)
         self.passed = suite_stat.passed
         self.failed = suite_stat.failed
-
-    @property
-    def attrs(self):
-        return self._default_attrs
=======================================
--- /utest/model/test_statistics.py     Mon Nov 14 16:39:48 2011
+++ /utest/model/test_statistics.py     Tue Nov 15 13:43:01 2011
@@ -271,7 +271,7 @@
         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],
+        assert_equals([(s.name, s.info, s.total) for s in stats],
                        [('c1', 'critical', 2), ('c2', 'critical', 1),
('n1', 'non-critical', 1), ('n2', 'non-critical', 2),
                         ('a title', 'combined', 0), ('c*', 'combined', 2),

==============================================================================
Revision: f1c518b61108
Author:   Pekka Klärck
Date:     Tue Nov 15 14:04:09 2011
Log:      TagStatLink: Simplified creating regexp pattern.
http://code.google.com/p/robotframework/source/detail?r=f1c518b61108

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

=======================================
--- /src/robot/model/tagstatistics.py   Tue Nov 15 04:40:38 2011
+++ /src/robot/model/tagstatistics.py   Tue Nov 15 14:04:09 2011
@@ -97,7 +97,7 @@


 class TagStatLink(object):
-    _match_pattern_tokenizer = re.compile('(\*|\?)')
+    _match_pattern_tokenizer = re.compile('(\*|\?+)')

     def __init__(self, pattern, link, title):
         self._regexp = self._get_match_regexp(pattern)
@@ -116,30 +116,20 @@

     def _replace_groups(self, link, title, match):
         for index, group in enumerate(match.groups()):
-            placefolder = '%' + str(index+1)
+            placefolder = '%%%d' % (index+1)
             link = link.replace(placefolder, group)
             title = title.replace(placefolder, group)
         return link, title

     def _get_match_regexp(self, pattern):
-        regexp = []
-        open_parenthesis = False
+        pattern = '^%s$' % ''.join(self._yield_match_pattern(pattern))
+        return re.compile(pattern, re.IGNORECASE)
+
+    def _yield_match_pattern(self, pattern):
         for token in self._match_pattern_tokenizer.split(pattern):
-            if token == '':
-                continue
-            if token == '?':
-                if not open_parenthesis:
-                    regexp.append('(')
-                    open_parenthesis = True
-                regexp.append('.')
-                continue
-            if open_parenthesis:
-                regexp.append(')')
-                open_parenthesis = False
-            if token == '*':
-                regexp.append('(.*)')
-                continue
-            regexp.append(re.escape(token))
-        if open_parenthesis:
-            regexp.append(')')
-        return re.compile('^%s$' % ''.join(regexp), re.IGNORECASE)
+            if token.startswith('?'):
+                yield '(%s)' % ('.'*len(token))
+            elif token == '*':
+                yield '(.*)'
+            else:
+                yield re.escape(token)
=======================================
--- /utest/model/test_statistics.py     Tue Nov 15 13:43:01 2011
+++ /utest/model/test_statistics.py     Tue Nov 15 14:04:09 2011
@@ -357,12 +357,12 @@
             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_equals(link.get_link('a-b-XXX'), ('XXX-XXX-a-b-XXX', 'Tracker'))
+        link = TagStatLink('??-?-*', '%3-%3-%1-%2-%3', 'Tracker')
+ assert_equals(link.get_link('aa-b-XXX'), ('XXX-XXX-aa-b-XXX', 'Tracker'))

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


 if __name__ == "__main__":

Reply via email to