Spaces:
Build error
Build error
File size: 3,959 Bytes
f1f433f |
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 |
from copy import deepcopy
from unittest import TestCase
from pydantic import ValidationError
from voicevox_engine.kana_parser import parse_kana
from voicevox_engine.model import UserDictWord
class TestUserDictWords(TestCase):
def setUp(self):
self.test_model = {
"surface": "テスト",
"priority": 0,
"part_of_speech": "名詞",
"part_of_speech_detail_1": "固有名詞",
"part_of_speech_detail_2": "一般",
"part_of_speech_detail_3": "*",
"inflectional_type": "*",
"inflectional_form": "*",
"stem": "*",
"yomi": "テスト",
"pronunciation": "テスト",
"accent_type": 0,
"accent_associative_rule": "*",
}
def test_valid_word(self):
test_value = deepcopy(self.test_model)
try:
UserDictWord(**test_value)
except ValidationError as e:
self.fail(f"Unexpected Validation Error\n{str(e)}")
def test_convert_to_zenkaku(self):
test_value = deepcopy(self.test_model)
test_value["surface"] = "test"
self.assertEqual(UserDictWord(**test_value).surface, "test")
def test_count_mora(self):
test_value = deepcopy(self.test_model)
self.assertEqual(UserDictWord(**test_value).mora_count, 3)
def test_count_mora_x(self):
test_value = deepcopy(self.test_model)
for s in [chr(i) for i in range(12449, 12533)]:
if s in ["ァ", "ィ", "ゥ", "ェ", "ォ", "ッ", "ャ", "ュ", "ョ", "ヮ"]:
continue
for x in "ァィゥェォャュョ":
expected_count = 0
test_value["pronunciation"] = s + x
for accent_phrase in parse_kana(
test_value["pronunciation"] + "'",
):
expected_count += len(accent_phrase.moras)
with self.subTest(s=s, x=x):
self.assertEqual(
UserDictWord(**test_value).mora_count,
expected_count,
)
def test_count_mora_xwa(self):
test_value = deepcopy(self.test_model)
test_value["pronunciation"] = "クヮンセイ"
expected_count = 0
for accent_phrase in parse_kana(
test_value["pronunciation"] + "'",
):
expected_count += len(accent_phrase.moras)
self.assertEqual(
UserDictWord(**test_value).mora_count,
expected_count,
)
def test_invalid_pronunciation_not_katakana(self):
test_value = deepcopy(self.test_model)
test_value["pronunciation"] = "ぼいぼ"
with self.assertRaises(ValidationError):
UserDictWord(**test_value)
def test_invalid_pronunciation_invalid_sutegana(self):
test_value = deepcopy(self.test_model)
test_value["pronunciation"] = "アィウェォ"
with self.assertRaises(ValidationError):
UserDictWord(**test_value)
def test_invalid_pronunciation_invalid_xwa(self):
test_value = deepcopy(self.test_model)
test_value["pronunciation"] = "アヮ"
with self.assertRaises(ValidationError):
UserDictWord(**test_value)
def test_count_mora_voiced_sound(self):
test_value = deepcopy(self.test_model)
test_value["pronunciation"] = "ボイボ"
self.assertEqual(UserDictWord(**test_value).mora_count, 3)
def test_invalid_accent_type(self):
test_value = deepcopy(self.test_model)
test_value["accent_type"] = 4
with self.assertRaises(ValidationError):
UserDictWord(**test_value)
def test_invalid_accent_type_2(self):
test_value = deepcopy(self.test_model)
test_value["accent_type"] = -1
with self.assertRaises(ValidationError):
UserDictWord(**test_value)
|