Revision: 3415
Author: jussi.ao.malinen
Date: Mon May 24 05:10:22 2010
Log: support saving table headers
http://code.google.com/p/robotframework/source/detail?r=3415
Modified:
/trunk/src/robot/parsing/datareader.py
/trunk/src/robot/parsing/htmlreader.py
/trunk/src/robot/parsing/model.py
/trunk/src/robot/parsing/populator.py
/trunk/src/robot/parsing/tsvreader.py
/trunk/utest/parsing/test_htmlreader.py
/trunk/utest/parsing/test_populator.py
/trunk/utest/parsing/test_tsvreader.py
=======================================
--- /trunk/src/robot/parsing/datareader.py Sun May 23 23:13:54 2010
+++ /trunk/src/robot/parsing/datareader.py Mon May 24 05:10:22 2010
@@ -82,10 +82,11 @@
except KeyError:
raise DataError("No reader found for extension '%s'." %
extension)
- def start_table(self, name):
+ def start_table(self, header):
self._current_populator.populate()
+ header = DataRow(header)
try:
- self._current_populator = self.populators[name](self._datafile)
+ self._current_populator =
self.populators[header.head](self._datafile, header.all)
except KeyError:
self._current_populator = self._null_populator
return self._current_populator is not self._null_populator
@@ -112,7 +113,6 @@
def __init__(self, cells):
self.cells, self.comments = self._parse(cells)
-
@property
def head(self):
return self.cells[0] if self.cells else None
=======================================
--- /trunk/src/robot/parsing/htmlreader.py Tue May 18 05:28:18 2010
+++ /trunk/src/robot/parsing/htmlreader.py Mon May 24 05:10:22 2010
@@ -127,8 +127,7 @@
self.td_end()
if self.state == self.INITIAL:
if len(self.current_row) > 0:
- table_name = self.current_row[0]
- if self.populator.start_table(table_name):
+ if self.populator.start_table(self.current_row):
self.state = self.PROCESS
else:
self.state = self.IGNORE
=======================================
--- /trunk/src/robot/parsing/model.py Mon May 24 04:58:12 2010
+++ /trunk/src/robot/parsing/model.py Mon May 24 05:10:22 2010
@@ -113,8 +113,16 @@
class _Table(object):
+ @property
+ def name(self):
+ return self.header[0]
+
def __init__(self, parent):
self.parent = parent
+ self.header = None
+
+ def set_header(self, header):
+ self.header = header
@property
def source(self):
@@ -125,9 +133,7 @@
return self.parent.directory
def report_invalid_syntax(self, message, level='ERROR'):
- # TODO: Use the real table name here when headers are available
- table = type(self).__name__.replace('Table', '')
- self.parent.report_invalid_syntax(table, message, level)
+ self.parent.report_invalid_syntax(self.name, message, level)
class _WithSettings(object):
=======================================
--- /trunk/src/robot/parsing/populator.py Mon May 24 04:42:22 2010
+++ /trunk/src/robot/parsing/populator.py Mon May 24 05:10:22 2010
@@ -44,8 +44,9 @@
class _TablePopulator(Populator):
- def __init__(self, datafile):
+ def __init__(self, datafile, header):
self._table = self._get_table(datafile)
+ self._table.set_header(header)
self._populator = NullPopulator()
self._comments = CommentCacher()
=======================================
--- /trunk/src/robot/parsing/tsvreader.py Tue May 18 05:28:18 2010
+++ /trunk/src/robot/parsing/tsvreader.py Mon May 24 05:10:22 2010
@@ -24,7 +24,7 @@
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
populator.start_table(name.replace('*','')):
+ if name.startswith('*') and populator.start_table([
c.replace('*','') for c in cells ]):
process = True
elif process:
populator.add(cells)
=======================================
--- /trunk/utest/parsing/test_htmlreader.py Thu May 20 06:30:57 2010
+++ /trunk/utest/parsing/test_htmlreader.py Mon May 24 05:10:22 2010
@@ -16,7 +16,8 @@
self.tables = {}
self.current = None
- def start_table(self, name):
+ def start_table(self, header):
+ name = header[0]
if name in VALID_TABLES:
self.tables[name] = []
self.current = name
=======================================
--- /trunk/utest/parsing/test_populator.py Mon May 24 04:42:33 2010
+++ /trunk/utest/parsing/test_populator.py Mon May 24 05:10:22 2010
@@ -22,6 +22,8 @@
class _PopulatorTest(unittest.TestCase):
def _start_table(self, name):
+ if isinstance(name, basestring):
+ name = [name]
return self._populator.start_table(name)
def _create_table(self, name, rows, eof=True):
@@ -97,6 +99,13 @@
for name in ['Test Cases', ' variables ', 'K E Y WO R D S']:
assert_true(self._start_table(name))
+ def test_table_headers(self):
+ header_list = ['seTTINGS', 'header', 'again']
+ self._create_table(header_list,[])
+ setting_table = self._datafile.setting_table
+ assert_equals(setting_table.header, header_list)
+ assert_equals(setting_table.name, header_list[0])
+
def test_starting_invalid_table(self):
assert_false(self._start_table('Per Se'))
@@ -327,16 +336,6 @@
assert_equals(len(self._datafile.testcase_table.tests), 1)
assert_equals(len(self._nth_uk(0).steps), 1)
- def _start_table(self, name):
- return self._populator.start_table(name)
-
- def _create_table(self, name, rows, eof=True):
- self._start_table(name)
- for r in rows:
- self._populator.add(r)
- if eof:
- self._populator.eof()
-
def _nth_uk(self, index):
return self._datafile.keyword_table.keywords[index]
=======================================
--- /trunk/utest/parsing/test_tsvreader.py Fri May 21 05:30:38 2010
+++ /trunk/utest/parsing/test_tsvreader.py Mon May 24 05:10:22 2010
@@ -23,7 +23,7 @@
robot.parsing.datareader.PROCESS_CURDIR = self._orig_curdir
def test_start_table(self):
- tsv = StringIO('''*Setting*\t*Value*\t*V*
+ tsv = StringIO('''*SettING*\t* Value *\t*V*
***Variable
*Not*Table*
@@ -33,7 +33,8 @@
*******************T*e*s*t*********C*a*s*e************\t***********\t******\t*
''')
TsvReader().read(tsv, FromFilePopulator(self.tcf))
- assert_false(True, "Need to add checks after new model supports
table names")
+ assert_equals(self.tcf.setting_table.name, 'SettING')
+ assert_equals(self.tcf.setting_table.header,
['SettING','Value','V'])
def test_rows(self):
tsv = StringIO('''Ignored text before tables...