- fix hypen

- fix tests
- add hypen test
This commit is contained in:
Vadim committed 2023-11-17 00:29:21 +01:00
1 parent 37664ab35d
commit 1c74ee7e23
5 files changed
+64 -15

No files matched your search

@@ -1,17 +1,34 @@
"""Tests for hyphenation.py"""
import unittest
from src.modules.Speech_Recognition.hyphenation import hyphenation
from unittest.mock import patch
from src.modules.Speech_Recognition.hyphenation import hyphenation, language_check
from hyphen import Hyphenator
class TestHypenation(unittest.TestCase):
def test_hypenation():
"""Test case for hyphenation function."""
def test_hypenation(self):
"""Test case for hyphenation function."""
assert hyphenation("begegnen", Hyphenator("de_DE")) == ["be", "geg", "nen"]
assert hyphenation(".b,e~g'eg*nen, ", Hyphenator("de_DE")) == [".b,e", "~g'eg", "*nen, "]
assert hyphenation("Abend, ", Hyphenator("de_AT")) == None
assert hyphenation("Abend.", Hyphenator("de_AT")) == None
assert hyphenation("begegnen", Hyphenator("de_DE")) == ["be", "geg", "nen"]
assert hyphenation(".b,e~g'eg*nen, ", Hyphenator("de_DE")) == [".b,e", "~g'eg", "*nen, "]
assert hyphenation("Abend, ", Hyphenator("de_AT")) == None
assert hyphenation("Abend.", Hyphenator("de_AT")) == None
@patch('hyphen.dictools.list_installed')
def test_language_check_has_installed_language(self, mock_list_installed):
mock_list_installed.return_value = ['de', 'de_DE', 'en', 'en_US', 'en_GB']
assert language_check("en") == "en_US"
assert language_check("de") == "de_DE"
@patch('hyphen.dictools.list_installed')
def test_language_check_not_installed_language(self, mock_list_installed):
mock_list_installed.return_value = []
assert language_check("fr") == "fr_FR"
assert language_check("de") == "de"
assert language_check("none") == None
if __name__ == "__main__":
unittest.main()
@@ -82,7 +82,7 @@ class TestCreateUltrastarTxt(unittest.TestCase):
@staticmethod
def default_values(default_ultrastar_class):
expected_calls = [
f"#{UltrastarTxtTag.VERSION}:{default_ultrastar_class.version}\n",
#f"#{UltrastarTxtTag.VERSION}:{default_ultrastar_class.version}\n", # todo: Version definition is in progress
f"#{UltrastarTxtTag.ARTIST}:{default_ultrastar_class.artist}\n",
f"#{UltrastarTxtTag.TITLE}:{default_ultrastar_class.title}\n",
f"#{UltrastarTxtTag.MP3}:{default_ultrastar_class.mp3}\n",
@@ -103,7 +103,7 @@ class TestCreateUltrastarTxt(unittest.TestCase):
@staticmethod
def full_values(default_ultrastar_class):
expected_calls = [
f"#{UltrastarTxtTag.VERSION}:{default_ultrastar_class.version}\n",
#f"#{UltrastarTxtTag.VERSION}:{default_ultrastar_class.version}\n", # todo: Version definition is in progress
f"#{UltrastarTxtTag.ARTIST}:{default_ultrastar_class.artist}\n",
f"#{UltrastarTxtTag.TITLE}:{default_ultrastar_class.title}\n",
f"#{UltrastarTxtTag.YEAR}:{default_ultrastar_class.year}\n",
+1 -1
View File
@@ -1,5 +1,5 @@
class Settings:
APP_VERSION = "0.0.1-2023-11-13"
APP_VERSION = "0.0.2"
create_midi = True
create_plot = False
+13
View File
@@ -264,6 +264,18 @@ def print_support() -> None:
f"{ULTRASINGER_HEAD} {gold_highlighted('This will help alot to keep this project alive and improved.')}"
)
def print_version() -> None:
"""Print version text"""
print()
print(
f"{ULTRASINGER_HEAD} {gold_highlighted('*****************************')}"
)
print(
f"{ULTRASINGER_HEAD} {gold_highlighted('UltraSinger Version:')} {light_blue_highlighted(settings.APP_VERSION)}"
)
print(
f"{ULTRASINGER_HEAD} {gold_highlighted('*****************************')}"
)
def run() -> None:
"""The processing function of this program"""
@@ -772,6 +784,7 @@ def denoise_vocal_audio(basename_without_ext: str, cache_path: str) -> None:
def main(argv: list[str]) -> None:
"""Main function"""
print_version()
init_settings(argv)
run()
# todo: cleanup
+24 -5
View File
@@ -2,7 +2,7 @@
import string
from hyphen import Hyphenator
from hyphen import Hyphenator, dictools
from modules.console_colors import (
ULTRASINGER_HEAD,
@@ -78,10 +78,29 @@ def language_check(language="en") -> str | None:
"""Check if language is supported"""
lang_region = None
for dict_lang in LANGUAGES:
if dict_lang.startswith(language):
lang_region = dict_lang
break
installed = dictools.list_installed()
installed_region_keys = [i for i in installed if i.startswith(language) and "_" in i]
try:
# Try to find installed language with region prediction
lang_region = next(i for i in installed_region_keys if i == f"{language}_{language.upper()}")
except StopIteration:
if installed_region_keys:
# Take first installed region language
lang_region = installed_region_keys[0]
else:
# Take downloadable language key
downloadable_key = [i for i in LANGUAGES if i.startswith(language)]
downloadable_folder_key = [i for i in downloadable_key if i == language]
if downloadable_folder_key:
lang_region = downloadable_key[0]
else:
try:
# Try to find downloadable language with region prediction
lang_region = next(i for i in downloadable_key if i == f"{language}_{language.upper()}")
except StopIteration:
if downloadable_key:
# Take first installed region language
lang_region = downloadable_key[0]
if lang_region is None:
return None