2 new revisions:

Revision: b0e8522fd5f4
Branch:   default
Author:   Pekka Klärck
Date:     Wed May 29 08:42:16 2013
Log:      fixed BuiltIn Set/Remove Tags
http://code.google.com/p/robotframework/source/detail?r=b0e8522fd5f4

Revision: 33c5cb646a75
Branch:   default
Author:   Pekka Klärck
Date:     Wed May 29 08:42:20 2013
Log:      Automated merge with https://code.google.com/p/robotframework/
http://code.google.com/p/robotframework/source/detail?r=33c5cb646a75

==============================================================================
Revision: b0e8522fd5f4
Branch:   default
Author:   Pekka Klärck
Date:     Wed May 29 08:42:16 2013
Log:      fixed BuiltIn Set/Remove Tags
http://code.google.com/p/robotframework/source/detail?r=b0e8522fd5f4

Modified:
 /atest/robot/standard_libraries/builtin/tags.txt
 /src/robot/libraries/BuiltIn.py
 /src/robot/model/testcase.py
 /src/robot/model/testsuite.py
 /utest/model/test_testsuite.py

=======================================
--- /atest/robot/standard_libraries/builtin/tags.txt Fri Aug 31 00:15:08 2012 +++ /atest/robot/standard_libraries/builtin/tags.txt Wed May 29 08:42:16 2013
@@ -20,7 +20,7 @@
 Set Multiple Tags
${tc} = Tags Should Have Been Added Set Multiple Tags 1 2 3 HELLO Some spaces here
     Check Log Message  ${tc.kws[0].msgs[0]}  Set tags '1', '2' and '3'.
- Check Log Message ${tc.kws[1].msgs[0]} Set tags 'HELLO' and 'Some spaces here'. + Check Log Message ${tc.kws[1].msgs[0]} Set tags 'HELLO', '' and 'Some spaces here'.

 Tags Set In One Test Are Not Visible To Others
Should Have Only Suite Tags Tags Set In One Test Are Not Visible To Others
@@ -37,8 +37,8 @@

 Remove Multiple Tags
${tc} = Tags Should Have Been Removed Remove Multiple Tags default set set-init - Check Log Message ${tc.kws[0].msgs[0]} Removed tags 'default', 'non-existing' and 'SET'.
-    Check Log Message  ${tc.kws[1].msgs[0]}  Removed tag 'set-init'.
+ Check Log Message ${tc.kws[0].msgs[0]} Removed tags 'default', 'SET' and 'non-existing'. + Check Log Message ${tc.kws[1].msgs[0]} Removed tags '' and 'set-init'.

 Remove Tags With Pattern
     Check Test Tags  Remove Tags With Pattern
=======================================
--- /src/robot/libraries/BuiltIn.py     Wed May 29 07:18:32 2013
+++ /src/robot/libraries/BuiltIn.py     Wed May 29 08:42:16 2013
@@ -2329,12 +2329,19 @@
         See `Remove Tags` if you want to remove certain tags and `Fail` if
         you want to fail the test case after setting and/or removing tags.
         """
-        tags = utils.normalize_tags(tags)
-        handler = lambda test: utils.normalize_tags(test.tags + tags)
-        self._set_or_remove_tags(handler)
+        ns = self._namespace
+        if ns.test:
+            ns.test.tags.add(tags)
+            ns.variables.set_test('@{TEST_TAGS}', ns.test.tags[:])
+        elif self._context.suite_teardown:
+            raise RuntimeError("'Set Tags' and 'Remove Tags' keywords "
+                               "cannot be used in suite teardown.")
+        else:
+            ns.suite.set_tags(tags, persist=True)
         self.log('Set tag%s %s.' % (utils.plural_or_not(tags),
                                     utils.seq2str(tags)))

+
     def remove_tags(self, *tags):
"""Removes given `tags` from the current test or all tests in a suite.

@@ -2352,31 +2359,18 @@
See `Set Tags` if you want to add certain tags and `Fail` if you want
         to fail the test case after setting and/or removing tags.
         """
-        tags = TagPatterns(tags)
-        handler = lambda test: [t for t in test.tags if not tags.match(t)]
-        self._set_or_remove_tags(handler)
+        ns = self._namespace
+        if ns.test:
+            ns.test.tags.remove(tags)
+            ns.variables.set_test('@{TEST_TAGS}', ns.test.tags[:])
+        elif self._context.suite_teardown:
+            raise RuntimeError("'Set Tags' and 'Remove Tags' keywords "
+                               "cannot be used in suite teardown.")
+        else:
+            ns.suite.set_tags(remove=tags, persist=True)
         self.log('Removed tag%s %s.' % (utils.plural_or_not(tags),
                                         utils.seq2str(tags)))

-    def _set_or_remove_tags(self, handler, suite=None, test=None):
-        if not (suite or test):
-            ns = self._namespace
-            if ns.test is None:
-                if self._context.suite_teardown:
- raise RuntimeError("'Set Tags' and 'Remove Tags' keywords "
-                                       "cannot be used in suite teardown.")
-                self._set_or_remove_tags(handler, suite=ns.suite)
-            else:
-                self._set_or_remove_tags(handler, test=ns.test)
-                ns.variables.set_test('@{TEST_TAGS}', ns.test.tags[:])
-        elif suite:
-            for sub in suite.suites:
-                self._set_or_remove_tags(handler, suite=sub)
-            for test in suite.tests:
-                self._set_or_remove_tags(handler, test=test)
-        else:
-            test.tags = handler(test)
-
     def get_library_instance(self, name):
"""Returns the currently active instance of the specified test library.

