Revision: 3304
Author: janne.t.harkonen
Date: Tue May 18 02:23:10 2010
Log: process ${CURDIR}
http://code.google.com/p/robotframework/source/detail?r=3304
Modified:
/trunk/src/robot/parsing/populator.py
/trunk/utest/parsing/test_populator.py
=======================================
--- /trunk/src/robot/parsing/populator.py Tue May 18 01:59:40 2010
+++ /trunk/src/robot/parsing/populator.py Tue May 18 02:23:10 2010
@@ -13,10 +13,15 @@
# limitations under the License.
import re
+import os
from robot import utils
+# Hook for external tools for altering ${CURDIR} processing
+PROCESS_CURDIR = True
+
+
class Populator(object):
"""Explicit interface for all populators."""
def add(self, row): raise NotImplementedError()
@@ -292,6 +297,7 @@
self._datafile = datafile
self._datafile.source = path
self._current_populator = self._null_populator
+ self._curdir = os.path.dirname(self._datafile.source)
def start_table(self, name):
try:
@@ -307,10 +313,15 @@
self.populate()
def add(self, row):
+ if PROCESS_CURDIR:
+ row = self._replace_curdirs_in(row)
data = DataRow(row)
if data:
self._current_populator.add(data)
+ def _replace_curdirs_in(self, row):
+ return [cell.replace('${CURDIR}', self._curdir) for cell in row]
+
class DataRow(object):
_whitespace_regexp = re.compile('\s+')
=======================================
--- /trunk/utest/parsing/test_populator.py Tue May 18 01:10:22 2010
+++ /trunk/utest/parsing/test_populator.py Tue May 18 02:23:10 2010
@@ -9,7 +9,7 @@
def setUp(self):
self._datafile = TestCaseFile()
- self._path = '/path/to/source'
+ self._path = '/path/to/source.txt'
self._populator = TestCaseFilePopulator(self._datafile, self._path)
def test_creation(self):
@@ -170,6 +170,20 @@
assert_equals(uk.args.value, ['${foo}', '${bar}'])
assert_equals(uk.return_.value, ['ankka', 'kameli'])
+ def test_curdir_handling(self):
+ self._create_table('Test cases', [['My test name'],
+ ['', 'Log', '${CURDIR}']])
+ assert_equals(self._first_test().steps[0].args, ['/path/to'])
+
+ def test_turn_off_curdir_handling(self):
+ from robot.parsing import populator
+ populator.PROCESS_CURDIR = False
+ self.setUp()
+ self._create_table('Test cases', [['My test name'],
+ ['', 'Log', '${CURDIR}']])
+ assert_equals(self._first_test().steps[0].args, ['${CURDIR}'])
+ populator.PROCESS_CURDIR = True
+
def test_whitespace_is_ignored(self):
self._create_table('Test Cases', [['My test'],
[' ', '[Tags]', 'foo', ' \t '],