Files
TTS/tests/text_tests/test_punctuation.py

34 lines
1.4 KiB
Python
Raw Permalink Normal View History

2021-11-19 17:17:11 +01:00
import unittest
2021-11-24 18:46:48 +01:00
from TTS.tts.utils.text.punctuation import _DEF_PUNCS, Punctuation
2021-11-19 17:17:11 +01:00
class PunctuationTest(unittest.TestCase):
def setUp(self):
self.punctuation = Punctuation()
2021-11-24 18:46:48 +01:00
self.test_texts = [
("This, is my text ... to be striped !! from text?", "This is my text to be striped from text"),
("This, is my text ... to be striped !! from text", "This is my text to be striped from text"),
("This, is my text ... to be striped from text?", "This is my text to be striped from text"),
("This, is my text to be striped from text", "This is my text to be striped from text"),
]
2021-11-19 17:17:11 +01:00
def test_get_set_puncs(self):
self.punctuation.puncs = "-="
self.assertEqual(self.punctuation.puncs, "-=")
self.punctuation.puncs = _DEF_PUNCS
self.assertEqual(self.punctuation.puncs, _DEF_PUNCS)
def test_strip_punc(self):
for text, gt in self.test_texts:
text_striped = self.punctuation.strip(text)
self.assertEqual(text_striped, gt)
def test_strip_restore(self):
for text, gt in self.test_texts:
text_striped, puncs_map = self.punctuation.strip_to_restore(text)
text_restored = self.punctuation.restore(text_striped, puncs_map)
2021-11-24 18:46:48 +01:00
self.assertEqual(" ".join(text_striped), gt)
2021-11-19 17:17:11 +01:00
self.assertEqual(text_restored[0], text)