Revision: 3311
Author: pekka.klarck
Date: Tue May 18 03:43:02 2010
Log: 1) Settings to separate module, 2) Handle variables with empty value correctly
http://code.google.com/p/robotframework/source/detail?r=3311

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

=======================================
--- /dev/null
+++ /trunk/src/robot/parsing/settings.py        Tue May 18 03:43:02 2010
@@ -0,0 +1,110 @@
+#  Copyright 2008-2009 Nokia Siemens Networks Oyj
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+
+class Setting(object):
+
+    def __init__(self):
+        self.value = []
+
+    def set(self, value):
+        self.value = value
+
+    def _string_value(self, value):
+        return value if isinstance(value, basestring) else ' '.join(value)
+
+
+class Documentation(Setting):
+
+    def __init__(self):
+        self.value = ''
+
+    def set(self, value):
+        self.value = self._string_value(value)
+
+
+class Fixture(Setting):
+
+    def __init__(self):
+        self.name = None
+        self.args = []
+
+    def set(self, value):
+        self.name = value[0] if value else ''
+        self.args = value[1:]
+
+
+class Timeout(Setting):
+
+    def __init__(self):
+        self.value = None
+        self.message = ''
+
+    def set(self, value):
+        self.value = value[0] if value else ''
+        self.message = ' '.join(value[1:])
+
+
+class Tags(Setting):
+    pass
+
+
+class Arguments(Setting):
+    pass
+
+
+class Return(Setting):
+    pass
+
+
+class Metadata(Setting):
+
+    def __init__(self, name, value):
+        self.name = name
+        self.value = self._string_value(value)
+
+
+class Import(Setting):
+
+    def __init__(self, name, args=None, alias=None):
+        self.name = name
+        self.args = args or []
+        self.alias = alias
+
+
+class Library(Import):
+
+    def __init__(self, name, args=None, alias=None):
+        if args and not alias:
+            args, alias = self._split_alias(args)
+        Import.__init__(self, name, args, alias)
+
+    def _split_alias(self, args):
+        if len(args) >= 2 and args[-2].upper() == 'WITH NAME':
+            return args[:-2], args[-1]
+        return args, None
+
+
+class Resource(Import):
+
+    def __init__(self, name, invalid_args=None):
+        if invalid_args:
+            name += ' ' + ' '.join(invalid_args)
+        Import.__init__(self, name)
+
+
+class Variables(Import):
+
+    def __init__(self, name, args=None):
+        Import.__init__(self, name, args)
=======================================
--- /trunk/src/robot/parsing/newmodel.py        Tue May 18 02:39:17 2010
+++ /trunk/src/robot/parsing/newmodel.py        Tue May 18 03:43:02 2010
@@ -14,10 +14,13 @@

 import os

+from robot.errors import DataError
 from robot.variables import is_var
-from readers import Reader
 from robot import utils
-from robot.errors import DataError
+
+from readers import Reader
+from settings import (Documentation, Fixture, Timeout, Tags, Metadata,
+                      Library, Resource, Variables, Arguments, Return)


 class TestCaseFile(object):
@@ -31,11 +34,6 @@
         if source:
             self._populate(source)

-    def __iter__(self):
-        for table in [self.setting_table, self.variable_table,
-                      self.testcase_table, self.keyword_table]:
-            yield table
-
     def _populate(self, path):
         if not os.path.isfile(path):
             raise DataError("Data source '%s' does not exist." % path)
@@ -48,6 +46,11 @@
         finally:
             datafile.close()

+    def __iter__(self):
+        for table in [self.setting_table, self.variable_table,
+                      self.testcase_table, self.keyword_table]:
+            yield table
+

 class DataTable(object):
     pass
@@ -129,108 +132,13 @@
         return iter(self.keywords)


-class Setting(object):
-
-    def __init__(self):
-        self.value = []
-
-    def set(self, value):
-        self.value = value
-
-    def _string_value(self, value):
-        return value if isinstance(value, basestring) else ' '.join(value)
-
-
-class Documentation(Setting):
-
-    def __init__(self):
-        self.value = ''
-
-    def set(self, value):
-        self.value = self._string_value(value)
-
-
-class Fixture(Setting):
-
-    def __init__(self):
-        self.name = None
-        self.args = []
-
-    def set(self, value):
-        self.name = value[0] if value else ''
-        self.args = value[1:]
-
-
-class Timeout(Setting):
-
-    def __init__(self):
-        self.value = None
-        self.message = ''
-
-    def set(self, value):
-        self.value = value[0] if value else ''
-        self.message = ' '.join(value[1:])
-
-
-class Tags(Setting):
-    pass
-
-
-class Arguments(Setting):
-    pass
-
-
-class Return(Setting):
-    pass
-
-
-class Metadata(Setting):
-
-    def __init__(self, name, value):
-        self.name = name
-        self.value = self._string_value(value)
-
-
-class Import(Setting):
-
-    def __init__(self, name, args=None, alias=None):
-        self.name = name
-        self.args = args or []
-        self.alias = alias
-
-
-class Library(Import):
-
-    def __init__(self, name, args=None, alias=None):
-        if args and not alias:
-            args, alias = self._split_alias(args)
-        Import.__init__(self, name, args, alias)
-
-    def _split_alias(self, args):
-        if len(args) >= 2 and args[-2].upper() == 'WITH NAME':
-            return args[:-2], args[-1]
-        return args, None
-
-
-class Resource(Import):
-
-    def __init__(self, name, invalid_args=None):
-        if invalid_args:
-            name += ' ' + ' '.join(invalid_args)
-        Import.__init__(self, name)
-
-
-class Variables(Import):
-
-    def __init__(self, name, args=None):
-        Import.__init__(self, name, args)
-
-
 class Variable(object):

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

=======================================
--- /trunk/utest/parsing/test_model.py  Tue May 18 03:12:06 2010
+++ /trunk/utest/parsing/test_model.py  Tue May 18 03:43:02 2010
@@ -3,6 +3,7 @@

 from robot.utils.asserts import *
 from robot.parsing.newmodel import *
+from robot.parsing.settings import *
 from robot.parsing.txtreader import TxtReader
 import robot.parsing.populator

@@ -147,6 +148,17 @@
         assert_equal(self.table.variables[2].name, '@{LIST}')
         assert_equal(self.table.variables[2].value, ['hello', 'world'])

+    def test_empty_value(self):
+        self.table.add('${V1}', [])
+        self.table.add('${V2}', '')
+        assert_equal(self.table.variables[0].value, [''])
+        assert_equal(self.table.variables[1].value, [''])
+
+    def test_variable_syntax_is_not_verified(self):
+        self.table.add('not var', 'the value')
+        assert_equal(self.table.variables[0].name, 'not var')
+        assert_equal(self.table.variables[0].value, ['the value'])
+

 class TestTestCaseTable(unittest.TestCase):

Reply via email to