File: test_dict.py

package info (click to toggle)
tomoe 0.6.0-1.3
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 51,396 kB
  • sloc: xml: 1,387,526; ansic: 11,515; sh: 9,072; ruby: 1,344; python: 762; makefile: 450
file content (144 lines) | stat: -rw-r--r-- 5,533 bytes parent folder | download | duplicates (2)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# encoding: utf-8
import os
import sys
import shutil
import unittest
import tomoe

class TomoeDictTest(unittest.TestCase):

    def testCopy(self):
        dict_modules = os.getenv('DICT_MODULES').split()
        for dest_dict_name in dict_modules:
            if dest_dict_name == "xml":
                if os.access('copy-test.xml', os.F_OK):
                    os.unlink('copy-test.xml')
                dest_dict = tomoe.Dict("XML", filename = 'copy-test.xml' ,editable = True)
            elif dest_dict_name == "unihan":
                return 
            elif dest_dict_name == "est":
                if os.access('copy-test', os.F_OK):
                    shutil.rmtree('copy-test')
                dest_dict = tomoe.Dict('Est', name = 'copy-test', database = 'copy-test', editable = True)
            elif dest_dict_name == "mysql":
                self.assert_(False)
            else:
                self.assert_(False)
            self.assertNotEqual(None, dest_dict)
            self.assert_(self.dict.copy(dest_dict))

            query = tomoe.Query()
            for src_char, dest_char in zip(sorted(map(lambda x: x.get_char(), self.dict.search(query)), key=lambda char: char.get_utf8()),
                                           sorted(map(lambda x: x.get_char(), dest_dict.search(query)), key=lambda char: char.get_utf8())):
                self.assertEqual(src_char.to_xml(), dest_char.to_xml())

    def testRegisterChar(self):
        char_code = '地'
        tomoe_char = self.dict.get_char(char_code)
        self.assertEqual(None, tomoe_char)

        tomoe_char = tomoe.Char(char_code)
        self.assert_(self.dict.register_char(tomoe_char))

        tomoe_char = self.dict.get_char(char_code)
        self.assertNotEqual(None, tomoe_char)
        self.assertEqual(char_code, tomoe_char.get_utf8())

    def testUnregisterChar(self):
        char_code = '池'
        tomoe_char = self.dict.get_char(char_code)
        self.assertEqual(char_code, tomoe_char.get_utf8())

        self.assert_(self.dict.unregister_char(char_code))
        self.assertEqual(None, self.dict.get_char(char_code))

    def testGetExistChar(self):
        char_code = '池'
        n_strokes = 6
        tomoe_char = self.dict.get_char(char_code)
        self.assertNotEqual(None, tomoe_char)
        self.assertEqual(char_code, tomoe_char.get_utf8())
        self.assertEqual(n_strokes, tomoe_char.get_n_strokes())

    def testFailGetExistChar(self):
        char_code = '存在しない'
        self.assertEqual(None, self.dict.get_char(char_code))

    def testFailReadingSearch(self):
        tomoe_reading = tomoe.Reading(tomoe.READING_UNKNOWN, 'そんなよみかたありません')
        tomoe_query = tomoe.Query()
        tomoe_query.add_reading(tomoe_reading)
        candidates = self.dict.search(tomoe_query)
        self.assertEqual(0, len(candidates))

    def testUnknownReadingSearch(self):
        char_code = '池'
        reading = 'あんのうん'
        tomoe_reading = tomoe.Reading(tomoe.READING_UNKNOWN, reading)
        tomoe_query = tomoe.Query()
        tomoe_query.add_reading(tomoe_reading)

        candidates = self.dict.search(tomoe_query)
        self.assertEqual(char_code, candidates[0].get_char().get_utf8())

    def testKunReadingSearch(self):
        char_code = '池'
        reading = 'いけ'
        tomoe_reading = tomoe.Reading(tomoe.READING_JA_KUN, reading)
        tomoe_query = tomoe.Query()
        tomoe_query.add_reading(tomoe_reading)

        candidates = self.dict.search(tomoe_query)
        self.assertEqual(char_code, candidates[0].get_char().get_utf8())

    def testOnReadingSearch(self):
        char_code = '池'
        reading = 'チ'
        tomoe_reading = tomoe.Reading(tomoe.READING_JA_ON, reading)
        tomoe_query = tomoe.Query()
        tomoe_query.add_reading(tomoe_reading)

        candidates = self.dict.search(tomoe_query)
        self.assertEqual(char_code, candidates[0].get_char().get_utf8())

    def testUnknownOnReadingSearch(self):
        char_code = '池'
        reading = 'チ'
        tomoe_reading = tomoe.Reading(tomoe.READING_UNKNOWN, reading)
        tomoe_query = tomoe.Query()
        tomoe_query.add_reading(tomoe_reading)

        candidates = self.dict.search(tomoe_query)
        self.assertEqual(char_code, candidates[0].get_char().get_utf8())

    def testUnknownKunReadingSearch(self):
        char_code = '池'
        reading = 'いけ'
        tomoe_reading = tomoe.Reading(tomoe.READING_UNKNOWN, reading)
        tomoe_query = tomoe.Query()
        tomoe_query.add_reading(tomoe_reading)

        candidates = self.dict.search(tomoe_query)
        self.assertEqual(char_code, candidates[0].get_char().get_utf8())

    def testOnUnknownReadingSearch(self):
        char_code = '池'
        reading = 'あんのうん'
        tomoe_reading = tomoe.Reading(tomoe.READING_JA_ON, reading)
        tomoe_query = tomoe.Query()
        tomoe_query.add_reading(tomoe_reading)

        candidates = self.dict.search(tomoe_query)
        self.assertEqual(char_code, candidates[0].get_char().get_utf8())

    def testKunUnknownReadingSearch(self):
        char_code = '池'
        reading = 'あんのうん'
        tomoe_reading = tomoe.Reading(tomoe.READING_JA_KUN, reading)
        tomoe_query = tomoe.Query()
        tomoe_query.add_reading(tomoe_reading)

        candidates = self.dict.search(tomoe_query)
        self.assertEqual(char_code, candidates[0].get_char().get_utf8())

# vi:ts=4:nowrap:ai:expandtab