def TestCaseControllerWithSteps(chief=None, source='some_suite.txt'): tcf = TestCaseFile() tcf.source = source tcf.setting_table.suite_setup.name = 'Suite Setup Kw' tcf.setting_table.test_setup.name = SUITE_TEST_SETUP_KEYWORD tcf.setting_table.test_teardown.name = 'Test Teardown Kw' tcf.setting_table.suite_teardown.name = 'Suite Teardown Kw' tcf.setting_table.test_template.value = SUITE_TEST_TEMPLATE_KEYWORD testcase = tcf.testcase_table.add(TEST1_NAME) for step in [[STEP1_KEYWORD, 'Hello'], ['Run Keyword', STEP2_ARGUMENT], [USERKEYWORD2_NAME]]: testcase.add_step(step) for_loop = testcase.add_for_loop([': FOR', '${i}', 'IN RANGE', '10']) for_loop.add_step(['Log', '${i}']) testcase.setup.name = SETUP_KEYWORD testcase.teardown.name = 'Teardown Kw' testcase.template.value = TEMPLATE_KEYWORD uk = tcf.keyword_table.add(USERKEYWORD1_NAME) uk.add_step([KEYWORD_IN_USERKEYWORD1]) uk = tcf.keyword_table.add(USERKEYWORD2_NAME) uk.add_step(['No Operation']) if chief is None: chief = ChiefController(Namespace()) tcf_ctrl = TestCaseFileController(tcf, chief) chief._controller = tcf_ctrl tctablectrl = TestCaseTableController(tcf_ctrl, tcf.testcase_table) return TestCaseController(tctablectrl, testcase), chief._namespace
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 add_testsuite_file(self, filename): """Add all keywords in a test suite file""" suite = TestCaseFile(self, source=filename) suite.populate() if len(suite.keywords) > 0: collection_id = self.add_collection(suite.name, "testsuite", suite.setting_table.doc.value) for kw in suite.keywords: args = [arg.strip("${}") for arg in kw.args.value] self._add_keyword(collection_id, kw.name, kw.doc.value, args)
def add_testsuite_file(self, filename): '''Add all keywords in a test suite file''' suite = TestCaseFile(self, source=filename) suite.populate() if len(suite.keywords) > 0: collection_id = self.add_collection(suite.name, "testsuite", suite.setting_table.doc.value) for kw in suite.keywords: args = [arg.strip("${}") for arg in kw.args.value] self._add_keyword(collection_id, kw.name, kw.doc.value, args)
def test_overwrite(self): ctrl = TestCaseFileController( TestCaseFile(source=self._filepath).populate(), create_chief()) os.utime(self._filepath, (1, 1)) assert_true(ctrl.has_been_modified_on_disk()) ctrl.execute(SaveFile()) assert_false(ctrl.has_been_modified_on_disk())
def _create_test(self, name='test'): suite = TestCaseFile(source='suite') suite_controller = TestCaseFileController(suite) parent = TestCaseTableController( suite_controller, suite.testcase_table) test = TestCase(parent=lambda: 0, name=name) return TestCaseController(parent, test)
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 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 test_deleting_source_should_remove_it_from_model(self): chief = create_chief() chief._controller = TestCaseFileController( TestCaseFile(source=self._filepath), chief) os.remove(self._filepath) ctrl = chief.data ctrl.remove() assert_true(chief.data is None) assert_true(self._removed_datafile is ctrl)
def test_deleting_source_should_remove_it_from_model(self): project = create_project() project._controller = TestCaseFileController( TestCaseFile(source=self._filepath), project) os.remove(self._filepath) ctrl = project.data ctrl.remove() assert_true(project.data is None) assert_true(self._removed_datafile is ctrl)
def setUp(self): self.tcf = TestCaseFile() filectrl = TestCaseFileController(self.tcf) filectrl.resource_import_modified = Mock() resource_file_controller_mock = lambda:0 resource_file_controller_mock.add_known_import = lambda *_:0 resu_factory_mock = lambda:0 resu_factory_mock.find_with_import = lambda *_: resource_file_controller_mock self.ctrl = ImportSettingsController(filectrl, self.tcf.setting_table, resu_factory_mock)
def setUp(self): self.tcf = TestCaseFile() uk = self.tcf.keyword_table.add('UK') uk.add_step(['No Operation']) uk2 = self.tcf.keyword_table.add('UK 2') tablectrl = KeywordTableController(TestCaseFileController(self.tcf), self.tcf.keyword_table) self.ctrl = UserKeywordController(tablectrl, uk) self.ctrl2 = UserKeywordController(tablectrl, uk2)
def setUp(self): self.tcf = TestCaseFile() self.testcase = self.tcf.testcase_table.add('Test') self.testcase.add_step(['Log', 'Hello']) self.testcase.add_step(['No Operation']) self.testcase.add_step(['Foo']) self.tcf.testcase_table.add('Another Test') tctablectrl = TestCaseTableController(TestCaseFileController(self.tcf), self.tcf.testcase_table) self.ctrl = TestCaseController(tctablectrl, self.testcase)
class TestKeywordTable(unittest.TestCase): def setUp(self): self.table = TestCaseFile().keyword_table self.kw = UserKeyword(None, 'name') def test_init(self): assert_equal(self.table.keywords, []) def test_add_keyword(self): kw = self.table.add('My name') assert_true(len(self.table.keywords), 1) assert_true(self.table.keywords[0] is kw) assert_equal(kw.name, 'My name') def test_settings(self): assert_true(isinstance(self.kw.doc, Documentation)) assert_true(isinstance(self.kw.args, Arguments)) assert_true(isinstance(self.kw.return_, Return)) assert_true(isinstance(self.kw.timeout, Timeout)) assert_true(isinstance(self.kw.teardown, Fixture)) def test_set_settings(self): self.kw.doc.populate('My coooool doc') self.kw.args.populate(['${args}', 'are not', 'validated']) assert_equal(self.kw.doc.value, 'My coooool doc') assert_equal(self.kw.args.value, ['${args}', 'are not', 'validated']) def test_add_step(self): step = self.kw.add_step(['Keyword', 'arg1', 'arg2']) assert_equal(self.kw.steps, [step]) assert_equal(step.name, 'Keyword') assert_equal(step.args, ['arg1', 'arg2']) def test_add_for_loop(self): loop = self.kw.add_for_loop(['${var}', 'IN', 'value']) assert_equal(self.kw.steps, [loop]) def test_old_style_headers_are_ignored(self): self.table.set_header(['keywords', 'Action', 'Arg', 'Argument']) assert_equal(self.table.header, ['keywords']) def test_len(self): self.table.set_header(['Keywords']) assert_equal(len(self.table), 0) self.table.add('A kw') self.table.add('B keyword') assert_equal(len(self.table), 2)
def scan_suite(self, file): #return None if file is not a test suite file. try: st = TestCaseFile(source=file) st.populate() cases = [] kws = [] ftags = [] for kw in st.keywords: print "-- keyword: %s" % (kw.name) kws.append(kw.name.strip()) for cs in st.testcase_table.tests: print "-- test case: %s" % (cs.name) cases.append(cs.name.strip()) if st.setting_table.force_tags: ftags = st.setting_table.force_tags.value print "## force tags: %s" % ftags return dict(name=st.name, cases=cases, kws=kws, ftags=ftags) except Exception as e: print "not a suite: %s, %s" % (file, e) return None
def TestData(source, parent=None, settings=None): """Parses a file or directory to a corresponding model object. :param source: path where test data is read from. :returns: :class:`~.model.TestDataDirectory` if `source` is a directory, :class:`~.model.TestCaseFile` otherwise. """ if os.path.isdir(source): data = TestDataDirectoryWithExcludes(parent, source, settings) data.populate() return data return TestCaseFile(parent, source).populate()
def TestCaseControllerWithSteps(chief=None, source="some_suite.txt"): tcf = TestCaseFile() tcf.source = source tcf.setting_table.suite_setup.name = "Suite Setup Kw" tcf.setting_table.test_setup.name = SUITE_TEST_SETUP_KEYWORD tcf.setting_table.test_teardown.name = "Test Teardown Kw" tcf.setting_table.suite_teardown.name = "Suite Teardown Kw" tcf.setting_table.test_template.value = SUITE_TEST_TEMPLATE_KEYWORD testcase = _create_testcase(tcf) uk = tcf.keyword_table.add(USERKEYWORD1_NAME) uk.add_step([KEYWORD_IN_USERKEYWORD1]) uk = tcf.keyword_table.add(USERKEYWORD2_NAME) uk.add_step(["No Operation"]) uk = tcf.keyword_table.add(EMBEDDED_ARGUMENTS_KEYWORD) uk.add_step(["No Operation"]) if chief is None: chief = ChiefController(Namespace(FakeSettings())) tcf_ctrl = TestCaseFileController(tcf, chief) chief._controller = tcf_ctrl tctablectrl = TestCaseTableController(tcf_ctrl, tcf.testcase_table) return TestCaseController(tctablectrl, testcase), chief._namespace
def setUp(self): self.tcf = TestCaseFile() self.tcf.setting_table.add_library('somelib', ['foo', 'bar']) self.tcf.setting_table.add_resource('resu') self.tcf.setting_table.add_library('BuiltIn', ['WITH NAME', 'InBuilt']) self.tcf_ctrl = TestCaseFileController(self.tcf, ImportControllerTest.FakeParent()) self.tcf_ctrl.data.directory = 'tmp' self.parent = ImportSettingsController(self.tcf_ctrl, self.tcf.setting_table, resource_file_controller_factory=self._resource_file_controller_factory_mock()) self.add_import_listener = PublisherListener(RideImportSettingAdded) self.changed_import_listener = PublisherListener(RideImportSettingChanged) self.removed_import_listener = PublisherListener(RideImportSettingRemoved) self.import_listener = PublisherListener(RideImportSetting)
def test_reload(self): controller_parent = object() model_parent = object() ctrl = TestCaseFileController(TestCaseFile( parent=model_parent, source=self._filepath).populate(), parent=controller_parent) assert_equals(len(ctrl.tests), 1) open(self._filepath, 'a').write('Second Test Log Hello World!\n') ctrl.reload() assert_equals(len(ctrl.tests), 2) assert_equals(ctrl.tests[-1].name, 'Second Test') assert_equals(ctrl.parent, controller_parent) assert_equals(ctrl.data.parent, model_parent)
def _create_data(self, resource_name, resource_import): res_path = os.path.abspath(resource_name) tcf = TestCaseFile(source=os.path.abspath('test.txt')) tcf.setting_table.add_resource(resource_import) tcf.variable_table.add('${dirname}', os.path.abspath('.').replace('\\', '\\\\')) tcf.variable_table.add('${path}', os.path.abspath(resource_name).replace('\\', '\\\\')) library_manager = LibraryManager(':memory:') library_manager.create_database() self.chef = ChiefController(Namespace(FakeSettings()), FakeSettings(), library_manager) self.chef._controller = TestCaseFileController(tcf, self.chef) res = ResourceFile(source=res_path) self.res_controller = \ self.chef._resource_file_controller_factory.create(res) self.chef._namespace._resource_factory.cache[os.path.normcase(res_path)] = res
def TestCaseControllerWithSteps(project=None, source='some_suite.txt'): tcf = TestCaseFile() tcf.source = source tcf.setting_table.suite_setup.name = 'Suite Setup Kw' tcf.setting_table.test_setup.name = SUITE_TEST_SETUP_KEYWORD tcf.setting_table.test_teardown.name = 'Test Teardown Kw' tcf.setting_table.suite_teardown.name = 'Suite Teardown Kw' tcf.setting_table.test_template.value = SUITE_TEST_TEMPLATE_KEYWORD testcase = _create_testcase(tcf) uk = tcf.keyword_table.add(USERKEYWORD1_NAME) uk.add_step([KEYWORD_IN_USERKEYWORD1]) uk = tcf.keyword_table.add(USERKEYWORD2_NAME) uk.add_step(['No Operation']) uk = tcf.keyword_table.add(EMBEDDED_ARGUMENTS_KEYWORD) uk.add_step(['No Operation']) if project is None: library_manager = LibraryManager(':memory:') library_manager.create_database() project = Project(Namespace(FakeSettings()), library_manager=library_manager) tcf_ctrl = TestCaseFileController(tcf, project) project._controller = tcf_ctrl tctablectrl = TestCaseTableController(tcf_ctrl, tcf.testcase_table) return TestCaseController(tctablectrl, testcase), project._namespace
def _create_controller(self, path='some.txt'): self._filenames_to_remove.append(path) self.ctrl = TestCaseFileController(TestCaseFile(source=path)) self.saved = False self.deleted = False self._message = None self._error_message = None def save(*args): self.saved = True def remove_from_filesystem(*Args): self.deleted = True self.ctrl.save = save self.ctrl.remove_from_filesystem = remove_from_filesystem return self.ctrl
class TestTestCaseTable(unittest.TestCase): def setUp(self): self.table = TestCaseFile().testcase_table self.test = TestCase(None, 'name') def test_init(self): assert_equal(self.table.tests, []) def test_add_test(self): test = self.table.add('My name') assert_true(len(self.table.tests), 1) assert_true(self.table.tests[0] is test) assert_equal(test.name, 'My name') def test_settings(self): assert_true(isinstance(self.test.doc, Documentation)) assert_true(isinstance(self.test.tags, Tags)) assert_true(isinstance(self.test.setup, Fixture)) assert_true(isinstance(self.test.teardown, Fixture)) assert_true(isinstance(self.test.timeout, Timeout)) def test_set_settings(self): self.test.doc.populate('My coooool doc') self.test.tags.populate(['My', 'coooool', 'tags']) assert_equal(self.test.doc.value, 'My coooool doc') assert_equal(self.test.tags.value, ['My', 'coooool', 'tags']) def test_add_step(self): step = self.test.add_step(['Keyword', 'arg1', 'arg2']) assert_equal(self.test.steps, [step]) assert_equal(step.name, 'Keyword') assert_equal(step.args, ['arg1', 'arg2']) def test_add_for_loop(self): loop = self.test.add_for_loop(['${var}', 'IN', 'value']) assert_equal(self.test.steps, [loop]) def test_old_style_headers_are_ignored(self): self.table.set_header(['test case', 'Action', 'Arg', 'Argument']) assert_equal(self.table.header, ['test case']) def test_len(self): self.table.set_header(['Test Case']) assert_equal(len(self.table), 0) self.table.add('A test') self.table.add('B test') assert_equal(len(self.table), 2)
def _process_test_suite(self, suite): """ Processes a TestSuite containing test cases and performs the following: - Parses the suite's dependencies (e.g. Library & Resource references) and adds them into the `dependencies` dict - Corrects the path references in the suite file to where the dependencies will be placed on the remote side - Returns a dict with metadata alongside the updated test suite file data :param suite: a TestSuite containing test cases :type suite: robot.running.model.TestSuite :return: Dictionary containing the suite file data and path from the root directory :rtype: dict """ logger.debug('Processing Test Suite: `{}`'.format(suite.name)) # Traverse the suite's ancestry to work out the directory path so that it can be recreated on the remote side path = calculate_ts_parent_path(suite) # At this point `suite` is a robot.running.model.TestSuite which doesn't appear to support writing the source # back to disk in robot syntax. To get around this, read it from disk again into a TestCaseFile which can be # modified and then converted into bytes tcf = TestCaseFile(source=suite.source).populate() # Iterate through the imports of suite. _process_dependency() will update the path to the reference which we # then copy to the TestCaseFile. From this we will produce the modified test suite file data for suite_imp, tcf_imp in zip(suite.resource.imports, tcf.imports): logger.debug('Processing dependency: `{}` for Test Suite: {}'.format(suite_imp.name, suite.name)) self._process_dependency(suite_imp) tcf_imp.name = suite_imp.name # Now that we've updated the references, get the file contents string_io = StringIO() DataFileWriter(output=string_io).write(tcf) return { 'path': path, 'suite_data': string_io.getvalue() }
def setUp(self): self.tcf = TestCaseFile() self._orig_curdir = robot.parsing.populators.PROCESS_CURDIR robot.parsing.populators.PROCESS_CURDIR = False
def NewTestCaseFile(path): datafile = TestCaseFile(source=path) _create_missing_directories(datafile.directory) return datafile
class TestSettingTable(unittest.TestCase): def setUp(self): self.table = TestCaseFile().setting_table 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)) assert_true(isinstance(self.table.test_setup, Fixture)) assert_true(isinstance(self.table.test_teardown, Fixture)) assert_true(isinstance(self.table.test_timeout, Timeout)) assert_true(isinstance(self.table.force_tags, Tags)) assert_true(isinstance(self.table.default_tags, Tags)) assert_equal(self.table.metadata.data, []) assert_equal(self.table.imports.data, []) def test_doc_default(self): assert_equal(self.table.doc.value, '') def test_set_doc_with_string(self): self.table.doc.populate('hello') assert_equal(self.table.doc.value, 'hello') def test_set_doc_with_list(self): self.table.doc.populate(['hello', 'world']) assert_equal(self.table.doc.value, 'helloworld') def test_fixture_default(self): assert_equal(self.table.suite_setup.name, None) assert_equal(self.table.suite_setup.args, []) assert_false(hasattr(self.table.suite_setup, 'value')) def test_set_fixture(self): self.table.suite_teardown.populate(['Name', 'a1', 'a2']) assert_equal(self.table.suite_teardown.name, 'Name') assert_equal(self.table.suite_teardown.args, ['a1', 'a2']) assert_false(hasattr(self.table.suite_teardown, 'value')) def test_set_fixture_with_empty_value(self): self.table.test_teardown.populate([]) assert_equal(self.table.test_teardown.name, '') assert_equal(self.table.test_teardown.args, []) def test_timeout_default(self): assert_equal(self.table.test_timeout.value, None) assert_equal(self.table.test_timeout.message, '') assert_false(hasattr(self.table.suite_setup, 'value')) def test_set_timeout(self): self.table.test_timeout.populate(['1s', 'msg', 'in multiple', 'cell']) assert_equal(self.table.test_timeout.value, '1s') assert_equal(self.table.test_timeout.message, 'msg in multiple cell') assert_false(hasattr(self.table.suite_teardown, 'value')) def test_set_timeout_with_empty_value(self): self.table.test_timeout.populate([]) assert_equal(self.table.test_timeout.value, '') assert_equal(self.table.test_timeout.message, '') def test_metadata(self): self.table.add_metadata('Foo', 'bar') self.table.add_metadata('boo', ['f', 'a', 'r']) assert_equal(len(self.table.metadata), 2) assert_equal(self.table.metadata[0].name, 'Foo') assert_equal(self.table.metadata[0].value, 'bar') assert_equal(self.table.metadata[1].name, 'boo') assert_equal(self.table.metadata[1].value, 'f a r') self.table.metadata[0] = self.table.metadata[1] assert_equal(self.table.metadata[0].name, 'boo') assert_equal(self.table.metadata[0].value, 'f a r') def test_imports(self): self._verify_import(self.table.add_library('Name'), 'Name') self._verify_import(self.table.add_resource('reso.txt'), 'reso.txt') self._verify_import(self.table.add_variables('varz.py'), 'varz.py') self._verify_import(self.table.add_variables('./v2.py', ['a1', 'a2']), './v2.py', ['a1', 'a2']) self._verify_import(self.table.add_library('N2', ['1', '2', '3', '4']), 'N2', ['1', '2', '3', '4']) assert_equal(len(self.table.imports), 5) assert_true(all(isinstance(im, _Import) for im in self.table.imports)) self.table.imports[1] = self.table.imports[0] assert_equal(self.table.imports[1].name, 'Name') def test_resource_with_invalid_args(self): reso = self.table.add_resource('reso.txt', ['invalid', 'args']) self._verify_import(reso, 'reso.txt invalid args') def test_library_with_name(self): lib = self.table.add_library('Name', ['WITH NAME', 'New name']) self._verify_import(lib, 'Name', [], 'New name') lib = self.table.add_library('Orig', ['a1', 'a2', 'WITH NAME', 'New']) self._verify_import(lib, 'Orig', ['a1', 'a2'], 'New') def _verify_import(self, imp, name, args=[], alias=None): assert_equal(imp.name, name) assert_equal(imp.args, args) assert_equal(imp.alias, alias) assert_equal(imp.type, type(imp).__name__) def test_old_style_headers_are_ignored(self): self.table.set_header(['Settings', 'Value', 'value', 'Value']) assert_equal(self.table.header, ['Settings']) def test_len(self): assert_equal(len(self.table), 0) self.table.add_library('SomeLib') assert_equal(len(self.table), 1) self.table.doc.value = 'Some doc' self.table.add_metadata('meta name', 'content') assert_equal(len(self.table), 3)
def setUp(self): self.table = TestCaseFile().setting_table
def setUp(self): self.tcf = TestCaseFile() self.tcf.setting_table.add_metadata('Meta name', 'Some value') self.ctrl = MetadataListController(TestCaseFileController(self.tcf), self.tcf.setting_table)
def setUp(self): self.table = TestCaseFile().testcase_table self.test = TestCase(None, 'name')
def setUp(self): _TestMacroCommands.setUp(self) self._ctrl = TestCaseFileController(TestCaseFile())
def setUp(self): self.tcf = TestCaseFile() self._add_var('${foo}', 'foo') self._add_var('@{bar}', ['b', 'a', 'r']) self.ctrl = VariableTableController(TestCaseFileController(self.tcf), self.tcf.variable_table)
def setUp(self): self.table = TestCaseFile().variable_table
class TestVariableTable(unittest.TestCase): def setUp(self): self.table = TestCaseFile().variable_table def test_init(self): assert_equal(self.table.variables, []) def test_add_variables(self): self.table.add('${SCALAR}', ['hello']) self.table.add('${S2} =', 'hello as string') self.table.add('@{LIST}', ['hello', 'world']) assert_equal(len(self.table.variables), 3) assert_equal(self.table.variables[0].name, '${SCALAR}') assert_equal(self.table.variables[0].value, ['hello']) assert_equal(self.table.variables[1].name, '${S2}') assert_equal(self.table.variables[1].value, ['hello as string']) assert_equal(self.table.variables[2].name, '@{LIST}') assert_equal(self.table.variables[2].value, ['hello', 'world']) def test_empty_value(self): self.table.add('${V1}', []) self.table.add('${V2}', '') assert_equal(self.table.variables[0].value, ['']) assert_equal(self.table.variables[1].value, ['']) def test_variable_syntax_is_not_verified(self): self.table.add('not var', 'the value') assert_equal(self.table.variables[0].name, 'not var') assert_equal(self.table.variables[0].value, ['the value']) def test_old_style_headers_are_ignored(self): self.table.set_header(['Variable', 'value', 'Value']) assert_equal(self.table.header, ['Variable']) def test_len(self): self.table.set_header(['Variable', 'value', 'Value']) assert_equal(len(self.table), 0) self.table.add('${a var}', 'some') self.table.add('@{b var}', 's', 'ome') assert_equal(len(self.table), 2)
def setUp(self): self.table = TestCaseFile().keyword_table self.kw = UserKeyword(None, 'name')
def _assert_format(self, expected, source, format=''): data = TestCaseFile(source=source) ctx = WritingContext(data, format=format) assert_equal(ctx.format, expected)
def _testcasefile(path): data = TestCaseFile() data.source = os.path.normpath(path) return data
def _assert_output_file(self, expected, source=None, format=''): ctx = WritingContext(TestCaseFile(source=source), format=format) assert_equal(ctx._output_path(), expected)