=======================================
--- /src/robot/model/testcase.py        Wed May 22 15:27:57 2013
+++ /src/robot/model/testcase.py        Wed May 29 08:42:16 2013
@@ -67,3 +67,8 @@

     def __init__(self, test_class=TestCase, parent=None, tests=None):
         ItemList.__init__(self, test_class, {'parent': parent}, tests)
+
+    def _check_type_and_set_attrs(self, test):
+        ItemList._check_type_and_set_attrs(self, test)
+        for visitor in test.parent._visitors:
+            test.visit(visitor)
=======================================
--- /src/robot/model/testsuite.py       Wed May 22 04:57:27 2013
+++ /src/robot/model/testsuite.py       Wed May 29 08:42:16 2013
@@ -26,7 +26,7 @@


 class TestSuite(ModelObject):
-    __slots__ = ['parent', 'source', '_name', 'doc', '_criticality']
+ __slots__ = ['parent', 'source', '_name', 'doc', '_criticality', '_my_visitors']
     test_class = TestCase
     keyword_class = Keyword

@@ -40,6 +40,12 @@
         self.tests = []
         self.keywords = []
         self._criticality = None
+        self._my_visitors = []
+
+    @property
+    def _visitors(self):
+        parent_visitors = self.parent._visitors if self.parent else []
+        return self._my_visitors + parent_visitors

     def _get_name(self):
         return self._name or ' & '.join(s.name for s in self.suites)
@@ -92,8 +98,11 @@
     def test_count(self):
return len(self.tests) + sum(suite.test_count for suite in self.suites)

-    def set_tags(self, add=None, remove=None):
-        self.visit(TagSetter(add, remove))
+    def set_tags(self, add=None, remove=None, persist=False):
+        setter = TagSetter(add, remove)
+        self.visit(setter)
+        if persist:
+            self._my_visitors.append(setter)

     def filter(self, included_suites=None, included_tests=None,
                included_tags=None, excluded_tags=None):
=======================================
--- /utest/model/test_testsuite.py      Fri Dec  2 06:36:31 2011
+++ /utest/model/test_testsuite.py      Wed May 29 08:42:16 2013
@@ -53,6 +53,29 @@
         assert_equal(list(suite.suites), [sub1])
         assert_equal(list(sub1.suites), [sub2])

+    def test_set_tags(self):
+        suite = TestSuite()
+        suite.tests.create()
+        suite.tests.create(tags=['t1', 't2'])
+        suite.set_tags(add='a', remove=['t2', 'nonex'])
+        suite.tests.create()
+        assert_equal(list(suite.tests[0].tags), ['a'])
+        assert_equal(list(suite.tests[1].tags), ['a', 't1'])
+        assert_equal(list(suite.tests[2].tags), [])
+
+    def test_set_tags_also_to_new_child(self):
+        suite = TestSuite()
+        suite.tests.create()
+        suite.set_tags(add='a', remove=['t2', 'nonex'], persist=True)
+        suite.tests.create(tags=['t1', 't2'])
+        suite.tests = list(suite.tests)
+        suite.tests.create()
+        suite.suites.create().tests.create()
+        assert_equal(list(suite.tests[0].tags), ['a'])
+        assert_equal(list(suite.tests[1].tags), ['a', 't1'])
+        assert_equal(list(suite.tests[2].tags), ['a'])
+        assert_equal(list(suite.suites[0].tests[0].tags), ['a'])
+
     def test_slots(self):
         assert_raises(AttributeError, setattr, self.suite, 'attr', 'value')


==============================================================================
Revision: 33c5cb646a75
Branch:   default
Author:   Pekka Klärck
Date:     Wed May 29 08:42:20 2013
Log:      Automated merge with https://code.google.com/p/robotframework/
http://code.google.com/p/robotframework/source/detail?r=33c5cb646a75


--

--- You received this message because you are subscribed to the Google Groups "robotframework-commit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to