Revision: 3624
Author: KariHusa
Date: Fri May 28 03:40:17 2010
Log: Added var and for loop handling with templates, issue 500
http://code.google.com/p/robotframework/source/detail?r=3624

Modified:
 /trunk/src/robot/parsing/model.py
 /trunk/src/robot/running/defaultvalues.py
 /trunk/src/robot/running/keywords.py
 /trunk/src/robot/running/model.py
 /trunk/utest/parsing/test_model.py

=======================================
--- /trunk/src/robot/parsing/model.py   Thu May 27 23:28:51 2010
+++ /trunk/src/robot/parsing/model.py   Fri May 28 03:40:17 2010
@@ -465,6 +465,9 @@
     def is_for_loop(self):
         return True

+    def apply_template(self, template):
+        return Step(['Fail', 'Templates not supported with FOR loops.'])
+

 class Step(object):

@@ -491,3 +494,7 @@

     def is_for_loop(self):
         return False
+
+    def apply_template(self, template):
+        kw = [self.keyword] if self.keyword else []
+        return Step([template] + self.assign + kw + self.args)
=======================================
--- /trunk/src/robot/running/defaultvalues.py   Fri May 28 01:22:46 2010
+++ /trunk/src/robot/running/defaultvalues.py   Fri May 28 03:40:17 2010
@@ -60,5 +60,4 @@
         return self._force_tags + self._parent._get_force_tags()

     def get_template(self, template):
-        tmplt = template if template.is_set() else self._test_template
-        return tmplt.value
+ return (template if template.is_set() else self._test_template).value
=======================================
--- /trunk/src/robot/running/keywords.py        Fri May 28 01:22:46 2010
+++ /trunk/src/robot/running/keywords.py        Fri May 28 03:40:17 2010
@@ -21,18 +21,21 @@

 class Keywords(object):

-    def __init__(self, steps, template=False):
+    def __init__(self, steps, template=None):
         self._keywords = []
-        for step in steps:
-            self._add_keyword(step, template)
-
-    def _add_keyword(self, step, template):
+        self._continue_on_failure = bool(template)
+        if template:
+            steps = [s.apply_template(template) for s in steps]
+        for s in steps:
+            self._add_keyword(s)
+
+    def _add_keyword(self, step):
         if step.is_comment():
             return
         if step.is_for_loop():
             keyword = ForLoop(step)
         else:
- keyword = Keyword(step.keyword, step.args, step.assign, continue_on_failure=template)
+            keyword = Keyword(step.keyword, step.args, step.assign)
         self._keywords.append(keyword)

     def run(self, context):
@@ -42,7 +45,7 @@
                 kw.run(context)
             except ExecutionFailed, err:
                 errors.extend(err.get_errors())
-                if not err.cont:
+                if not (err.cont or self._continue_on_failure):
                     break
         if errors:
             raise ExecutionFailures(errors)
@@ -56,19 +59,16 @@

 class Keyword(BaseKeyword):

- def __init__(self, name, args, assign=None, type='kw', continue_on_failure=False):
+    def __init__(self, name, args, assign=None, type='kw'):
         BaseKeyword.__init__(self, name, args, type=type)
         self.assign = assign or []
         self.handler_name = name
-        self.continue_on_failure = continue_on_failure

     def run(self, context):
         handler = self._start(context)
         try:
             return_value = self._run(handler, context)
         except ExecutionFailed, err:
-            if self.continue_on_failure:
-                err.cont = True
             self.status = 'FAIL'
             self._end(context, error=err)
             raise
=======================================
--- /trunk/src/robot/running/model.py   Fri May 28 01:22:46 2010
+++ /trunk/src/robot/running/model.py   Fri May 28 03:40:17 2010
@@ -198,24 +198,6 @@
         self._run_mode_dry_run = False


-class Template(object):
-
-    def __init__(self, template):
-        self.template = template
-
-    def apply_to_steps(self, orig_steps):
-        if not self.template:
-            return orig_steps
-        steps = []
-        for s in orig_steps:
- templated_step = Step([self.template] + s.assign + [s.keyword] + s.args)
-            steps.append(templated_step)
-        return steps
-
-    def __nonzero__(self):
-        return bool(self.template)
-
-
 class RunnableTestCase(BaseTestCase):

     def __init__(self, tc_data, parent, defaults):
@@ -225,9 +207,8 @@
         self.teardown = defaults.get_teardown(tc_data.teardown)
         self.tags = defaults.get_tags(tc_data.tags)
         self.timeout = defaults.get_timeout(tc_data.timeout)
-        self.template = Template(defaults.get_template(tc_data.template))
-        steps = self.template.apply_to_steps(tc_data.steps)
-        self.keywords = Keywords(steps, self.template)
+        self.template = defaults.get_template(tc_data.template)
+        self.keywords = Keywords(tc_data.steps, self.template)

     def run(self, context, suite_errors):
         self._suite_errors = suite_errors
=======================================
--- /trunk/utest/parsing/test_model.py  Thu May 27 00:49:51 2010
+++ /trunk/utest/parsing/test_model.py  Fri May 28 03:40:17 2010
@@ -264,6 +264,14 @@
         assert_true(Step([], comment="comment").is_comment())
         assert_false(Step(['KW'], comment="comment").is_comment())

+    def test_apply_template_to_step(self):
+        kw = 'Should Be Equal'
+        args = ['Foo', 'Bar']
+        step = Step(args)
+        templated_step = step.apply_template(kw)
+        assert_equal(templated_step.keyword, kw)
+        assert_equal(templated_step.args, args)
+
     def _test(self, content, kw='KW', args=[], assign=[]):
         step = Step(content)
         assert_equal(step.keyword, kw)

Reply via email to