-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathunit_tests.py
executable file
·109 lines (89 loc) · 3.09 KB
/
unit_tests.py
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
#!/usr/bin/env python3
import unittest
from fileformat import load_stemming, load_lexicon
from fileformat import RefDoesNotExistException
from greek_inflexion import GreekInflexion
class FileFormatTest(unittest.TestCase):
def test_bad_ref(self):
with self.assertRaises(RefDoesNotExistException):
load_stemming("test_files/bad_ref.yaml")
def test_stemming(self):
s = load_stemming("test_files/stemming_test.yaml")
self.assertEqual(s.key_to_rules["bar"][0].surface, "ace")
self.assertEqual(s.key_to_rules["foo"][1].tags, {"baz"})
def test_lexicon(self):
(
lexicon, form_override, accent_override, segmented_lemmas
) = load_lexicon(
"test_files/lexicon_test.yaml")
self.assertEqual(form_override[("lemma2", "PAI.3S")], "blah")
self.assertEqual(accent_override["lemma2"], [('PAI', 'blah')])
self.assertEqual(
lexicon.lemma_to_stems["lemma2"], [
('I', 'baz', {'+z'}),
('P', 'bar', set()),
('foo', 'bar', set())
])
class InflexionTest(unittest.TestCase):
def setUp(self):
self.inflexion = GreekInflexion(
"stemming.yaml",
"STEM_DATA/pratt_lexicon.yaml"
)
def test_generate(self):
self.inflexion.generate('λύω', 'AAI.1S')
# @@@
def test_find_stems(self):
self.assertEqual(
self.inflexion.find_stems('λύω', 'AAI.1S'),
{'ἐλυσ'}
)
def test_parse1(self):
self.assertEqual(
self.inflexion.parse('ἔλυσα'),
{('λύω', 'AAI.1S')}
)
def test_parse2(self):
self.assertEqual(
self.inflexion.parse('ποιοῦμαι'),
set()
)
def test_possible_stems1(self):
self.assertEqual(
sorted(self.inflexion.possible_stems('ποιοῦμαι')),
[
('AAN', 'ποιουμ'),
('AAO.3S', 'ποιουμ'),
('AMD.2S', 'ποιουμ'),
('FMI.1S', 'ποι{contract}'),
('PMI.1S', 'ποιε'),
('PMI.1S', 'ποιο'),
('PMI.1S', 'ποιου{athematic}'),
('XMI.1S', 'ποιου'),
('ZMI.1S', 'ποι{contract}'),
]
)
def test_possible_stems2(self):
self.assertEqual(
sorted(self.inflexion.possible_stems('ποιοῦμαι', '.+1S$')),
[
('FMI.1S', 'ποι{contract}'),
('PMI.1S', 'ποιε'),
('PMI.1S', 'ποιο'),
('PMI.1S', 'ποιου{athematic}'),
('XMI.1S', 'ποιου'),
('ZMI.1S', 'ποι{contract}'),
]
)
def test_conjugate(self):
self.inflexion.conjugate(
"λύω", "PAI", "AAI", tags={"final-nu-aai.3s"}
)
# @@@
def test_decline(self):
self.inflexion.decline(
"λύω", "PAP"
)
# @@@
if __name__ == "__main__":
unittest.main()