MoinLight

Annotated tests/test_parser.py

36:7b9f5d3e242d
2017-05-05 Paul Boddie Introduced a necessary mechanism for transferring state between tokenisers. Added table node insertion around collections of table rows.
paul@0 1
#!/usr/bin/env python
paul@0 2
paul@11 3
from moinformat import parse
paul@36 4
from moinformat.parsers import table
paul@11 5
from moinformat.serialisers import serialise, HTMLSerialiser
paul@26 6
from glob import glob
paul@26 7
from os.path import join, split
paul@26 8
import sys
paul@1 9
paul@26 10
dirname = split(sys.argv[0])[0]
paul@16 11
paul@36 12
formats = {
paul@36 13
    "table" : table.TableParser,
paul@36 14
    }
paul@36 15
paul@26 16
def test_input(s):
paul@36 17
    d = parse(s, formats)
paul@26 18
    o = serialise(d)
paul@12 19
paul@26 20
    print o == s
paul@26 21
    print "-" * 60
paul@26 22
    print o
paul@26 23
    if o != s:
paul@26 24
        print "-" * 60
paul@26 25
        print s
paul@26 26
    print "-" * 60
paul@26 27
    print serialise(d, HTMLSerialiser)
paul@26 28
    print "-" * 60
paul@26 29
    print d.prettyprint()
paul@26 30
    print
paul@20 31
paul@26 32
if __name__ == "__main__":
paul@26 33
    filenames = sys.argv[1:] or glob(join(dirname, "test*.txt"))
paul@26 34
    filenames.sort()
paul@0 35
paul@26 36
    for filename in filenames:
paul@26 37
        f = open(filename)
paul@26 38
        try:
paul@26 39
            print filename
paul@26 40
            test_input(f.read())
paul@26 41
        finally:
paul@26 42
            f.close()
paul@3 43
paul@0 44
# vim: tabstop=4 expandtab shiftwidth=4