def setUp(self): self._datafile = TestCaseFile() self._datafile.directory = '/path/to' self._populator = FromFilePopulator(self._datafile) self._logger = _MockLogger() LOGGER.disable_message_cache() LOGGER.register_logger(self._logger)
def setUp(self): self._datafile = TestCaseFile() self._datafile.directory = '/path/to' self._populator = FromFilePopulator(self._datafile) self._logger = _MockLogger() self._console_logger = LOGGER._loggers.remove_first_regular_logger() LOGGER.register_logger(self._logger)
def create(data): tcf = TestCaseFile() tcf.directory = '/path/to' pop = FromFilePopulator(tcf) pop.start_table(['Test cases']) for row in [[cell for cell in line.split(' ')] for line in data]: pop.add(row) pop.eof() return tcf
def create(data): tcf = TestCaseFile() tcf.directory = '/path/to' pop = FromFilePopulator(tcf) pop.start_table(['Test cases']) for row in [ [cell for cell in line.split(' ')] for line in data]: pop.add(row) pop.eof() return tcf
def test_start_table(self): tsv = StringIO('''*SettING*\t* Value *\t*V* ***Variable *Not*Table* Keyword*\tNot a table because doesn't start with '*' *******************T*e*s*t*********C*a*s*e************\t***********\t******\t* ''') TsvReader().read(tsv, FromFilePopulator(self.tcf)) 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... Mote\tignored\text *Setting*\t*Value*\t*Value* Document\tWhatever\t\t\\\t Default Tags\tt1\tt2\tt3\t\t *Variable*\tWhatever \\ \\ 2 escaped spaces before and after \\ \\\t\\ \\ value \\ \\ ''') TsvReader().read(tsv, FromFilePopulator(self.tcf)) assert_equals(self.tcf.setting_table.doc.value, 'Whatever ') assert_equals(self.tcf.setting_table.default_tags.value, ['t1','t2','t3']) assert_equals(self.tcf.variable_table.variables[0].name, '\\ \\ 2 escaped spaces before and after \\ \\') assert_equals(self.tcf.variable_table.variables[0].value, ['\\ \\ value \\ \\'])
def test_quotes(self): tsv = StringIO('''*Variable*\t*Value* ${v}\tHello ${v}\t"Hello" ${v}\t"""Hello""" ${v}\t"""""Hello""""" ${v}\t"Hel""lo" ${v}\t"""Hel "" """" lo""""""" ${v}\t"Hello ${v}\tHello" ''') TsvReader().read(tsv, FromFilePopulator(self.tcf)) actual = [variable for variable in self.tcf.variable_table.variables] expected = ['Hello','Hello','"Hello"','""Hello""','Hel"lo', '"Hel " "" lo"""','"Hello','Hello"'] assert_equals(len(actual), len(expected)) for act, exp in zip(actual, expected): assert_equals(act.name, '${v}') assert_equals(act.value, [exp])
class _PopulatorTest(unittest.TestCase): def setUp(self): self._datafile = TestCaseFile() self._datafile.directory = '/path/to' self._populator = FromFilePopulator(self._datafile) self._logger = _MockLogger() LOGGER.disable_message_cache() LOGGER.register_logger(self._logger) def tearDown(self): LOGGER.unregister_logger(self._logger) def _assert_no_parsing_errors(self): assert_true(self._logger.value() == '', self._logger.value()) def _start_table(self, name): if is_string(name): name = [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 _assert_setting(self, name, exp_value, exp_comment=None): setting = self._setting_with(name) assert_equal(setting.value, exp_value) self._assert_comment(setting, exp_comment) def _assert_fixture(self, fixture_name, exp_name, exp_args, exp_comment=None): fixture = self._setting_with(fixture_name) self._assert_name_and_args(fixture, exp_name, exp_args) self._assert_comment(fixture, exp_comment) def _assert_import(self, index, exp_name, exp_args, exp_comment=None): imp = self._datafile.setting_table.imports[index] self._assert_name_and_args(imp, exp_name, exp_args) self._assert_comment(imp, exp_comment) def _assert_name_and_args(self, item, exp_name, exp_args): assert_equal(item.name, exp_name) assert_equal(item.args, exp_args) def _assert_meta(self, index, exp_name, exp_value, exp_comment=None): meta = self._setting_with('metadata')[index] assert_equal(meta.name, exp_name) assert_equal(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_equal(tag.value, exp_value) def _assert_variable(self, index, exp_name, exp_value, exp_comment=[]): var = self._datafile.variable_table.variables[index] assert_equal(var.name, exp_name) assert_equal(var.value, exp_value) self._assert_comment(var, exp_comment) def _assert_comment(self, item, exp_comment): if exp_comment: assert_equal(item.comment.as_list(), exp_comment) def _setting_with(self, name): return getattr(self._datafile.setting_table, name) def _nth_test(self, index): return self._datafile.testcase_table.tests[index-1] 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_equal(len(test.steps), expected_steps)
class _PopulatorTest(unittest.TestCase): def setUp(self): self._datafile = TestCaseFile() self._datafile.directory = '/path/to' self._populator = FromFilePopulator(self._datafile) self._logger = _MockLogger() LOGGER.disable_message_cache() LOGGER.register_logger(self._logger) def tearDown(self): LOGGER.unregister_logger(self._logger) def _assert_no_parsing_errors(self): assert_true(self._logger.value() == '', self._logger.value()) 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): self._start_table(name) for r in rows: self._populator.add(r) if eof: self._populator.eof() def _assert_setting(self, name, exp_value, exp_comment=None): setting = self._setting_with(name) assert_equals(setting.value, exp_value) self._assert_comment(setting, exp_comment) def _assert_fixture(self, fixture_name, exp_name, exp_args, exp_comment=None): fixture = self._setting_with(fixture_name) self._assert_name_and_args(fixture, exp_name, exp_args) self._assert_comment(fixture, exp_comment) def _assert_import(self, index, exp_name, exp_args, exp_comment=None): imp = self._datafile.setting_table.imports[index] self._assert_name_and_args(imp, exp_name, exp_args) self._assert_comment(imp, exp_comment) def _assert_name_and_args(self, item, exp_name, exp_args): assert_equals(item.name, exp_name) assert_equals(item.args, exp_args) def _assert_meta(self, index, exp_name, exp_value, exp_comment=None): meta = self._setting_with('metadata')[index] assert_equals(meta.name, exp_name) 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=[]): var = self._datafile.variable_table.variables[index] assert_equals(var.name, exp_name) assert_equals(var.value, exp_value) self._assert_comment(var, exp_comment) def _assert_comment(self, item, exp_comment): if exp_comment: assert_equals(item.comment.as_list(), exp_comment) def _setting_with(self, name): return getattr(self._datafile.setting_table, name) def _nth_test(self, index): return self._datafile.testcase_table.tests[index - 1] 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)
def _run(self): result = TestDataDirectory(source=os.path.dirname(self._path)) result.initfile = self._path FromFilePopulator(result).populate(self._path) return result
def _load_resource(self, path, report_status): r = ResourceFile(path) if os.stat(path)[6] != 0 and report_status: return r.populate() FromFilePopulator(r).populate(r.source) return r