MoinLight

Annotated tests/test_parser.py

42:083967e32406
2017-12-13 Paul Boddie Moved the Moin wiki parser into the parsers subpackage. Made the parsers and serialisers plus general functions available via the package root.
paul@0 1
#!/usr/bin/env python
paul@0 2
paul@42 3
from moinformat import parse, parsers, serialise, serialisers
paul@26 4
from glob import glob
paul@26 5
from os.path import join, split
paul@26 6
import sys
paul@1 7
paul@26 8
dirname = split(sys.argv[0])[0]
paul@16 9
paul@26 10
def test_input(s):
paul@42 11
    d = parse(s, parsers)
paul@26 12
    o = serialise(d)
paul@12 13
paul@26 14
    print o == s
paul@38 15
paul@38 16
    if quiet:
paul@38 17
        return
paul@38 18
paul@26 19
    print "-" * 60
paul@26 20
    print o
paul@26 21
    if o != s:
paul@26 22
        print "-" * 60
paul@26 23
        print s
paul@26 24
    print "-" * 60
paul@42 25
    print serialise(d, serialisers["html"])
paul@26 26
    print "-" * 60
paul@26 27
    print d.prettyprint()
paul@26 28
    print
paul@20 29
paul@26 30
if __name__ == "__main__":
paul@38 31
    args = sys.argv[1:]
paul@38 32
    quiet = "-q" in args
paul@38 33
    if quiet:
paul@38 34
        del args[args.index("-q")]
paul@38 35
    filenames = args or glob(join(dirname, "test*.txt"))
paul@26 36
    filenames.sort()
paul@0 37
paul@26 38
    for filename in filenames:
paul@26 39
        f = open(filename)
paul@26 40
        try:
paul@26 41
            print filename
paul@26 42
            test_input(f.read())
paul@26 43
        finally:
paul@26 44
            f.close()
paul@3 45
paul@0 46
# vim: tabstop=4 expandtab shiftwidth=4