Revision: 3342
Author: jprantan
Date: Thu May 20 02:57:56 2010
Log: Added table attribute to all settings.
http://code.google.com/p/robotframework/source/detail?r=3342

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

=======================================
--- /trunk/src/robot/parsing/settings.py        Wed May 19 05:06:11 2010
+++ /trunk/src/robot/parsing/settings.py        Thu May 20 02:57:56 2010
@@ -13,11 +13,15 @@
 #  limitations under the License.


-class Setting(object):
-
-    def __init__(self):
+class _Setting(object):
+
+    def __init__(self, table=None, comment=None):
+        self.table = table
+        self.comment = comment
+        self._init()
+
+    def _init(self):
         self.value = []
-        self.comment = ''

     def set(self, value, comment=None):
         self._set(value)
@@ -30,18 +34,18 @@
         return value if isinstance(value, basestring) else ' '.join(value)


-class Documentation(Setting):
-
-    def __init__(self):
+class Documentation(_Setting):
+
+    def _init(self):
         self.value = ''

     def _set(self, value):
         self.value = self._string_value(value)


-class Fixture(Setting):
-
-    def __init__(self):
+class Fixture(_Setting):
+
+    def _init(self):
         self.name = None
         self.args = []

@@ -50,9 +54,9 @@
         self.args = value[1:]


-class Timeout(Setting):
-
-    def __init__(self):
+class Timeout(_Setting):
+
+    def _init(self):
         self.value = None
         self.message = ''

@@ -61,29 +65,31 @@
         self.message = ' '.join(value[1:])


-class Tags(Setting):
+class Tags(_Setting):
     pass


-class Arguments(Setting):
+class Arguments(_Setting):
     pass


-class Return(Setting):
+class Return(_Setting):
     pass


-class Metadata(Setting):
-
-    def __init__(self, name, value, comment):
+class Metadata(_Setting):
+
+    def __init__(self, table, name, value, comment):
+        self.table = table
         self.name = name
         self.value = self._string_value(value)
         self.comment = comment


-class Import(Setting):
-
-    def __init__(self, name, args=None, alias=None, comment=None):
+class _Import(_Setting):
+
+    def __init__(self, table, name, args=None, alias=None, comment=None):
+        self.table = table
         self.name = name
         self.args = args or []
         self.alias = alias
@@ -94,12 +100,12 @@
         return type(self).__name__


-class Library(Import):
-
-    def __init__(self, name, args=None, alias=None, comment=None):
+class Library(_Import):
+
+    def __init__(self, table, name, args=None, alias=None, comment=None):
         if args and not alias:
             args, alias = self._split_alias(args)
-        Import.__init__(self, name, args, alias, comment)
+        _Import.__init__(self, table, name, args, alias, comment)

     def _split_alias(self, args):
         if len(args) >= 2 and args[-2].upper() == 'WITH NAME':
@@ -107,15 +113,15 @@
         return args, None


-class Resource(Import):
-
-    def __init__(self, name, invalid_args=None, comment=None):
+class Resource(_Import):
+
+    def __init__(self, table, name, invalid_args=None, comment=None):
         if invalid_args:
             name += ' ' + ' '.join(invalid_args)
-        Import.__init__(self, name, comment=comment)
+        _Import.__init__(self, table, name, comment=comment)


-class Variables(Import):
-
-    def __init__(self, name, args=None, comment=None):
-        Import.__init__(self, name, args, comment=comment)
+class Variables(_Import):
+
+    def __init__(self, table, name, args=None, comment=None):
+        _Import.__init__(self, table, name, args, comment=comment)
=======================================
--- /trunk/utest/parsing/test_model.py  Wed May 19 06:35:22 2010
+++ /trunk/utest/parsing/test_model.py  Thu May 20 02:57:56 2010
@@ -4,6 +4,7 @@
 from robot.utils.asserts import *
 from robot.parsing.newmodel import *
 from robot.parsing.settings import *
+from robot.parsing.settings import _Import
 from robot.parsing.txtreader import TxtReader
 from robot.parsing.populator import TestDataPopulator

@@ -117,7 +118,7 @@
self._verify_import(self.table.add_library('N2', ['1', '2', '3', '4']),
                             'N2', ['1', '2', '3', '4'])
         assert_equal(len(self.table.imports), 5)
- assert_true(all(isinstance(im, Import) for im in self.table.imports)) + assert_true(all(isinstance(im, _Import) for im in self.table.imports))

     def test_resource_with_invalid_args(self):
         reso = self.table.add_resource('reso.txt', ['invalid', 'args'])

Reply via email to