Revision: b4d933c497fd
Branch:   default
Author:   Robot Framework Developers ([email protected])
Date:     Thu May 16 02:32:15 2013
Log:      new running: builder for running model
http://code.google.com/p/robotframework/source/detail?r=b4d933c497fd

Added:
 /src/robot/new_running/builder.py
 /utest/new_running/test_builder.py
Modified:
 /src/robot/new_running/__init__.py
 /src/robot/new_running/model.py
 /src/robot/parsing/settings.py

=======================================
--- /dev/null
+++ /src/robot/new_running/builder.py   Thu May 16 02:32:15 2013
@@ -0,0 +1,38 @@
+from robot.parsing import TestData
+
+from .model import TestSuite
+
+
+class TestSuiteBuilder(object):
+
+    def __init__(self):
+        pass
+
+    def build(self, path):
+        data = TestData(source=path)
+        suite = TestSuite(name=data.name,
+                          source=data.source,
+                          doc=data.setting_table.doc.value)
+        for imp in data.setting_table.imports:
+            suite.imports.create(type=imp.type,
+                                 name=imp.name,
+                                 args=tuple(imp.args),
+                                 alias=imp.alias)
+        for test_data in data.testcase_table.tests:
+            test = suite.tests.create(name=test_data.name,
+                                      doc=test_data.doc.value,
+                                      tags=self._get_tags(test_data,
+ data.setting_table))
+            for kw_data in test_data.steps:
+                test.keywords.create(name=kw_data.keyword,
+                                     args=tuple(kw_data.args),
+                                     assign=tuple(kw_data.assign))
+        return suite
+
+    def _get_tags(self, test, settings):
+        tags = test.tags.value
+        defaults = settings.default_tags.value or []
+        forced = settings.force_tags.value or []
+        if tags is None:
+            tags = defaults
+        return tags + forced
=======================================
--- /dev/null
+++ /utest/new_running/test_builder.py  Thu May 16 02:32:15 2013
@@ -0,0 +1,44 @@
+import unittest
+from os.path import abspath, dirname, normpath, join
+
+from robot.utils.asserts import assert_equals, assert_true
+from robot.new_running import TestSuite, TestSuiteBuilder
+
+
+CURDIR = dirname(abspath(__file__))
+DATADIR = normpath(join(CURDIR, '..', '..', 'atest', 'testdata', 'misc'))
+
+
+class TestBuilding(unittest.TestCase):
+
+    def _build(self, path):
+        path = join(DATADIR, path)
+        suite = TestSuiteBuilder().build(path)
+        assert_true(isinstance(suite, TestSuite))
+        assert_equals(suite.source, path)
+        return suite
+
+    def test_suite_data(self):
+        suite = self._build('pass_and_fail.txt')
+        assert_equals(suite.name, 'Pass And Fail')
+        assert_equals(suite.doc, 'Some tests here')
+        assert_equals(suite.metadata, {})
+
+    def test_imports(self):
+        imp = self._build('dummy_lib_test.txt').imports[0]
+        assert_equals(imp.type, 'Library')
+        assert_equals(imp.name, 'DummyLib')
+        assert_equals(imp.args, ())
+
+    def test_test_data(self):
+        test = self._build('pass_and_fail.txt').tests[1]
+        assert_equals(test.name, 'Fail')
+        assert_equals(test.doc, 'FAIL Expected failure')
+        assert_equals(list(test.tags), ['fail', 'force'])
+
+    def test_test_keywords(self):
+        kw = self._build('pass_and_fail.txt').tests[0].keywords[0]
+        assert_equals(kw.name, 'My Keyword')
+        assert_equals(kw.args, ('Pass',))
+        assert_equals(kw.assign, ())
+        assert_equals(kw.type, kw.KEYWORD_TYPE)
=======================================
--- /src/robot/new_running/__init__.py  Mon Apr 22 06:31:58 2013
+++ /src/robot/new_running/__init__.py  Thu May 16 02:32:15 2013
@@ -13,3 +13,4 @@
 #  limitations under the License.

 from .model import TestSuite, TestCase, Keyword
+from .builder import TestSuiteBuilder
=======================================
--- /src/robot/new_running/model.py     Wed May 15 06:52:16 2013
+++ /src/robot/new_running/model.py     Thu May 16 02:32:15 2013
@@ -25,7 +25,7 @@
     __slots__ = ['assign']
     message_class = None  # TODO: Remove from base model?

-    def __init__(self, name='', args=None, assign=None, type='kw'):
+    def __init__(self, name='', args=(), assign=(), type='kw'):
         model.Keyword.__init__(self, name=name, args=args, type=type)
         self.assign = assign

@@ -82,9 +82,9 @@

     # TODO: Should type be verified?
# TODO: Should we have separate methods for adding libs, resources, vars?
-    def __init__(self, type, name, *args):
+    def __init__(self, type, name, args=(), alias=None):
         self.type = type
         self.name = name
         self.args = args
-        self.alias = None
+        self.alias = alias
         self.directory = None
=======================================
--- /src/robot/parsing/settings.py      Fri Dec 14 01:53:50 2012
+++ /src/robot/parsing/settings.py      Thu May 16 02:32:15 2013
@@ -302,6 +302,9 @@
     def __len__(self):
         return len(self.data)

+    def __iter__(self):
+        return iter(self.data)
+

 class ImportList(_DataList):

--

--- 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