Blame view

morfeusz/wrappers/python2/test2.py 2.58 KB
Michał Lenart authored
1
# -*- coding: utf-8 -*-
Michał Lenart authored
2
3
import morfeusz2
Michał Lenart authored
4
5
6
7
8
9
10
11
import unittest
import tempfile
import os
import sys

class TestSequenceFunctions(unittest.TestCase):

    def setUp(self):
Zbigniew Gawłowicz authored
12
        self.morfeusz = morfeusz2.Morfeusz()
Michał Lenart authored
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

    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
Michał Lenart authored
57
58
59
    def testValidCaseHandling(self):
        self.morfeusz.setCaseHandling(morfeusz2.IGNORE_CASE)
Michał Lenart authored
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
    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:
Michał Lenart authored
83
            self.morfeusz.setDictionary("1P4sEBuWv")
Michał Lenart authored
84
85
86
87
88
            self.fail()
        except IOError:
            pass

    def testInvalidDictionaryFile(self):
Michał Lenart authored
89
90
91
92
93
        dirpath = tempfile.mkdtemp()
        dictName = '6J1vMiqY'
        path = os.path.join(dirpath, dictName + '-a.dict')
        with open(path, "a+") as f:
            f.write('ee2rmtsq')
Michał Lenart authored
94
        try:
Michał Lenart authored
95
            self.morfeusz.setDictionary(dictName)
Michał Lenart authored
96
97
98
99
100
101
102
            self.fail()
        except IOError:
            pass

if __name__ == '__main__':
    unittest.main()