Revision: 3283
Author: pekka.klarck
Date: Wed May 12 07:49:09 2010
Log: 1) Variable table allows using '=' in assignments and setting scalar vars with strings, 2) Steps handle assigning variables
http://code.google.com/p/robotframework/source/detail?r=3283

Modified:
 /trunk/src/robot/parsing/newmodel.py
 /trunk/utest/parsing/test_model.py

=======================================
--- /trunk/src/robot/parsing/newmodel.py        Wed May 12 05:50:26 2010
+++ /trunk/src/robot/parsing/newmodel.py        Wed May 12 07:49:09 2010
@@ -12,6 +12,9 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License.

+from robot.variables import is_var
+
+
 class TestCaseFile(object):

     def __init__(self, source=None):
@@ -159,7 +162,9 @@
 class Variable(object):

     def __init__(self, name, value):
-        self.name = name
+        self.name = name.rstrip('= ')
+        if name.startswith('$') and isinstance(value, basestring):
+            value = [value]  # Need to support scalar lists until RF 2.6
         self.value = value


@@ -195,5 +200,18 @@
 class Step(object):

     def __init__(self, content):
-        self.keyword = content[0]
-        self.args = content[1:]
+        self.assign = self._get_assigned_vars(content)
+        try:
+            self.keyword = content[len(self.assign)]
+        except IndexError:
+            self.keyword = ''
+        self.args = content[len(self.assign)+1:]
+
+    def _get_assigned_vars(self, content):
+        vars = []
+        for item in content:
+            item = item.rstrip('= ')
+            if not is_var(item):
+                break
+            vars.append(item)
+        return vars
=======================================
--- /trunk/utest/parsing/test_model.py  Wed May 12 05:50:26 2010
+++ /trunk/utest/parsing/test_model.py  Wed May 12 07:49:09 2010
@@ -78,12 +78,15 @@

     def test_add_variables(self):
         self.table.add('${SCALAR}', ['hello'])
+        self.table.add('${S2} =', 'hello as string')
         self.table.add('@{LIST}', ['hello', 'world'])
-        assert_true(len(self.table.variables), 2)
+        assert_equal(len(self.table.variables), 3)
         assert_equal(self.table.variables[0].name, '${SCALAR}')
         assert_equal(self.table.variables[0].value, ['hello'])
-        assert_equal(self.table.variables[1].name, '@{LIST}')
-        assert_equal(self.table.variables[1].value, ['hello', 'world'])
+        assert_equal(self.table.variables[1].name, '${S2}')
+        assert_equal(self.table.variables[1].value, ['hello as string'])
+        assert_equal(self.table.variables[2].name, '@{LIST}')
+        assert_equal(self.table.variables[2].value, ['hello', 'world'])


 class TestTestCaseTable(unittest.TestCase):
@@ -114,6 +117,12 @@
         assert_equal(self.test.doc.value, 'My coooool doc')
         assert_equal(self.test.tags.value, ['My', 'coooool', 'tags'])

+    def test_add_step(self):
+        self.test.add_step(['Keyword', 'arg1', 'arg2'])
+        assert_equal(len(self.test.steps), 1)
+        assert_equal(self.test.steps[0].keyword, 'Keyword')
+        assert_equal(self.test.steps[0].args, ['arg1', 'arg2'])
+

 class TestKeywordTable(unittest.TestCase):

@@ -142,17 +151,39 @@
         assert_equal(self.kw.doc.value, 'My coooool doc')
assert_equal(self.kw.args.value, ['${args}', 'are not', 'validated'])

+    def test_add_step(self):
+        self.kw.add_step(['Keyword', 'arg1', 'arg2'])
+        assert_equal(len(self.kw.steps), 1)
+        assert_equal(self.kw.steps[0].keyword, 'Keyword')
+        assert_equal(self.kw.steps[0].args, ['arg1', 'arg2'])
+

 class TestStep(unittest.TestCase):

-    def setUp(self):
-        self.test = TestCase('name')
-
-    def test_add_test_step(self):
-        self.test.add_step(['Keyword', 'arg1', 'arg2'])
-        assert_equal(len(self.test.steps), 1)
-        assert_equal(self.test.steps[0].keyword, 'Keyword')
-        assert_equal(self.test.steps[0].args, ['arg1', 'arg2'])
+    def test_kw_only(self):
+        self._test(['My kewl keyword'], 'My kewl keyword')
+
+    def test_kw_and_args(self):
+ self._test(['KW', 'first arg', '${a2}'], args=['first arg', '${a2}'])
+
+    def test_assign_to_one_var(self):
+        self._test(['${var}', 'KW'], assign=['${var}'])
+        self._test(['${var}=', 'KW', 'a'], args=['a'], assign=['${var}'])
+        self._test(['@{var}     =', 'KW'], assign=['@{var}'])
+
+    def test_assign_to_multiple_var(self):
+        self._test(['${v1}', '${v2}', '@{v3} =', 'KW', '${a1}', '${a2}'],
+ args=['${a1}', '${a2}'], assign=['${v1}', '${v2}', '@{v3}'])
+        self._test(['${v1}=', '${v2}=', 'KW'], assign=['${v1}', '${v2}'])
+
+    def test_assign_without_keyword(self):
+        self._test(['${v1}', '${v2}'], kw='', assign=['${v1}', '${v2}'])
+
+    def _test(self, content, kw='KW', args=[], assign=[]):
+        step = Step(content)
+        assert_equal(step.keyword, kw)
+        assert_equal(step.args, args)
+        assert_equal(step.assign, assign)


 if __name__ == "__main__":

Reply via email to