Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng_to_ipa/transcribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __str__(self):

def preprocess(words):
"""Returns a string of words stripped of punctuation"""
punct_str = '!"#$%&\'()*+,-./:;<=>/?@[\\]^_`{|}~«» '
punct_str = '!"#$%&\'()*+,-./:;<=>/?@[\\]^_`{|}~«» '
return ' '.join([w.strip(punct_str).lower() for w in words.split()])


Expand Down
21 changes: 21 additions & 0 deletions tests/test_transcribe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-

# USAGE:
# PYTHONPATH=".." python test_transcribe.py

from eng_to_ipa import transcribe
import transcribe_fixtures
import sys

words6 = "diction… …rocks"
words6 = [transcribe.preserve_punc(w.lower())[0] for w in words6.split()]
words6 = [w[1] for w in words6]

ipa6 = [['ˈdɪkʃən'], ['rɑks']]

class TestConversion_default(transcribe_fixtures.BaseConversion):
@classmethod
def setUpClass(self):
self.words6 = words6
self.ipa6 = ipa6
self.cmu6 = [['d ih1 k sh ah0 n'], ['r aa1 k s']]
21 changes: 21 additions & 0 deletions tests/transcribe_fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-

# USAGE:
# PYTHONPATH=".." python test_transcribe.py

from eng_to_ipa import transcribe
import unittest

class BaseConversion(unittest.TestCase):
"""Simple unit testing for the transcribe function(s)."""

def test_get_cmu_ellipsis(self):
res1 = transcribe.get_cmu(self.words6, db_type='sql')
res2 = transcribe.get_cmu(self.words6, db_type='json')
self.assertEqual(res1, self.cmu6)
self.assertEqual(res2, self.cmu6)
self.assertEqual(res1, res2)

def test_cmu_to_ipa_ellipsis(self):
res1 = transcribe.cmu_to_ipa(self.cmu6, stress_marking='both')
self.assertEqual(res1, self.ipa6)