Revision: 3858
Author: janne.t.harkonen
Date: Mon Aug 23 00:53:52 2010
Log: Reorg
http://code.google.com/p/robotframework/source/detail?r=3858
Modified:
/trunk/utest/parsing/test_populator.py
=======================================
--- /trunk/utest/parsing/test_populator.py Thu Aug 19 03:09:58 2010
+++ /trunk/utest/parsing/test_populator.py Mon Aug 23 00:53:52 2010
@@ -30,6 +30,10 @@
self._console_logger = LOGGER._loggers.pop(0)
LOGGER.register_logger(self._logger)
+ def tearDown(self):
+ LOGGER.unregister_logger(self._logger)
+ LOGGER._loggers.insert(0, self._console_logger)
+
def _assert_no_parsing_errors(self):
assert_true(self._logger.value() == '', self._logger.value())
@@ -70,6 +74,10 @@
assert_equals(meta.value, exp_value)
self._assert_comment(meta, exp_comment)
+ def _assert_tags(self, tag_name, exp_value):
+ tag = self._setting_with(tag_name)
+ assert_equals(tag.value, exp_value)
+
def _assert_variable(self, index, exp_name, exp_value,
exp_comment=None):
var = self._datafile.variable_table.variables[index]
assert_equals(var.name, exp_name)
@@ -89,15 +97,14 @@
def _first_test(self):
return self._nth_test(1)
+ def _nth_uk(self, index):
+ return self._datafile.keyword_table.keywords[index-1]
+
def _number_of_steps_should_be(self, test, expected_steps):
assert_equals(len(test.steps), expected_steps)
-class TestCaseFilePopulatingTest(_PopulatorTest):
-
- def tearDown(self):
- LOGGER.unregister_logger(self._logger)
- LOGGER._loggers.insert(0, self._console_logger)
+class TablePopulatorTest(_PopulatorTest):
def test_starting_valid_table(self):
for name in ['Test Cases', ' variables ', 'K E Y WO R D S']:
@@ -116,7 +123,58 @@
def test_adding_empty_row_should_not_fail(self):
self._create_table('Settings', [[]])
- def test_adding_settings(self):
+ def test_curdir_handling(self):
+ self._create_table('Test cases', [['My test name'],
+ ['', 'Log', '${CURDIR}']])
+ assert_equals(self._first_test().steps[0].args,
+ [self._datafile.directory])
+
+ def test_turn_off_curdir_handling(self):
+ from robot.parsing import populators
+ populators.PROCESS_CURDIR = False
+ self.setUp()
+ self._create_table('Test cases', [['My test name'],
+ ['', 'Log', '${CURDIR}']])
+ assert_equals(self._first_test().steps[0].args, ['${CURDIR}'])
+ populators.PROCESS_CURDIR = True
+
+ def test_whitespace_is_ignored(self):
+ self._create_table('Test Cases', [['My test'],
+ [' ', '[Tags]', 'foo', ' \t '],
+ [' '],
+ [ '\t'],
+ ['', 'Log Many', '', 'argh']])
+ test = self._first_test()
+ assert_equals(test.name, 'My test')
+ self._number_of_steps_should_be(test, 1)
+ assert_equals(test.tags.value, ['foo'])
+
+ def test_escaping_empty_cells(self):
+ self._create_table('Settings', [['Documentation', '\\']],)
+ self._assert_setting('doc', '')
+ self._create_table('Test cases', [['test',
+ '', 'Log Many', 'foo', '\\']],)
+ assert_equals(self._first_test().steps[0].args, ['Log
Many', 'foo', ''])
+
+ def test_populator_happy_path_workflow(self):
+ self._create_table('settings', [['Library', 'FooBarness']],
eof=False)
+ self._create_table('Variables', [['${scalar}', 'value']],
eof=False)
+ self._create_table('Test cases', [['My test name'],
+ ['', 'Log', 'quux']], eof=False)
+ self._create_table('More cases', [['My other test name'],
+ ['', 'Log', 'foox']], eof=False)
+ self._create_table('Keywords', [['My User Keyword'],
+ ['', 'Foo', 'Bar']], eof=False)
+ self._populator.eof()
+ self._assert_import(0, 'FooBarness', [])
+ assert_equals(len(self._datafile.variable_table.variables), 1)
+ assert_equals(len(self._datafile.testcase_table.tests), 1)
+ assert_equals(len(self._nth_uk(1).steps), 1)
+
+
+class SettingTablePopulatingTest(_PopulatorTest):
+
+ def test_testcasefile_settings(self):
doc = 'This is doc'
template = 'Foo'
more_doc = 'smore'
@@ -149,7 +207,24 @@
assert_equals(timeout.message, 'timeout message '+more_doc)
self._assert_setting('test_template', template)
- def test_line_continuation_in_setting_table(self):
+ def test_imports(self):
+ self._create_table('settings', [['Library', 'FooBarness'],
+
['Library', 'BarFooness', 'arg1', 'arg2'],
+ ['Resource', 'QuuxNess.txt'],
+ ['Variables', 'varzors.py']])
+ assert_equals(len(self._datafile.setting_table.imports), 4)
+ self._assert_import(0, 'FooBarness', [])
+ self._assert_import(1, 'BarFooness', ['arg1', 'arg2'])
+ self._assert_import(2, 'QuuxNess.txt', [])
+ self._assert_import(3, 'varzors.py', [])
+
+ def test_free_suite_metadata(self):
+ self._create_table('settings', [['Meta: Foon:ess', 'Barness'],
+ ['Metadata', 'Quux', 'Value']])
+ self._assert_meta(0, 'Foon:ess', 'Barness')
+ self._assert_meta(1, 'Quux', 'Value')
+
+ def test_line_continuation(self):
self._create_table('Settings', [['Documentation', 'doc'],
['...', 'in two lines'],
['Force Tags', 'one', 'two'],
@@ -158,66 +233,22 @@
self._assert_setting('doc', 'doc in two lines')
self._assert_setting('force_tags', ['one', 'two', 'three'])
- def _assert_tags(self, tag_name, exp_value):
- tag = self._setting_with(tag_name)
- assert_equals(tag.value, exp_value)
-
def test_invalid_settings(self):
self._create_table('Settings', [['In valid', 'val ue']])
assert_equals(self._logger.value(), "Invalid syntax in file 'None'
in "
"table 'Settings':
Non-existing "
"setting 'In valid'.")
- def test_continuing_in_the_begining_of_the_setting_table(self):
+ def test_continuing_in_the_begining_of_the_table(self):
self._create_table('Settings', [['...']])
assert_equals(self._logger.value(), "Invalid syntax in file 'None'
in "
"table 'Settings':
Non-existing "
"setting '...'.")
- def test_continuing_in_the_begining_of_the_variable_table(self):
- self._create_table('Variables', [['...', 'val']])
- self._assert_variable(0, '...', ['val'])
-
- def test_continuing_in_the_begining_of_the_testcase_table(self):
- self._create_table('test cases', [['...', 'foo']])
- assert_equals(self._first_test().name, '...')
-
- def test_unnamed_testcase(self):
- self._create_table('test cases', [['', 'foo', '#comment'],
- ['', '[documentation]', "What's
up doc?"]])
- test = self._first_test()
- assert_equals(test.name, '')
- assert_equals(test.doc.value, "What's up doc?")
- assert_equals(test.steps[0].comment, 'comment')
-
- def test_unnamed_test_and_line_continuation(self):
- self._create_table('test cases', [['', '...', 'foo', '#comment']])
- assert_equals(self._first_test().name, '')
- assert_equals(self._first_test().steps[0].keyword, 'foo')
- assert_equals(self._first_test().steps[0].comment, 'comment')
-
- def test_continuing_in_the_begining_of_the_keyword_table(self):
- self._create_table('keywords', [['...', 'foo']])
- assert_equals(self._nth_uk(1).name, '...')
-
- def test_adding_import(self):
- self._create_table('settings', [['Library', 'FooBarness'],
-
['Library', 'BarFooness', 'arg1', 'arg2'],
- ['Resource', 'QuuxNess.txt'],
- ['Variables', 'varzors.py']])
- assert_equals(len(self._datafile.setting_table.imports), 4)
- self._assert_import(0, 'FooBarness', [])
- self._assert_import(1, 'BarFooness', ['arg1', 'arg2'])
- self._assert_import(2, 'QuuxNess.txt', [])
- self._assert_import(3, 'varzors.py', [])
-
- def test_suite_metadata(self):
- self._create_table('settings', [['Meta: Foon:ess', 'Barness'],
- ['Metadata', 'Quux', 'Value']])
- self._assert_meta(0, 'Foon:ess', 'Barness')
- self._assert_meta(1, 'Quux', 'Value')
-
- def test_adding_variables(self):
+
+class VariableTablePopulatingTest(_PopulatorTest):
+
+ def test_populating_variables(self):
self._create_table('Variables', [['${scalar}', 'value'],
['${slist}', '[s, o, m, e]'],
['@{list}', 'v1', 'v2', 'v3', 'v4']])
@@ -226,13 +257,20 @@
self._assert_variable(1, '${slist}', ['[s, o, m, e]'])
self._assert_variable(2, '@{list}', ['v1', 'v2', 'v3', 'v4'])
- def test_line_continuation_in_variable_table(self):
+ def test_line_continuation(self):
self._create_table('Variables', [['@{list}'],
['...', 'v1'],
['', '...', 'v2'],
['', '', '...', 'v3', 'v4']])
self._assert_variable(0, '@{list}', ['v1', 'v2', 'v3', 'v4'])
+ def test_continuing_in_the_begining_of_the_table(self):
+ self._create_table('Variables', [['...', 'val']])
+ self._assert_variable(0, '...', ['val'])
+
+
+
+class TestCaseTablePopulatingTest(_PopulatorTest):
def test_test_case_populating(self):
self._create_table('Test cases', [['My test name'],
@@ -249,7 +287,11 @@
self._create_table('Test cases', [['My test name', 'No
Operation']])
assert_equals(len(self._first_test().steps), 1)
- def test_line_continuation_in_test(self):
+ def test_continuing_in_the_begining_of_the_table(self):
+ self._create_table('test cases', [['...', 'foo']])
+ assert_equals(self._first_test().name, '...')
+
+ def test_line_continuation(self):
self._create_table('Test cases', [['My test name', 'Log
Many', 'foo'],
['', '...', 'bar', 'quux'],
['Another test'],
@@ -262,55 +304,19 @@
assert_equals(self._nth_test(2).steps[0].keyword, 'Log Many')
assert_equals(self._nth_test(2).steps[0].args,
['quux', 'fooness', 'and more'])
- def test_for_loop(self):
- self._create_table('Test cases', [['For loop test'],
-
['', ':FOR', '${i}', 'IN', '@{list}'],
- ['', '', 'Log', '${i}']])
- assert_equals(len(self._first_test().steps), 1)
- for_loop = self._first_test().steps[0]
- assert_equals(len(for_loop.steps), 1)
- assert_true(not for_loop.range)
- assert_equals(for_loop.vars, ['${i}'])
- assert_equals(for_loop.items, ['@{list}'])
-
- def test_in_range_for_loop(self):
- self._create_table('Test cases', [['For loop test'],
- ['', 'Log', 'Before FOR'],
- ['', ':
for', '${i}', '${j}', 'IN RANGE', '10'],
- ['', '', 'Log', '${i}'],
- ['', '', 'Fail', '${j}'],
- ['', 'Log', 'Outside FOR']])
- assert_equals(len(self._first_test().steps), 3)
- for_loop = self._first_test().steps[1]
- assert_equals(len(for_loop.steps), 2)
- assert_true(for_loop.range)
- assert_equals(for_loop.vars, ['${i}', '${j}'])
-
- def test_line_continuation_in_for_loop(self):
- self._create_table('Test cases', [['Malicious for loop test'],
- ['', 'Log', 'Before FOR'],
- ['', '::::
fOr', '${i}', 'IN', '10'],
- ['', '...', '20'],
- ['', '', '...', '30', '40'],
- ['', '', '', '...', '50', '60'],
- ['', '', 'Log Many', '${i}'],
- ['', '', '...', '${i}'],
- ['', '...', '${i}'],
- ['', 'Log', 'Outside FOR']])
- assert_equals(len(self._first_test().steps), 3)
- for_loop = self._first_test().steps[1]
- assert_equals(len(for_loop.steps), 1)
- assert_true(not for_loop.range)
- assert_equals(for_loop.vars, ['${i}'])
- assert_equals(for_loop.items, ['10', '20', '30', '40', '50', '60'])
-
- def test_for_loop_with_empty_body(self):
- self._create_table('Test cases', [['For loop test'],
-
['', ':FOR ', '${var}', 'IN', 'foo'],
- ['', 'Log', 'outside FOR']])
+ def test_unnamed_testcase(self):
+ self._create_table('test cases', [['', 'foo', '#comment'],
+ ['', '[documentation]', "What's
up doc?"]])
test = self._first_test()
- assert_equals(len(test.steps), 2)
- assert_equals(test.steps[0].steps, [])
+ assert_equals(test.name, '')
+ assert_equals(test.doc.value, "What's up doc?")
+ assert_equals(test.steps[0].comment, 'comment')
+
+ def test_unnamed_test_and_line_continuation(self):
+ self._create_table('test cases', [['', '...', 'foo', '#comment']])
+ assert_equals(self._first_test().name, '')
+ assert_equals(self._first_test().steps[0].keyword, 'foo')
+ assert_equals(self._first_test().steps[0].comment, 'comment')
def test_test_settings(self):
doc = 'This is domumentation for the test case'
@@ -341,15 +347,10 @@
test = self._first_test()
assert_equals(test.template.value, test_test_template)
- def test_invalid_keyword_settings(self):
- self._create_table('Keywords', [['My User Keyword'],
- ['', '[ank ka]']])
- assert_equals(self._logger.value(), "Invalid syntax in file 'None'
in "
- "table 'Keywords': Invalid
syntax "
- "in keyword 'My User
Keyword': "
- "Non-existing setting 'ank
ka'.")
-
- def test_creating_user_keywords(self):
+
+class UserKeywordTablePopulatingTest(_PopulatorTest):
+
+ def test_user_keyword_populating(self):
self._create_table('Keywords', [['My User Keyword'],
['', '[Arguments]', '${foo}', '${bar}'],
['', 'Log Many', '${foo}'],
@@ -361,56 +362,71 @@
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,
- [self._datafile.directory])
-
- def test_turn_off_curdir_handling(self):
- from robot.parsing import populators
- populators.PROCESS_CURDIR = False
- self.setUp()
- self._create_table('Test cases', [['My test name'],
- ['', 'Log', '${CURDIR}']])
- assert_equals(self._first_test().steps[0].args, ['${CURDIR}'])
- populators.PROCESS_CURDIR = True
-
- def test_whitespace_is_ignored(self):
- self._create_table('Test Cases', [['My test'],
- [' ', '[Tags]', 'foo', ' \t '],
- [' '],
- [ '\t'],
- ['', 'Log Many', '', 'argh']])
- test = self._first_test()
- assert_equals(test.name, 'My test')
- self._number_of_steps_should_be(test, 1)
- assert_equals(test.tags.value, ['foo'])
-
- def test_escaping_empty_cells(self):
- self._create_table('Settings', [['Documentation', '\\']],)
- self._assert_setting('doc', '')
- self._create_table('Test cases', [['test',
- '', 'Log Many', 'foo', '\\']],)
- assert_equals(self._first_test().steps[0].args, ['Log
Many', 'foo', ''])
-
- def test_populator_happy_path_workflow(self):
- self._create_table('settings', [['Library', 'FooBarness']],
eof=False)
- self._create_table('Variables', [['${scalar}', 'value']],
eof=False)
- self._create_table('Test cases', [['My test name'],
- ['', 'Log', 'quux']], eof=False)
- self._create_table('More cases', [['My other test name'],
- ['', 'Log', 'foox']], eof=False)
- self._create_table('Keywords', [['My User Keyword'],
- ['', 'Foo', 'Bar']], eof=False)
- self._populator.eof()
- self._assert_import(0, 'FooBarness', [])
- assert_equals(len(self._datafile.variable_table.variables), 1)
- assert_equals(len(self._datafile.testcase_table.tests), 1)
- assert_equals(len(self._nth_uk(1).steps), 1)
-
- def _nth_uk(self, index):
- return self._datafile.keyword_table.keywords[index-1]
+ def test_continuing_in_the_begining_of_the_table(self):
+ self._create_table('keywords', [['...', 'foo']])
+ assert_equals(self._nth_uk(1).name, '...')
+
+ def test_invalid_keyword_settings(self):
+ self._create_table('Keywords', [['My User Keyword'],
+ ['', '[ank ka]']])
+ assert_equals(self._logger.value(), "Invalid syntax in file 'None'
in "
+ "table 'Keywords': Invalid
syntax "
+ "in keyword 'My User
Keyword': "
+ "Non-existing setting 'ank
ka'.")
+
+
+class ForLoopPopulatingTest(_PopulatorTest):
+
+ def test_single_loop(self):
+ self._create_table('Test cases', [['For loop test'],
+
['', ':FOR', '${i}', 'IN', '@{list}'],
+ ['', '', 'Log', '${i}']])
+ assert_equals(len(self._first_test().steps), 1)
+ for_loop = self._first_test().steps[0]
+ assert_equals(len(for_loop.steps), 1)
+ assert_true(not for_loop.range)
+ assert_equals(for_loop.vars, ['${i}'])
+ assert_equals(for_loop.items, ['@{list}'])
+
+ def test_in_range_for_loop(self):
+ self._create_table('Test cases', [['For loop test'],
+ ['', 'Log', 'Before FOR'],
+ ['', ':
for', '${i}', '${j}', 'IN RANGE', '10'],
+ ['', '', 'Log', '${i}'],
+ ['', '', 'Fail', '${j}'],
+ ['', 'Log', 'Outside FOR']])
+ assert_equals(len(self._first_test().steps), 3)
+ for_loop = self._first_test().steps[1]
+ assert_equals(len(for_loop.steps), 2)
+ assert_true(for_loop.range)
+ assert_equals(for_loop.vars, ['${i}', '${j}'])
+
+ def test_line_continuation(self):
+ self._create_table('Test cases', [['Malicious for loop test'],
+ ['', 'Log', 'Before FOR'],
+ ['', '::::
fOr', '${i}', 'IN', '10'],
+ ['', '...', '20'],
+ ['', '', '...', '30', '40'],
+ ['', '', '', '...', '50', '60'],
+ ['', '', 'Log Many', '${i}'],
+ ['', '', '...', '${i}'],
+ ['', '...', '${i}'],
+ ['', 'Log', 'Outside FOR']])
+ assert_equals(len(self._first_test().steps), 3)
+ for_loop = self._first_test().steps[1]
+ assert_equals(len(for_loop.steps), 1)
+ assert_true(not for_loop.range)
+ assert_equals(for_loop.vars, ['${i}'])
+ assert_equals(for_loop.items, ['10', '20', '30', '40', '50', '60'])
+
+ def test_with_empty_body(self):
+ self._create_table('Test cases', [['For loop test'],
+
['', ':FOR ', '${var}', 'IN', 'foo'],
+ ['', 'Log', 'outside FOR']])
+ test = self._first_test()
+ assert_equals(len(test.steps), 2)
+ assert_equals(test.steps[0].steps, [])
+
class TestPopulatingComments(_PopulatorTest):