def test_ri1(): ip = IterParser.IterRecords( Martel.Group("spam", Martel.Re(r"b*\Rc*\R")).make_parser(), RecordReader.CountLines, (2,), "spam") lines = ["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 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