def chunk_assertion_blocks(text):
    chunks = []
    buffer = None
    for lineno, line in enumerate(text.splitlines()):
        if not line.startswith('::'):
            if buffer:
                buffer[-1].append(line)
            continue
        tokens = line[2:].split()
        try:
            pragma, args = tokens[0], tokens[1:]
            if pragma == 'test':
                if buffer:
                    raise ChunkError("test out of order")
                chunknum = len(chunks) + 1
                if args:
                    title = ' '.join(args)
                else:
                    title = str(chunknum)
                buffer = [chunknum, title, []]
                continue
            elif pragma == 'endtest':
                if not buffer or len(buffer) == 3:
                    raise ChunkError("endtest out of order")
                buffer[2] = ' '.join(buffer[2]).strip()
                buffer[3] = ' '.join(buffer[3]).strip()
                chunks.append(buffer)
                buffer = None
                continue
            elif pragma == 'eq':
                if not buffer or len(buffer) > 3:
                    raise ChunkError("eq out of order")
                buffer.append([])
            else:
                raise ChunkError("unknown pragma" + pragma)
        except (ChunkError, __HOLE__), exc:
            lineno += 1
            arg = exc.args[0] if exc.args else ''
            raise AssertionError(
                "Invalid testing chunk specification: %s\n"
                "line %s:\n%r" % (
                    arg, lineno, line))
    return chunks
dataset/ETHPy150Open jek/flatland/tests/genshi/_util.py/chunk_assertion_blocks