def rmttest_positive_01(self): """Requirement contains a tag where no handler exists""" mstderr = StringIO() init_logger(mstderr) test_config = TestConfig() test_config.set_solved_by() mods = InputModules(test_config) reqs = RequirementSet(None) req = Requirement("Hubbel: bubbel", "hubbel", reqs, mods, test_config) reqs.add_requirement(req) reqs._handle_modules(mods) lstderr = hide_volatile(mstderr.getvalue()) tear_down_log_handler() result_expected \ = ["===DATETIMESTAMP===;rmtoo;ERROR;RequirementSet;" "__all_tags_handled;===LINENO===; 57:hubbel:No tag handler " "found for " "tag(s) '[\"Hubbel\"]' - Hint: typo in tag(s)?", "===DATETIMESTAMP===;rmtoo;ERROR;" "RequirementSet;_handle_modules;" "===LINENO===; 56:There were errors encountered during parsing " "and checking - can't continue."] lstderr_last_two_lines = lstderr.split("\n")[-3:-1] assert result_expected == lstderr_last_two_lines
def rmttest_neg_point_to_self(self): "'Solved by' points to same requirement" mstderr = StringIO() init_logger(mstderr) config = TestConfig() reqset = RequirementSet(config) req1 = Requirement('''Name: A Type: master requirement''', 'A', None, None, None) reqset.add_requirement(req1) req2 = Requirement('''Name: B Type: requirement Solved by: B''', 'B', None, None, None) reqset.add_requirement(req2) config.set_solved_by() rdep = RDepSolvedBy(config) status = rdep.rewrite(reqset) assert not status lstderr = hide_volatile(mstderr.getvalue()) tear_down_log_handler() result_expected \ = "===DATETIMESTAMP===;rmtoo;ERROR;RequirementSet;" \ "__resolve_solved_by_one_req_deps;===LINENO===; " \ "75:B:'Solved by' points to the requirement itself\n" assert result_expected == lstderr
def rmttest_json_init_add_new_cmd_line_params(self): '''Init Cfg with JSON and adds parameters with command line options''' mstderr = StringIO() init_logger(mstderr) # Create two JSON files. tmpdir = create_tmp_dir() jsonfile1 = os.path.join(tmpdir, "config1.json") with open(jsonfile1, "w") as jsonfd1: jsonfd1.write(json.dumps({'k': 2, 'm': {'n': 5}, 'o': 7})) jsonfile2 = os.path.join(tmpdir, "config2.json") with open(jsonfile2, "w") as jsonfd2: jsonfd2.write(json.dumps({'k': 3, 'm': {'w': 11}, 'p': 9})) config = Cfg.new_by_json_str('{"k": 1, "l": [2, 3], "m": {"n": 4}}') config.merge_cmd_line_params(['-j', '{"m": {"p": 99}}', '-j', 'file://' + jsonfile1, '-j', '{"m": {"q": 100}}', '-j', 'file://' + jsonfile2]) assert 1 == config.get_value("k"), "k is not 1" config.evaluate() assert 3 == config.get_value("k"), "k is not 3" assert 11 == config.get_value("m.w") lstderr = hide_volatile(mstderr.getvalue()) shutil.rmtree(tmpdir) tear_down_log_handler() assert lstderr == ""
def prepare_stderr(): '''Some lines of the stderr contain a date / timestamp. This must be unified in order to be able to compare them.''' with open(os.path.join(os.environ["rmtoo_test_dir"], "stderr")) as ms: lines = ms.readlines() with open(os.path.join(os.environ["rmtoo_test_dir"], "stderr"), "w") as new_stderr: for line in lines: new_stderr.write("%s" % hide_volatile(line))
def rmttest_neg_01(self): "BaseRMObject: check for module which has wrong type" mstderr = StringIO() init_logger(mstderr) TBRMObj() result = hide_volatile(mstderr.getvalue()) tear_down_log_handler() assert expected_result == result
def rmttest_positive_02(self): "Requirement contains a tag where no handler exists - multiple tags" mstderr = StringIO() init_logger(mstderr) tc = TestConfig() tc.set_solved_by() mods = InputModules(tc) reqs = RequirementSet(None) req = Requirement("Hubbel: bubbel\nSiebel: do", "InvalidTagReq", reqs, mods, tc) reqs.add_requirement(req) reqs._handle_modules(mods) lstderr = hide_volatile(mstderr.getvalue()) tear_down_log_handler() lstderr_last_two_lines = lstderr.split("\n")[-3:-1] result0 \ = re.match( r"^===DATETIMESTAMP===;rmtoo;ERROR;RequirementSet;" r"__all_tags_handled;===LINENO===; 57:InvalidTagReq:" r"No tag handler found " r"for tag\(s\) '\[.*\]' - Hint: typo in tag\(s\)\?$", lstderr_last_two_lines[0]) result1 \ = re.match( r"^===DATETIMESTAMP===;rmtoo;ERROR;RequirementSet;" "_handle_modules;" "===LINENO===; 56:There were errors encountered " "during parsing " "and checking - can't continue.$", lstderr_last_two_lines[1]) assert result0 assert result1