File: test_characters.py

package info (click to toggle)
python-wordaxe 0.3.2-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 1,228 kB
  • ctags: 786
  • sloc: python: 9,814; makefile: 5
file content (68 lines) | stat: -rw-r--r-- 2,021 bytes parent folder | download
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import unittest

import traceback

__author__ = "Henning von Bargen"

from wordaxe import *

OUTPUT = False

words = u"""
raven\u2019s
Dr.\x00A0Who
""".splitlines()

def test_words(hyphenator):
    if OUTPUT: print "Testing", hyphenator, "..."
    errors = []
    for word in words:
        if word:
            try:
                hword = u"n/a"
                hword = hyphenator.hyphenate(word)
                assert hword is None or isinstance(hword, HyphenatedWord)
                if OUTPUT: print (u"word:%s result:%s" % (word, hword)).encode("ascii", "xmlcharrefreplace")
            except:
                errors.append(u"word:%s result:%s exception:%s" %
                              (word, hword, traceback.format_exc()))
    if errors:
        raise AssertionError("Errors for %s:\n" % hyphenator + "\n".join([e.encode("ascii","backslashreplace") for e in errors]))


if False:
    # We know that PyHnj does not hyphenate many German words as it should,
    # so leave this test out
    class WordlistTestCase(unittest.TestCase):
        "Test hyphenation using a word list with PyHnj."

        def test(self):
            from wordaxe.PyHnjHyphenator import PyHnjHyphenator
            hyphenator = PyHnjHyphenator('de_DE', 4, purePython=1)
            test_words(hyphenator)


class DCWWordlistTestCase(unittest.TestCase):
    "Test hyphenation using a word list with DCW."

    def test(self):
        from wordaxe.DCWHyphenator import DCWHyphenator
        hyphenator = DCWHyphenator('DE', 4)
        test_words(hyphenator)

class PyHyphenWordlistTestCase(unittest.TestCase):
    "Test hyphenation using a word list with PyHyphen."

    def test(self):
        from wordaxe.plugins.PyHyphenHyphenator import PyHyphenHyphenator
        hyphenator = PyHyphenHyphenator('de_DE', 4)
        test_words(hyphenator)

if __name__ == "__main__":
    OUTPUT = True
    unittest.main()