/
validate_test.py
146 lines (130 loc) · 4.79 KB
/
validate_test.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
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
145
146
# coding=utf-8
# Copyright 2020 The Google Research Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for turkish_morphology.validate."""
import os
from turkish_morphology import analysis_pb2
from turkish_morphology import validate
from absl.testing import absltest
from absl.testing import parameterized
from google.protobuf import text_format
_TESTDATA_DIR = "turkish_morphology/testdata"
def _read_file(path):
with open(path, "r") as f:
read = f.read()
return read
def _read_analysis(basename):
path = os.path.join(_TESTDATA_DIR, f"{basename}.pbtxt")
return text_format.Parse(_read_file(path), analysis_pb2.Analysis())
class AnalysisTest(parameterized.TestCase):
@parameterized.named_parameters([
{
"testcase_name": "SingleInflectionalGroupsWithProperFeature",
"basename": "araba_with_proper",
},
{
"testcase_name": "SingleInflectionalGroupsWithoutProperFeature",
"basename": "araba_without_proper",
},
{
"testcase_name": "MultipleInflectionalGroupsWithProperFeature",
"basename": "yasa_with_proper",
},
{
"testcase_name": "MultipleInflectionalGroupsWithoutProperFeature",
"basename": "yasa_without_proper",
},
])
def test_success(self, basename):
analysis = _read_analysis(basename)
actual = validate.analysis(analysis)
self.assertIsNone(actual)
@parameterized.named_parameters([
{
"testcase_name": "AnalysisMissingInflectionalGroups",
"basename": "invalid_empty_analysis",
"message": "Analysis is missing inflectional groups",
},
{
"testcase_name": "InflectionalGroupMissingPartOfSpeechTag",
"basename": "invalid_ig_missing_pos",
"message": "Inflectional group 2 is missing part-of-speech tag",
},
{
"testcase_name": "InflectionalGroupEmptyPartOfSpeechTag",
"basename": "invalid_ig_empty_pos",
"message": "Inflectional group 2 part-of-speech tag is empty",
},
{
"testcase_name": "FirstInflectionalGroupMissingRoot",
"basename": "invalid_first_ig_missing_root",
"message": "Inflectional group 1 is missing root",
},
{
"testcase_name": "DerivedInflectionalGroupMissingDerivation",
"basename": "invalid_derived_ig_missing_derivation",
"message": "Inflectional group 2 is missing derivational affix",
},
{
"testcase_name": "AffixMissingFeature",
"basename": "invalid_affix_missing_feature",
"message": "Affix is missing feature",
},
{
"testcase_name": "DerivationalAffixMissingMetaMorpheme",
"basename": "invalid_derivational_affix_missing_meta_morpheme",
"message": "Derivational affix is missing meta-morpheme",
},
{
"testcase_name": "DerivationalAffixEmptyMetaMorpheme",
"basename": "invalid_derivational_affix_empty_meta_morpheme",
"message": "Derivational affix meta-morpheme is empty",
},
{
"testcase_name": "FeatureMissingCategory",
"basename": "invalid_feature_missing_category",
"message": "Feature is missing category",
},
{
"testcase_name": "FeatureEmptyCategory",
"basename": "invalid_feature_empty_category",
"message": "Feature category is empty",
},
{
"testcase_name": "FeatureMissingValue",
"basename": "invalid_feature_missing_value",
"message": "Feature is missing value",
},
{
"testcase_name": "FeatureEmptyValue",
"basename": "invalid_feature_empty_value",
"message": "Feature value is empty",
},
{
"testcase_name": "RootMissingMorpheme",
"basename": "invalid_root_missing_morpheme",
"message": "Root is missing morpheme",
},
{
"testcase_name": "RootEmptyMorpheme",
"basename": "invalid_root_empty_morpheme",
"message": "Root morpheme is empty",
},
])
def test_raises_exception(self, basename, message):
analysis = _read_analysis(basename)
with self.assertRaisesRegexp(validate.IllformedAnalysisError, message):
validate.analysis(analysis)
if __name__ == "__main__":
absltest.main()