File: wikitest.py

package info (click to toggle)
wikitrans 1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 728 kB
  • sloc: python: 5,253; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 1,090 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import print_function
from glob import glob
import os.path

def wiki_markup_test(classname, name_in, name_out):
    fh = open(name_out)
    buf = ''.join(fh.readlines()).strip()
    fh.close()
    hwm = classname(filename=name_in, lang="en")
    hwm.parse()

    if str(hwm).strip() == buf:
        return True

    # fail
    print("\n>>>%s<<<" % buf)
    print(">>>%s<<<" % str(hwm).strip())
    return False

def populate_methods(cls, wcls, suffix):
    def settest(self, base, wiki_name, pat_name):
        def dyntest(self):
            self.assertTrue(wiki_markup_test(wcls, wiki_name, pat_name))
        meth = 'test_' + wcls.__name__ + '_' + base
        dyntest.__name__ = meth
        setattr(cls, meth, dyntest)
    for file in glob('testdata/*.wiki'):
        if os.path.isfile(file):
            patfile = file[:len(file) - 5] + suffix
            base, ext = os.path.splitext(os.path.basename(file))
            if os.path.exists(patfile) and os.path.isfile(patfile):
                settest(cls, base, file, patfile)