Revision: 3307
Author: jprantan
Date: Tue May 18 02:39:17 2010
Log: started integrating new parsing. Build breaker.
http://code.google.com/p/robotframework/source/detail?r=3307

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

=======================================
--- /dev/null
+++ /trunk/src/robot/parsing/readers.py Tue May 18 02:39:17 2010
@@ -0,0 +1,38 @@
+#  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.
+
+from robot.errors import DataError
+
+from htmlreader import HtmlReader
+from tsvreader import TsvReader
+from txtreader import TxtReader
+try:
+    from restreader import RestReader
+except ImportError:
+    def RestReader():
+        raise DataError("Using reStructuredText test data requires having "
+                        "'docutils' module installed.")
+
+
+READERS = {'html': HtmlReader, 'htm': HtmlReader, 'xhtml': HtmlReader,
+           'tsv': TsvReader , 'rst': RestReader, 'rest': RestReader,
+           'txt': TxtReader }
+
+
+def Reader(path):
+    extension = path.split('.')[-1].lower()
+    try:
+        return READERS[extension]()
+    except KeyError:
+        raise DataError("No reader found for extension '%s'" % extension)
=======================================
--- /trunk/src/robot/parsing/newmodel.py        Mon May 17 06:11:53 2010
+++ /trunk/src/robot/parsing/newmodel.py        Tue May 18 02:39:17 2010
@@ -12,7 +12,12 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License.

+import os
+
 from robot.variables import is_var
+from readers import Reader
+from robot import utils
+from robot.errors import DataError


 class TestCaseFile(object):
@@ -23,12 +28,26 @@
         self.variable_table = VariableTable()
         self.testcase_table = TestCaseTable()
         self.keyword_table = KeywordTable()
+        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)
+        try:
+            datafile = open(path, 'rb')
+        except:
+            raise DataError(utils.get_error_message())
+        try:
+            return Reader(path).read(datafile, self)
+        finally:
+            datafile.close()
+

 class DataTable(object):
     pass
=======================================
--- /trunk/src/robot/parsing/tsvreader.py       Mon Apr 12 03:46:44 2010
+++ /trunk/src/robot/parsing/tsvreader.py       Tue May 18 02:39:17 2010
@@ -13,21 +13,24 @@
 #  limitations under the License.

 from codecs import BOM_UTF8
+from populator import TestCaseFilePopulator


 class TsvReader:

-    def read(self, tsvfile, rawdata):
+    def read(self, tsvfile, datafile):
         process = False
+        populator = TestCaseFilePopulator(datafile, tsvfile.name)
         for index, row in enumerate(tsvfile.readlines()):
             if index == 0 and row.startswith(BOM_UTF8):
                 row = row[len(BOM_UTF8):]
cells = [ self._process(cell) for cell in self._split_row(row) ]
             name = cells and cells[0].strip() or ''
- if name.startswith('*') and rawdata.start_table(name.replace('*','')): + if name.startswith('*') and populator.start_table(name.replace('*','')):
                 process = True
             elif process:
-                rawdata.add_row(cells)
+                populator.add(cells)
+        populator.eof()

     def _split_row(self, row):
         return row.rstrip().split('\t')
=======================================
--- /trunk/utest/parsing/test_model.py  Mon May 17 06:08:08 2010
+++ /trunk/utest/parsing/test_model.py  Tue May 18 02:39:17 2010
@@ -1,7 +1,9 @@
 import unittest
+from StringIO import StringIO

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


 class TestTestCaseFile(unittest.TestCase):
@@ -16,6 +18,13 @@
         assert_true(isinstance(self.tcf.testcase_table, TestCaseTable))
         assert_true(isinstance(self.tcf.keyword_table, KeywordTable))

+    def test_integration(self):
+        test_file = StringIO('*** Test Cases *** \ntest  No operation\n')
+        test_file.name = '/tmp/foo.txt'
+        TxtReader().read(test_file, self.tcf)
+        assert_equal(len(self.tcf.testcase_table.tests), 1)
+        assert_equal(self.tcf.testcase_table.tests[0].name, 'test')
+

 class TestSettingTable(unittest.TestCase):

Reply via email to