Revision: 3318
Author: pekka.klarck
Date: Tue May 18 05:28:18 2010
Log: move reading/populating logic fully away from model
http://code.google.com/p/robotframework/source/detail?r=3318
Added:
/trunk/src/robot/parsing/datareader.py
Deleted:
/trunk/src/robot/parsing/readers.py
Modified:
/trunk/src/robot/parsing/htmlreader.py
/trunk/src/robot/parsing/newmodel.py
/trunk/src/robot/parsing/populator.py
/trunk/src/robot/parsing/tsvreader.py
/trunk/utest/parsing/test_model.py
=======================================
--- /dev/null
+++ /trunk/src/robot/parsing/datareader.py Tue May 18 05:28:18 2010
@@ -0,0 +1,55 @@
+# 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.
+
+import os
+
+from robot.errors import DataError
+from robot import utils
+
+from populator import TestDataPopulator
+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)
+
+
+def read_data(path, datafile):
+ if not os.path.isfile(path):
+ raise DataError("Data source '%s' does not exist." % path)
+ try:
+ source = open(path, 'rb')
+ except:
+ raise DataError(utils.get_error_message())
+ try:
+ Reader(path).read(source, TestDataPopulator(datafile))
+ finally:
+ source.close()
=======================================
--- /trunk/src/robot/parsing/readers.py Tue May 18 02:39:17 2010
+++ /dev/null
@@ -1,38 +0,0 @@
-# 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/htmlreader.py Tue May 18 04:14:11 2010
+++ /trunk/src/robot/parsing/htmlreader.py Tue May 18 05:28:18 2010
@@ -17,14 +17,11 @@
from htmlentitydefs import entitydefs
from robot import utils
-from populator import TestDataPopulator
extra_entitydefs = {'nbsp': ' ', 'apos': "'", 'tilde': '~'}
class HtmlReader(HTMLParser.HTMLParser):
-
- # States
IGNORE = 0
INITIAL = 1
PROCESS = 2
@@ -43,8 +40,8 @@
'br_start' : self.br_start,
'meta_start' : self.meta_start }
- def read(self, htmlfile, datafile):
- self.populator = TestDataPopulator(datafile)
+ def read(self, htmlfile, populator):
+ self.populator = populator
self.state = self.IGNORE
self.current_row = None
self.current_cell = None
=======================================
--- /trunk/src/robot/parsing/newmodel.py Tue May 18 05:02:19 2010
+++ /trunk/src/robot/parsing/newmodel.py Tue May 18 05:28:18 2010
@@ -12,15 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import os
-
from robot.errors import DataError
from robot.variables import is_var
-from robot import utils
-
-from readers import Reader
+
from settings import (Documentation, Fixture, Timeout, Tags, Metadata,
Library, Resource, Variables, Arguments, Return)
+from datareader import read_data
class TestCaseFile(object):
@@ -32,19 +29,7 @@
self.testcase_table = TestCaseTable()
self.keyword_table = KeywordTable()
if source:
- self._populate(source)
-
- 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()
+ read_data(source, self)
def __iter__(self):
for table in [self.setting_table, self.variable_table,
=======================================
--- /trunk/src/robot/parsing/populator.py Tue May 18 04:01:37 2010
+++ /trunk/src/robot/parsing/populator.py Tue May 18 05:28:18 2010
@@ -334,7 +334,7 @@
self._current_populator.populate()
def add(self, row):
- if PROCESS_CURDIR:
+ if PROCESS_CURDIR and self._curdir:
row = self._replace_curdirs_in(row)
data = DataRow(row)
if data:
=======================================
--- /trunk/src/robot/parsing/tsvreader.py Tue May 18 03:12:06 2010
+++ /trunk/src/robot/parsing/tsvreader.py Tue May 18 05:28:18 2010
@@ -13,14 +13,12 @@
# limitations under the License.
from codecs import BOM_UTF8
-from populator import TestDataPopulator
class TsvReader:
- def read(self, tsvfile, datafile):
+ def read(self, tsvfile, populator):
process = False
- populator = TestDataPopulator(datafile)
for index, row in enumerate(tsvfile.readlines()):
if index == 0 and row.startswith(BOM_UTF8):
row = row[len(BOM_UTF8):]
=======================================
--- /trunk/utest/parsing/test_model.py Tue May 18 03:43:02 2010
+++ /trunk/utest/parsing/test_model.py Tue May 18 05:28:18 2010
@@ -5,20 +5,15 @@
from robot.parsing.newmodel import *
from robot.parsing.settings import *
from robot.parsing.txtreader import TxtReader
-import robot.parsing.populator
+from robot.parsing.populator import TestDataPopulator
class TestTestCaseFile(unittest.TestCase):
def setUp(self):
self.tcf = TestCaseFile()
- self._orig_curdir = robot.parsing.populator.PROCESS_CURDIR
- robot.parsing.populator.PROCESS_CURDIR = False
-
- def tearDown(self):
- robot.parsing.populator.PROCESS_CURDIR = self._orig_curdir
-
- def test_create(self):
+
+ def test_init(self):
assert_none(self.tcf.source)
assert_true(isinstance(self.tcf.setting_table, SettingTable))
assert_true(isinstance(self.tcf.variable_table, VariableTable))
@@ -26,10 +21,10 @@
assert_true(isinstance(self.tcf.keyword_table, KeywordTable))
def test_integration(self):
- test_file = StringIO('*** Test Cases *** \ntest No operation\n')
- TxtReader().read(test_file, self.tcf)
+ test_file = StringIO('*** Test Cases *** \nMy test No
operation\n')
+ TxtReader().read(test_file, TestDataPopulator(self.tcf))
assert_equal(len(self.tcf.testcase_table.tests), 1)
- assert_equal(self.tcf.testcase_table.tests[0].name, 'test')
+ assert_equal(self.tcf.testcase_table.tests[0].name, 'My test')
class TestSettingTable(unittest.TestCase):
@@ -37,7 +32,7 @@
def setUp(self):
self.table = TestCaseFile().setting_table
- def test_create(self):
+ def test_init(self):
assert_true(isinstance(self.table.doc, Documentation))
assert_true(isinstance(self.table.suite_setup, Fixture))
assert_true(isinstance(self.table.suite_teardown, Fixture))
@@ -133,7 +128,7 @@
def setUp(self):
self.table = TestCaseFile().variable_table
- def test_create(self):
+ def test_init(self):
assert_equal(self.table.variables, [])
def test_add_variables(self):
@@ -166,7 +161,7 @@
self.table = TestCaseFile().testcase_table
self.test = TestCase('name')
- def test_create(self):
+ def test_init(self):
assert_equal(self.table.tests, [])
def test_add_test(self):
@@ -205,7 +200,7 @@
self.table = TestCaseFile().keyword_table
self.kw = UserKeyword('name')
- def test_create(self):
+ def test_init(self):
assert_equal(self.table.keywords, [])
def test_add_keyword(self):