def test_hf4(): ip = IterParser.IterHeaderFooter( Martel.Re(r"a*\R").make_parser(), RecordReader.CountLines, (1,), Martel.Group("spam", Martel.Re(r"b*\Rc*\R")).make_parser(), RecordReader.CountLines, (2,), None, None, None, "spam") lines = ["aaaaaaaaa", "b", "c", "bb", "cc", "bbb", "ccc", ] text = "\n".join(lines) + "\n" i = 1 for x in ip.iterateString(text): assert x["spam"][0] == "b" * i + "\n" + "c" * i + "\n" i = i + 1
def gen_iterator(): return IterParser.IterHeaderFooter( Martel.Re(r"a*\R").make_parser(), RecordReader.CountLines, (1,), Martel.Group("spam", Martel.Re(r"b*\Rc*\R")).make_parser(debug_level = 1), RecordReader.CountLines, (2,), Martel.Re(r"d*\R").make_parser(), RecordReader.CountLines, (1,), "spam")
def test_ri3(): # error in the second record ip = IterParser.IterRecords( Martel.Group("spam", Martel.Re(r"b*\Rc*\R")).make_parser(debug_level = 1), RecordReader.CountLines, (2,), "spam") lines = ["b", "c", "b-", "cc", "bbb", "ccc", ] text = "\n".join(lines) + "\n" try: for x in ip.iterateString(text): pass except Parser.ParserPositionException, exc: assert exc.pos == 5, exc.pos