Skip to content

Commit

Permalink
Restore removed test files
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbrickhouse committed Oct 18, 2022
1 parent af8f871 commit 84b2c40
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 0 deletions.
76 changes: 76 additions & 0 deletions tests/fave/align/test_transcriptprocessor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
import logging
import pytest
from fave.align import transcriptprocessor
from fave import cmudictionary # We shouldn't be doing this...

# Copied from ../test_cmudictionary.py
# which means this really should be made a fixture...
KWARGS = {
'verbose': 1
}

CMU_EXCERPT = """
TEST T EH1 S T
TEST'S T EH1 S T S
TESTA T EH1 S T AH0
TESTAMENT T EH1 S T AH0 M AH0 N T
TESTAMENTARY T EH2 S T AH0 M EH1 N T ER0 IY0
TESTED T EH1 S T AH0 D
TESTER T EH1 S T ER0
TESTERMAN T EH1 S T ER0 M AH0 N
TESTERS T EH1 S T ER0 Z
TESTERS T EH1 S T AH0 Z
"""


def test_replace_smart_quotes():
def test_func( testcase ):
Expand Down Expand Up @@ -69,3 +91,57 @@ def provide_check_transcription_format_raises_value_error():
# Skip 5 entries (not an error)
[ 'a\tb\tc\td\te\tf', ValueError], # 6 entries
]

def test_read_transcription_file(tmp_path):
tmp_directory = tmp_path / "transcripts"
tmp_directory.mkdir()
tmp_file = tmp_directory / "test_transcript.csv"
dict_file = tmp_directory / "cmu.dict"
dict_file.write_text(CMU_EXCERPT)
cmu_dict = cmudictionary.CMU_Dictionary(dict_file, **KWARGS)
for test_case in provide_value_error_file():
test_text = test_case[0]
flags = test_case[1]
expected = test_case[2]
tmp_file.write_text(test_text)
tp_obj = transcriptprocessor.TranscriptProcessor(
tmp_file,
cmu_dict,
**flags
)
tp_obj.read_transcription_file()

assert tp_obj.lines == expected

def provide_value_error_file():
return [
[ # header row is detected and deleted
"Style\tSpeaker\tBeginning\tEnd\tDuration\nFoo\tBar\t0.0\t3.2\t3.2",
{
'prompt': "IDK what this is -CJB",
'check' : '',
'verbose': logging.DEBUG
},
['Foo\tBar\t0.0\t3.2\t3.2']
],
[ # test with one line
"Foo\tBar\t0.0\t3.2\t3.2\nTest\t1.0\t4.5\t3.5",
{
'prompt': "IDK what this is -CJB",
'check' : '',
'verbose': logging.DEBUG
},
['Foo\tBar\t0.0\t3.2\t3.2\n', 'Test\t1.0\t4.5\t3.5']
],
[ # test with more lines
"Foo\tBar\t0.0\t3.2\t3.2\nTest\t1.0\t4.5\t3.5\nTest\t1.0\t4.5\t3.5",
{
'prompt': "IDK what this is -CJB",
'check' : '',
'verbose': logging.DEBUG
},
['Foo\tBar\t0.0\t3.2\t3.2\n', 'Test\t1.0\t4.5\t3.5\n', 'Test\t1.0\t4.5\t3.5']
]

]

58 changes: 58 additions & 0 deletions tests/fave/extract/test_extractFormants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

from cmath import nan
import logging
import pytest
import numpy as np
from fave import extractFormants

def test_mean_stdv():
for test_case in provide_valuelist():
mean, stdv = extractFormants.mean_stdv(test_case[0])

assert mean == test_case[1]
assert stdv == test_case[2]

def provide_valuelist():
return [
[
[1, 2, 3, 4],
np.mean([1, 2, 3, 4]),
np.std([1, 2, 3, 4], ddof=1)
],
[
[3.5, 2.6, 11.6, 34.66, 2.8, 4.7],
np.mean([3.5, 2.6, 11.6, 34.66, 2.8, 4.7]),
np.std([3.5, 2.6, 11.6, 34.66, 2.8, 4.7], ddof=1)
],
[
[],
None,
None
],
[
[23, 34, 45, 56, 12, 312, 45, 943, 21, 1, 4, 6, 9, 2],
np.mean([23, 34, 45, 56, 12, 312, 45, 943, 21, 1, 4, 6, 9, 2]),
np.std([23, 34, 45, 56, 12, 312, 45, 943, 21, 1, 4, 6, 9, 2], ddof=1)
],
[
[3],
np.mean([3]),
0
],
[
[-1],
np.mean([-1]),
0
],
[
[3.5, 2.6, 11.6, None, 34.66, 2.8, 4.7],
np.nanmean(np.array([3.5, 2.6, 11.6, None, 34.66, 2.8, 4.7],
dtype=np.float64)),
np.nanstd(np.array([3.5, 2.6, 11.6, None, 34.66, 2.8, 4.7],
dtype=np.float64),
ddof=1)
]
]



0 comments on commit 84b2c40

Please sign in to comment.