def test__add__None(self): tags = Tags(['xx', 'yy']) new_tags = tags + None assert_true(isinstance(new_tags, Tags)) assert_equal(list(tags), ['xx', 'yy']) assert_equal(list(new_tags), list(tags)) assert_true(new_tags is not tags)
def test_reset_suites(self): s1 = TestSuite(name='s1') self.suite.suites = [s1] s2 = self.suite.suites.create(name='s2') assert_true(s1.parent is self.suite) assert_true(s2.parent is self.suite) assert_equal(list(self.suite.suites), [s1, s2])
def test_is_variable(self): for no in ['', 'xxx', '${var} not alone', '\\${notvat}', '\\\\${var}', '${var}xx}', '${x}${y}']: assert_false(VariableSplitter(no).is_variable(), no) for yes in ['${var}', '${var${}', '${var${internal}}', '@{var}', '@{var}[0]']: assert_true(VariableSplitter(yes).is_variable(), yes)
def test_multiple_ands(self): patterns = TagPatterns(['xANDyANDz']) assert_false(patterns.match([])) assert_false(patterns.match(['x'])) assert_false(patterns.match(['x', 'y'])) assert_true(patterns.match(['x', 'Y', 'z'])) assert_true(patterns.match(['a', 'y', 'z', 'b', 'X']))
def test_create_and_add_suite(self): s1 = self.suite.suites.create(name='s1') s2 = TestSuite(name='s2') self.suite.suites.append(s2) assert_true(s1.parent is self.suite) assert_true(s2.parent is self.suite) assert_equal(list(self.suite.suites), [s1, s2])
def test_keyword_settings(self): labels = [setting.label for setting in self.ctrl.settings] assert_true('Documentation' in labels) assert_true('Arguments' in labels) assert_true('Teardown' in labels) assert_true('Return Value' in labels) assert_true('Timeout' in labels)
def test_resource_in_nested_directory(self): self._set_data_directory_controller('tmp') self._set_resources(j('tmp','res','ources','res.txt')) assert_equals(len(self.project.data.children), 1) assert_equals(len(self.project.data.children[0].children), 1) assert_equals(self.project.data.children[0].children[0].children, [self.project.resources[0]]) assert_true(len(self.project.external_resources)== 0)
def test_add_test_or_kw(self): assert_equals(len(self.ctrl.tests), 0) new_test = TestCaseController(self.ctrl, TestCase(TestCaseFile(), 'New test')) self.ctrl.add_test_or_keyword(new_test) assert_equals(len(self.ctrl.tests), 1) assert_true(self.ctrl.tests[0]._test.parent.parent is self.ctrl.datafile) assert_true(self.ctrl.dirty)
def test_import_class_from_file(self): path = create_temp_file('test.py', extra_content='class test:\n def m(s): return 1') klass = self._import(path, remove='test') self._assert_imported_message('test', path, type='class') assert_true(inspect.isclass(klass)) assert_equals(klass.__name__, 'test') assert_equals(klass().m(), 1)
def _verify_that_power2_estimate_overestimates(self, a, b, c, kw1000_result, kw2000_result, kw3000_result, kw4000_result): def power2estimate(kw_amount): x = kw_amount / 1000 return a + b * x + c * x**2 assert_true(power2estimate(4000) * self.SAFETY_MARGIN > kw4000_result, 'Possibly o(n*2) or greater growth in namespace performance measures!\nkw1000 time = %s kw2000 time = %s kw3000 time = %s kw4000 time = %s'\ % (kw1000_result, kw2000_result, kw3000_result, kw4000_result))
def test_has_format(self): ctrl = TestDataDirectoryController(self.data) assert_false(ctrl.has_format()) ctrl.mark_dirty() assert_false(ctrl.has_format()) ctrl.data.initfile = os.path.join('source', '__init__.html') assert_true(ctrl.has_format())
def test_creating_duplicate_keyword_in_resource_file(self): lib = self._get_userlibrary('kw', 'kw', 'kw 2') assert_equal(len(lib.handlers), 2) assert_true('kw' in lib.handlers) assert_true('kw 2' in lib.handlers) assert_equal(lib.handlers['kw'].error, "Keyword with same name defined multiple times.")
def test_other_list_like_items_are_not_touched(self): value = ({'key': 'value'}, [{}]) d = DotDict(key=value) assert_equal(d.key[0]['key'], 'value') assert_false(hasattr(d.key[0], 'key')) assert_true(isinstance(d.key[0], dict)) assert_true(isinstance(d.key[1][0], dict))
def test_deleting_init_file(self): project = create_project() project._controller = TestDataDirectoryController(TestDataDirectory(source=self._dirpath).populate(), project) os.remove(self._init_path) project.data.remove() open(self._init_path, 'w').write('*Settings*\nDocumentation Ride unit testing file\n') assert_true(project.data.has_format() is False, project.data.data.initfile)
def test_overwrite(self): ctrl = TestCaseFileController(TestCaseFile(source=self._filepath).populate(), create_project()) 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 test_all_methods(self): logger = LoggerMock2(('Hello, world!', 'INFO')) self.logger.register_logger(logger) self.logger.output_file('name', 'path') self.logger.close() assert_equals(logger.output_file, ('name', 'path')) assert_true(logger.closed)
def test_deleting_file_suite_under_dir_suite(self): project = create_project() project._controller = TestDataDirectoryController(TestDataDirectory(source=self._dirpath).populate(), project) original_children_length = len(project.data.children) file_suite = project.data.children[0] file_suite.remove() assert_true(len(project.data.children) == original_children_length-1, 'Child suite was not removed')
def test_editing_with_args(self): ctrl = ImportController(self.parent, self.parent[0]._import) ctrl.set_value('bar', 'quux') self._assert_import(0, 'bar', ['quux']) assert_true(self.parent.dirty) ctrl.set_value('name', 'a1 | a2') self._assert_import(0, 'name', ['a1', 'a2'])
def test_automatic_console_logger_can_be_disabled_after_registering_logger(self): logger = Logger() mock = LoggerMock() logger.register_logger(mock) logger.unregister_console_logger() self._number_of_registered_loggers_should_be(1, logger) assert_true(logger._loggers.all_loggers()[0].message.__self__.__class__ is LoggerMock)
def test_broken_listener(self): self.plugin.subscribe(self.plugin.error_listener, RideLog) RideTestMessage().publish() assert_true(self.plugin.error.message.startswith('Error in listener: ride.test'), 'Wrong error message text: ' + self.plugin.error.message) assert_equals(self.plugin.error.topic, 'ride.log.exception') assert_equals(self.plugin.error.level, 'ERROR')
def _verify_model_contains_no_keywords(self, model, mapped=False): if not mapped: model = remap(model, self.context.strings) assert_true('keyword' not in model, 'Not all keywords removed') for item in model: if isinstance(item, tuple): self._verify_model_contains_no_keywords(item, mapped=True)
def test_reset(self): sugs = self.ns.get_suggestions_for(self.kw, 'generate random') sugs2 = self.ns.get_suggestions_for(self.kw, 'generate random') assert_true(sugs[0] is sugs2[0]) self.ns.reset_resource_and_library_cache() sugs3 = self.ns.get_suggestions_for(self.kw, 'generate random') assert_false(sugs[0] is sugs3[0])
def test_through_jsexecutionresult(self): suite = ( 0, StringIndex(1), 2, 3, 4, StringIndex(5), ((0, 1, 2, StringIndex(3), 4, 5, (), (), ("suite", "kws"), 9),), ((0, 1, 2, StringIndex(3), 4, 5, ("test", "kws")), (0, StringIndex(1), 2, 3, 4, 5, ("test", "kws"))), ("suite", "kws"), 9, ) exp_s = ( 0, 0, 2, 3, 4, 2, ((0, 1, 2, 1, 4, 5, (), (), (), 9),), ((0, 1, 2, 1, 4, 5, ()), (0, 0, 2, 3, 4, 5, ())), (), 9, ) result = JsExecutionResult( suite=suite, strings=tuple(" ABCDEF"), errors=(1, 2), statistics={}, basemillis=0, min_level="DEBUG" ) assert_equals(result.data["errors"], (1, 2)) result.remove_data_not_needed_in_report() assert_equals(result.strings, tuple("ACE")) assert_equals(result.suite, exp_s) assert_equals(result.min_level, "DEBUG") assert_true("errors" not in result.data)
def test_match_with_not(self): patterns = TagPatterns(['xNOTy', '???NOT?']) assert_false(patterns.match([])) assert_false(patterns.match(['x', 'y'])) assert_false(patterns.match(['123', 'y', 'z'])) assert_true(patterns.match(['x'])) assert_true(patterns.match(['123', 'xx']))
def test_known_keyword(self): cell = CellInfo(CellContent(ContentType.USER_KEYWORD, 'Known', 'my_source'), CellPosition(CellType.KEYWORD, None)) msg = TipMessage(cell) assert_true(msg) assert_equals(str(msg), html_escape(_TooltipMessage.KEYWORD % 'my_source'))
def test_arguments_are_globbed(self): _, args = self.ap.parse_args([__file__.replace('test_', '?????')]) assert_equals(args, [__file__]) # Needed to ensure that the globbed directory contains files globexpr = os.path.join(os.path.dirname(__file__), '*') _, args = self.ap.parse_args([globexpr]) assert_true(len(args) > 1)
def test_resource_in_nested_directory(self): self.chief._controller = TestDataDirectoryController(self._data_directory('tmp')) self._set_resources(j('tmp','res','ources','res.txt')) assert_equals(len(self.chief.data.children), 1) assert_equals(len(self.chief.data.children[0].children), 1) assert_equals(self.chief.data.children[0].children[0].children, [self.chief.resources[0]]) assert_true(len(self.chief.external_resources)== 0)
def test_stopping(self): self.runner = self._create_runner('python %s output 0.8' % SCRIPT) time.sleep(0.3) self.runner.stop() self._sleep_and_log_output(0.1) assert_true(self.runner.finished) assert_true(self.runner.outstr.startswith('start\nrunning '))
def test_unescape_options(self): cli = '--escape quot:Q -E space:SP -E lt:LT -E gt:GT ' \ + '-N QQQLTmySPfineSPnameGTQQQ sourceSPwithSPspaces' opts, args = self.ap.parse_args(cli.split()) assert_equals(opts['name'], '"""<my fine name>"""') assert_equals(args, ['source with spaces']) assert_true('escape' not in opts)
def test_importer_caches_are_cleared_between_runs(self): self._run(self.data) lib = self._import_library() res = self._import_resource() self._run(self.data) assert_true(lib is not self._import_library()) assert_true(res is not self._import_resource())
def test_no_embedded_args(self): assert_true(not EmbeddedArguments('No embedded args here')) assert_true(EmbeddedArguments('${Yes} embedded args here'))
def test_creation(self): for st in self.ctrl.settings: assert_true(st is not None) assert_true(self.ctrl.datafile is self.tcf, self.ctrl.datafile)
def test_move_down(self): assert_false(self.ctrl2.move_down()) self._assert_uk_in(1, 'UK 2') assert_true(self.ctrl.move_down()) self._assert_uk_in(1, 'UK')
def test_move_up(self): assert_false(self.ctrl.move_up()) self._assert_uk_in(0, 'UK') assert_true(self.ctrl2.move_up()) self._assert_uk_in(0, 'UK 2')
def test_truthy_values(self): for item in [True, 1, [False], unittest.TestCase, 'truE', 'whatEver']: for item in self._strings_also_in_different_cases(item): assert_true(is_truthy(item) is True) assert_true(is_falsy(item) is False)
def test_keyword_argument_is_visible_in_keywords_local_namespace(self): assert_true(self._keyword.get_local_namespace().has_name('${argument}'))
def test_macro_controller_has_local_namespace(self): assert_true(self._test.get_local_namespace() is not None) assert_true(self._keyword.get_local_namespace() is not None)
def test_case_sensetive_filenames(self): imp = Resource(None, RESOURCE_PATH) first = self._res_cache.get_resource(imp.directory, imp.name.lower()) second = self._res_cache.get_resource(imp.directory, imp.name.upper()) assert_true(first is second)
def test_file_read_only_once(self): imp = Resource(None, RESOURCE_PATH) first = self._res_cache.get_resource(imp.directory, imp.name) second = self._res_cache.get_resource(imp.directory, imp.name) assert_true(first is second)
def test_embedded_args_handler_has_all_needed_attributes(self): normal = UserKeywordHandler(HandlerDataMock('My name'), None) embedded = EmbeddedArgs('My name', EAT('My ${name}')) for attr in dir(normal): assert_true(hasattr(embedded, attr), "'%s' missing" % attr)
def test_is_user_keyword_in_resource_file(self): everything_tcf = TestCaseFile(source=TESTCASEFILE_WITH_EVERYTHING).populate() assert_not_none(self.ns.find_user_keyword(everything_tcf, 'Duplicate UK')) assert_true(self.ns.is_user_keyword(everything_tcf, 'Duplicate UK')) assert_not_none(self.ns.find_user_keyword(everything_tcf, 'Another Resource UK')) assert_true(self.ns.is_user_keyword(everything_tcf, 'Another Resource UK'))
def test_file_with_absolute_path(self): imp = Resource(ParentMock(), RESOURCE_PATH) assert_true(self._res_cache.get_resource(imp.directory, imp.name))
def test_is_library_keyword_longname_with_alias(self): assert_true(self.ns.is_library_keyword(self.tcf, TELNET_LIB_ALIAS+'.LOGIN'))
def test_has_default_values(self): vars = _VariableStash() assert_true('${SPACE}' in [v.name for v in vars]) assert_true('${PREV_TEST_MESSAGE}' in [v.name for v in vars])
def test_is_library_keyword(self): assert_true(self.ns.is_library_keyword(self.tcf, 'Should Be Equal')) assert_false(self.ns.is_library_keyword(self.tcf, 'kameli')) assert_false(self.ns.is_library_keyword(self.tcf, 'UK From Resource from Resource with Variable'))
def test_is_user_keyword(self): assert_true(self.ns.is_user_keyword(self.tcf, 'UKFromResource from ResourcewithVariable')) assert_false(self.ns.is_user_keyword(self.tcf, 'hevoinen')) assert_false(self.ns.is_user_keyword(self.tcf, 'Should Be Equal'))
def test_suggestions_for_datafile(self): sugs = self.ns.get_suggestions_for(self.tcf_ctrl, 'Execute Manual') self._assert_import_kws(sugs, 'Dialogs') sugs = self.ns.get_suggestions_for(self.tcf_ctrl, '${libna') assert_true(len(sugs) == 1)
def test_is_library_keyword_longname(self): assert_true(self.ns.is_library_keyword(self.tcf, 'Builtin.Should Be Equal'))
def test_variable_file_arguments_are_resolved(self): sugs = self.ns.get_suggestions_for(self._get_controller(TESTCASEFILE_WITH_EVERYTHING).keywords[0], '${dyn ') assert_true(len(sugs) > 0)
def _assert_import_kws(self, sugs, source): assert_true(len(sugs) > 0) for s in sugs: assert_true(s.source.endswith(source), '%s does not end with %s' % (s.source, source))
def test_vars_from_file(self): sugs = self.ns.get_suggestions_for(self._get_controller(TESTCASEFILE_WITH_EVERYTHING).keywords[0], '${var_from_file') assert_true(len(sugs) > 0)
def test_argument_is_superior_to_variable_from_variable_table(self): sugs = self.ns.get_suggestions_for(self.kw, COLLIDING_ARGUMENT[0:4]) assert_true(any(True for s in sugs if s.source == ArgumentInfo.SOURCE))
def test_user_keywords(self): sugs = self.ns.get_suggestions_for(self.kw, 'sHoUlD') assert_true(EXISTING_USER_KEYWORD in [s.name for s in sugs])
def test_vars_from_path_resource_file(self): sugs = self.ns.get_suggestions_for(self._get_controller(TESTCASEFILE_WITH_EVERYTHING).keywords[0], '${Path RESOURCE var') assert_true(len(sugs) > 0)
def test_getting_suggestions_for_empty_datafile(self): start = 'shOulD' sugs = self.ns.get_suggestions_for(self.kw, start) assert_true(len(sugs) > 0) for s in sugs: assert_true(s.name.lower().startswith(start.lower()))
def test_xml_library_is_library_keyword(self): everything_tcf = TestCaseFile(source=TESTCASEFILE_WITH_EVERYTHING).populate() assert_true(self.ns.is_library_keyword(everything_tcf, 'Attributeless Keyword'))
def _assert_no_parsing_errors(self): assert_true(self._logger.value() == '', self._logger.value())
def test_getting_suggestions_in_order(self): sugs = self.ns.get_suggestions_for(self.kw, 'sHoUlD') assert_true(len(sugs) > 2) assert_equals(sugs, sorted(sugs))
def test_starting_valid_table(self): for name in ['Test Cases', ' variables ', 'K E Y WO R D S']: assert_true(self._start_table(name))
def test_commented_row(self): assert_true(DataRow(['#start of table comment']).is_commented())