def test_neg_06(self): "TestRecordTxt2: long long line - check for multiple errors" tioconfig = TxtIOConfig() tioconfig.set_max_line_length(7) txt_doc = TxtRecord.from_string("""#1 com ok: yes no #4 cs #5 dds good: but too long #7 dds #8 hi also good: but too long #10 gsst dhd #12 dhdh d: #14 """, "TooLong", tioconfig) assert(txt_doc.is_usable()==False) assert(txt_doc.to_list() == [[80, MemLog.error, 'line too long: is [18], max allowed [7]', 'TooLong', 6], [80, MemLog.error, 'line too long: is [23], max allowed [7]', 'TooLong', 9], [80, MemLog.error, 'line too long: is [8], max allowed [7]', 'TooLong', 10], [80, MemLog.error, 'line too long: is [9], max allowed [7]', 'TooLong', 12], [80, MemLog.info, TxtParser.comment_in_req, 'TooLong', 11]])
def test_pos_01(self): "TxtIOConfig: check new max line length setting" config = Cfg() config.set_value('max_input_line_length', 77) tic = TxtIOConfig(config, 'requirement') assert (tic.get_max_line_length() == 77)
def rmttest_pos_01(self): "TxtIOConfig: check new max line length setting" config = Cfg() config.set_value('max_input_line_length', 77) tic = TxtIOConfig(config, 'requirement') assert(tic.get_max_line_length() == 77)
def test_neg_04(self): "TestRecordTxt2: long long line" tioconfig = TxtIOConfig() tioconfig.set_max_line_length(7) txt_doc = TxtRecord.from_string("good: but too long", "TooLong", tioconfig) assert(txt_doc.is_usable()==False) assert(txt_doc.to_list() == [[80, MemLog.error, 'line too long: is [18], max allowed [7]', 'TooLong', 1]])
def rmttest_pos_01(self): "TestRecordTxt2: empty input" txt_doc = TxtRecord.from_string("", "Nothing", TxtIOConfig()) assert 0 == len(txt_doc) assert "" == txt_doc.get_comment()
def rmttest_neg_05(self): "TestRecordTxt2: long long line - check for lineno" mstderr = StringIO() init_logger(mstderr) cfg = Cfg.new_by_json_str('{"max_input_line_length": 7}') tioconfig = TxtIOConfig(cfg) txt_doc = TxtRecord.from_string( """# com ok: yes no # cs # dds good: but too long # dds """, "TooLong", tioconfig) self.assertEqual(txt_doc.is_usable(), False) lstderr = hide_volatile(mstderr.getvalue()) tear_down_log_handler() result_expected \ = "===DATETIMESTAMP===;rmtoo;ERROR;TxtRecord;" \ "check_line_length;===LINENO===; 80:TooLong:6:line too long: " \ "is [18], max allowed [7]\n" self.assertEquals(result_expected, lstderr)
def rmttest_pos_01(self): "TestRecordTxt2: empty input" txt_doc = TxtRecord.from_string("", "Nothing", TxtIOConfig()) self.assertEqual(0, len(txt_doc)) self.assertEqual("", txt_doc.get_comment())
def rmttest_pos_06(self): "Check top level Record: is_tag_available" txt_doc = TxtRecord.from_string(doc1, u"Nothing", TxtIOConfig()) txt_doc.insert(2, RecordEntry(u"Hinzu", u"This is quite new.")) self.assertTrue(txt_doc.is_tag_available("Hinzu")) self.assertFalse(txt_doc.is_tag_available("NichtDa"))
def test_pos_06(self): "Check top level Record: is_tag_available" txt_doc = TxtRecord.from_string(doc1, "Nothing", TxtIOConfig()) txt_doc.insert(2, RecordEntry("Hinzu", "This is quite new.")) assert (txt_doc.is_tag_available("Hinzu")) assert (not txt_doc.is_tag_available("NichtDa"))
def test_pos_01(self): "Check top level RecordAsDict (string)" txt_doc = TxtRecord.from_string(doc1, "Nothing", TxtIOConfig()) txt_doc_dict = txt_doc.get_dict() assert (txt_doc.get_comment() == dpC1) assert (txt_doc_dict["Name"].get_content() == "meiner") assert (txt_doc_dict["Note"].get_content() == "This is my Note.") assert (txt_doc.to_string() == doc1)
def test_neg_05(self): "TestRecordTxt2: long long line - check for lineno" tioconfig = TxtIOConfig() tioconfig.set_max_line_length(7) txt_doc = TxtRecord.from_string("""# com ok: yes no # cs # dds good: but too long # dds """, "TooLong", tioconfig) assert(txt_doc.is_usable()==False) assert([[80, MemLog.error, 'line too long: is [18], max allowed [7]', 'TooLong', 6]] == txt_doc.to_list())
def test_pos_04(self): "Check top level Record: append entry" txt_doc = TxtRecord.from_string(doc1, "Nothing", TxtIOConfig()) txt_doc.append(RecordEntry("Hinzu", "This is quite new.")) txt_doc_dict = txt_doc.get_dict() assert (txt_doc.get_comment() == dpC1) assert (txt_doc_dict["Name"].get_content() == "meiner") assert (txt_doc_dict["Note"].get_content() == "This is my Note.") assert (txt_doc.to_string() == doc4)
def rmttest_pos_01(self): "Check top level RecordAsDict (string)" txt_doc = TxtRecord.from_string(doc1, u"Nothing", TxtIOConfig()) txt_doc_dict = txt_doc.get_dict() self.assertEqual(dpC1, txt_doc.get_comment()) self.assertEqual("meiner", txt_doc_dict["Name"].get_content()) self.assertEqual("This is my Note.", txt_doc_dict["Note"].get_content()) self.assertEqual(doc1, txt_doc.to_string())
def rmttest_pos_02(self): "Check top level RecordAsDict (fd)" fd = StringIO(doc1) txt_doc = TxtRecord.from_fd(fd, u"Nothing", TxtIOConfig()) txt_doc_dict = txt_doc.get_dict() assert dpC1 == txt_doc.get_comment() assert "meiner" == txt_doc_dict["Name"].get_content() assert "This is my Note." == \ txt_doc_dict["Note"].get_content() assert doc1 == txt_doc.to_string()
def test_neg_01(self): "TestRecordTxt2: rubbish in input" mstderr = StringIO.StringIO() init_logger(mstderr) txt_doc = TxtRecord.from_string("rubbish", "Rubbish", TxtIOConfig()) self.assertEqual(txt_doc.is_usable(), False) lstderr = hide_timestamp(mstderr.getvalue()) tear_down_log_handler() result_expected = "===DATETIMESTAMP===;rmtoo;ERROR;TxtParser;" \ "split_entries;125; 79:Rubbish:1:Expected tag line not found\n" self.assertEquals(result_expected, lstderr)
def rmttest_pos_04(self): "Check top level Record: append entry" txt_doc = TxtRecord.from_string(doc1, u"Nothing", TxtIOConfig()) txt_doc.append(RecordEntry(u"Hinzu", u"This is quite new.")) txt_doc_dict = txt_doc.get_dict() self.assertEqual(dpC1, txt_doc.get_comment()) self.assertEqual("meiner", txt_doc_dict["Name"].get_content()) self.assertEqual("This is my Note.", txt_doc_dict["Note"].get_content()) self.assertEqual(doc4, txt_doc.to_string())
def rmttest_pos_03(self): "Check top level Record: insert entry" txt_doc = TxtRecord.from_string(doc1, u"Nothing", TxtIOConfig()) txt_doc.insert(2, RecordEntry(u"Hinzu", u"This is quite new.")) txt_doc_dict = txt_doc.get_dict() assert dpC1 == txt_doc.get_comment() assert "meiner" == txt_doc_dict["Name"].get_content() assert "This is my Note." == \ txt_doc_dict["Note"].get_content() assert doc2 == txt_doc.to_string()
def rmttest_neg_01(self): "TestRecordTxt2: rubbish in input" mstderr = StringIO() init_logger(mstderr) txt_doc = TxtRecord.from_string("rubbish", "Rubbish", TxtIOConfig()) assert txt_doc.is_usable() is False lstderr = hide_volatile(mstderr.getvalue()) tear_down_log_handler() result_expected \ = "===DATETIMESTAMP===;rmtoo;ERROR;TxtParser;" \ "split_entries;===LINENO===; 79:Rubbish:1:Expected tag line " \ "not found\n" assert result_expected == lstderr
def rmttest_neg_08(self): "TestRecordTxt2: only intro content line" mstderr = StringIO() init_logger(mstderr) tioconfig = TxtIOConfig() txt_doc = TxtRecord.from_string("#1 com", "OnlyEntryComment", tioconfig) self.assertEqual(txt_doc.is_usable(), True) self.assertEqual(txt_doc.get_comment(), "1 com\n") lstderr = hide_volatile(mstderr.getvalue()) tear_down_log_handler() self.assertEquals("", lstderr)
def rmttest_neg_02(self): "TestRecordTxt2: only ':'" mstderr = StringIO() init_logger(mstderr) txt_doc = TxtRecord.from_string(":", "Rubbish", TxtIOConfig()) self.assertEqual(txt_doc.is_usable(), False) lstderr = hide_volatile(mstderr.getvalue()) tear_down_log_handler() result_expected \ = "===DATETIMESTAMP===;rmtoo;ERROR;TxtParser;" \ "split_entries;===LINENO===; 79:Rubbish:1:Expected tag line " \ "not found\n" self.assertEquals(result_expected, lstderr)
def rmttest_neg_06(self): "TestRecordTxt2: long long line - check for multiple errors" mstderr = StringIO() init_logger(mstderr) cfg = Cfg.new_by_json_str('{"max_input_line_length": 7}') tioconfig = TxtIOConfig(cfg) txt_doc = TxtRecord.from_string( """#1 com ok: yes no #4 cs #5 dds good: but too long #7 dds #8 hi also good: but too long #10 gsst dhd #12 dhdh d: #14 """, "TooLong", tioconfig) self.assertEqual(txt_doc.is_usable(), False) lstderr = hide_volatile(mstderr.getvalue()) tear_down_log_handler() result_expected \ = "===DATETIMESTAMP===;rmtoo;ERROR;TxtRecord;" \ "check_line_length;===LINENO===; 80:TooLong:6:line too long: " \ "is [18], max allowed [7]\n" \ "===DATETIMESTAMP===;rmtoo;ERROR;TxtRecord;check_line_length;" \ "===LINENO===; 80:" \ "TooLong:9:line too long: is [23], max allowed [7]\n" \ "===DATETIMESTAMP===;rmtoo;ERROR;TxtRecord;check_line_length;" \ "===LINENO===; 80:" \ "TooLong:10:line too long: is [8], max allowed [7]\n" \ "===DATETIMESTAMP===;rmtoo;ERROR;TxtRecord;check_line_length;" \ "===LINENO===; 80:" \ "TooLong:12:line too long: is [8], max allowed [7]\n" \ "===DATETIMESTAMP===;rmtoo;INFO;TxtParser;split_next_record;" \ "===LINENO===; 80:" \ "TooLong:11:Compatibility info: Comments will be reordered when " \ "they are re-written with rmtoo-tools. Please consult " \ "rmtoo-req-format(5) or rmtoo-topic-format(5)\n" self.assertEquals(result_expected, lstderr)
def rmttest_pos_05(self): "Check top level Record: remove entry" txt_doc = TxtRecord.from_string(doc1, u"Nothing", TxtIOConfig()) del(txt_doc[2]) txt_doc_dict = txt_doc.get_dict() self.assertEqual(dpC1, txt_doc.get_comment()) self.assertEqual("meiner", txt_doc_dict["Name"].get_content()) # 'Note' is not available - it was deleted. try: txt_doc_dict["Note"].get_content() self.assertTrue(False) except KeyError: pass self.assertEqual(doc3, txt_doc.to_string())
def test_pos_05(self): "Check top level Record: remove entry" txt_doc = TxtRecord.from_string(doc1, "Nothing", TxtIOConfig()) del (txt_doc[2]) txt_doc_dict = txt_doc.get_dict() #print("ALL '%s'" % txt_doc.to_string()) assert (txt_doc.get_comment() == dpC1) assert (txt_doc_dict["Name"].get_content() == "meiner") # 'Note' is not available - it was deleted. try: txt_doc_dict["Note"].get_content() assert (False) except KeyError, ke: pass
def test_positive_01(self): "TopicSet - constructor with only one element" try: tioconfig = TxtIOConfig() cfg = Cfg() cfg.set_value('ahah.directory', 'tests/unit-test/topic-tests/testdata/topicset01') cfg.set_value('ahah.name', 't01') cfg.set_value('topics.bkdkd.output', {}) cfg.set_value('topic_root_node', 'RootNode') tvcs = TestVCS(cfg) tobjcache = ObjectCache() tinmod = TestInputModules() topicset = TopicSet(cfg, tvcs, "bkdkd", tobjcache, tinmod) assert (False) except AssertionError, ae: pass
def test_neg_04(self): "TestRecordTxt2: long long line" mstderr = StringIO.StringIO() init_logger(mstderr) cfg = Cfg.new_by_json_str('{"max_input_line_length": 7}') tioconfig = TxtIOConfig(cfg) txt_doc = TxtRecord.from_string("good: but too long", "TooLong", tioconfig) self.assertEqual(txt_doc.is_usable(), False) lstderr = hide_timestamp(mstderr.getvalue()) tear_down_log_handler() result_expected = "===DATETIMESTAMP===;rmtoo;ERROR;TxtRecord;" \ "check_line_length;77; 80:TooLong:1:line too long: is [18], " \ "max allowed [7]\n" self.assertEquals(result_expected, lstderr)
def __input(self, content): '''Read it in from the file (Syntactic input).''' txtio = TxtIOConfig(self.config, self.type_str) self.record = TxtRecord.from_string(content, self.id, txtio) brmo = self.record.get_dict() # This 'brmo' is always valid - if there is a problem, an exception # is raised. # Handle all the modules (Semantic input) self.handle_modules_tag(brmo) # Do not check for remaining tags here. There must be some # left over: all those that work on the whole requirement set # (e.g. 'Solved by'). # If everything's fine, store the rest of the req for later # inspection. self.brmo = brmo
def rmttest_neg_04(self): "TestRecordTxt2: long long line" mstderr = StringIO() init_logger(mstderr) cfg = Cfg.new_by_json_str('{"max_input_line_length": 7}') tioconfig = TxtIOConfig(cfg) txt_doc = TxtRecord.from_string("good: but too long", "TooLong", tioconfig) assert txt_doc.is_usable() is False lstderr = hide_volatile(mstderr.getvalue()) tear_down_log_handler() result_expected \ = "===DATETIMESTAMP===;rmtoo;ERROR;TxtRecord;" \ "check_line_length;===LINENO===; 80:TooLong:1:line too long: " \ "is [18], max allowed [7]\n" assert result_expected == lstderr
def rmttest_neg_07(self): "TestRecordTxt2: test comments between content lines" mstderr = StringIO() init_logger(mstderr) tioconfig = TxtIOConfig() txt_doc = TxtRecord.from_string( """#1 com t1: uuuu #3 Comment not allowed here. #4 Should emitt a warning vvvv t2: uuuu vvvv #8 Here a comment is also not allowed wwww t3: uuuu #11 Same as t1 but with additional #12 comment at the end of the requirement vvvv #14 End comment for t3 t4: uuuu vvvv #17 Same as t2 but with additional #18 comment at the end of the requirement wwww #20 End comment for t4 """, "CommentsEverywhere", tioconfig) self.assertEqual(txt_doc.is_usable(), True) lstderr = hide_volatile(mstderr.getvalue()) tear_down_log_handler() result_expected \ = comment_line % 5 + comment_line % 9 + \ comment_line % 13 + comment_line % 19 self.assertEquals(result_expected, lstderr)
def test_pos_01(self): "TxtIOConfig: check new max line length setting" config = {"max_line_length": 77} tic = TxtIOConfig(config) assert(tic.get_max_line_length()==77)