test.py
2.59 KB
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
# -*- coding: utf-8 -*-
import morfeusz2
import unittest
import tempfile
import os
import sys
class TestSequenceFunctions(unittest.TestCase):
def setUp(self):
self.morfeusz = morfeusz2.Morfeusz.createInstance()
def testAnalyzeAsList(self):
res = self.morfeusz.analyse("Aaaa żżżż");
self.assertEquals(2, len(res));
self.assertEquals(u"Aaaa", res[0].orth);
self.assertEquals(u"żżżż", res[1].orth);
try:
res[2];
fail();
except IndexError:
pass
def testAnalyzeAsIterator(self):
res = list(self.morfeusz.analyse_iter("Aaaa żżżż"));
self.assertEquals(2, len(res));
self.assertEquals(u"Aaaa", res[0].orth);
self.assertEquals(u"żżżż", res[1].orth);
try:
res[2];
fail();
except IndexError:
pass
def testInvalidAgglOption(self):
try:
self.morfeusz.setAggl('XXXXYYYYZZZZ')
self.fail()
except RuntimeError:
pass
def testInvalidPraetOption(self):
try:
self.morfeusz.setPraet('XXXXYYYYZZZZ')
self.fail()
except RuntimeError:
pass
def testInvalidGenerate(self):
try:
self.morfeusz.generate("AAAA BBBB")
self.fail()
except RuntimeError:
pass
def testValidCaseHandling(self):
self.morfeusz.setCaseHandling(morfeusz2.IGNORE_CASE)
def testInvalidCaseHandling(self):
try:
self.morfeusz.setCaseHandling(0)
self.fail()
except ValueError:
pass
def testInvalidTokenNumbering(self):
try:
self.morfeusz.setTokenNumbering(0)
self.fail()
except ValueError:
pass
def testInvalidWhitespaceHandling(self):
try:
self.morfeusz.setWhitespaceHandling(0)
self.fail()
except ValueError:
pass
def testNonExistingDictionaryFile(self):
try:
self.morfeusz.setDictionary("1P4sEBuWv")
self.fail()
except IOError:
pass
def testInvalidDictionaryFile(self):
dirpath = tempfile.mkdtemp()
dictName = '6J1vMiqY'
path = os.path.join(dirpath, dictName + '-a.dict')
with open(path, "a+") as f:
f.write('ee2rmtsq')
try:
self.morfeusz.setDictionary(dictName)
self.fail()
except IOError:
pass
if __name__ == '__main__':
unittest.main()