Skip to content

Commit

Permalink
Merge pull request #155 from NickleDave/fix-audio-wav-annot-phn-filen…
Browse files Browse the repository at this point in the history
…ame-issues

Fix issues with dir/filenames for audio-wav-annot-phn test data
  • Loading branch information
NickleDave committed Apr 6, 2022
2 parents a69fb38 + 97ef380 commit 05f5403
Show file tree
Hide file tree
Showing 28 changed files with 18 additions and 18 deletions.
12 changes: 6 additions & 6 deletions tests/fixtures/phn.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ def a_phn(phns):


@pytest.fixture
def audio_WAV_annot_PHN_root(test_data_root):
return test_data_root / 'audio_WAV_annot_PHN'
def audio_wav_nist_annot_phn_root(test_data_root):
return test_data_root / 'audio_wav_nist_annot_phn'


@pytest.fixture
def PHNs(audio_WAV_annot_PHN_root):
return sorted(audio_WAV_annot_PHN_root.glob('*.PHN'))
def wav_nist_phns(audio_wav_nist_annot_phn_root):
return sorted(audio_wav_nist_annot_phn_root.glob('*.PHN'))


@pytest.fixture
def a_PHN(PHNs):
return PHNs[0]
def a_wav_nist_phn(wav_nist_phns):
return wav_nist_phns[0]
24 changes: 12 additions & 12 deletions tests/test_phn.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,37 +64,37 @@ def test_annot2phn(tmp_path, phns):
assert np.all(np.char.equal(annot.seq.labels, annot_made.seq.labels))


def test_PHN2annot_single_str(a_PHN):
def test_PHN2annot_single_str(a_wav_nist_phn):
"""same unit-test as above, but here
test function still works when .phn extension is capitalized
and audio files are alternate .WAV format"""
annot = crowsetta.phn.phn2annot(a_PHN)
annot = crowsetta.phn.phn2annot(a_wav_nist_phn)
assert type(annot) == crowsetta.Annotation
assert hasattr(annot, 'seq')


def test_PHN2annot_list_of_str(PHNs):
def test_PHN2annot_list_of_str(wav_nist_phns):
"""same unit-test as above, but here
test function still works when .phn extension is capitalized
and audio files are alternate .WAV format"""
PHNs = [str(PHN) for PHN in PHNs]
PHNs = [str(PHN) for PHN in wav_nist_phns]
annots = crowsetta.phn.phn2annot(PHNs)
assert isinstance(annots, list)
assert len(annots) == len(PHNs)
assert all([type(annot) == crowsetta.Annotation for annot in annots])


def test_PHN2annot_list_of_Path(PHNs):
def test_PHN2annot_list_of_Path(wav_nist_phns):
"""same unit-test as above, but here
test function still works when .phn extension is capitalized
and audio files are alternate .WAV format"""
annots = crowsetta.phn.phn2annot(PHNs)
annots = crowsetta.phn.phn2annot(wav_nist_phns)
assert isinstance(annots, list)
assert len(annots) == len(PHNs)
assert len(annots) == len(wav_nist_phns)
assert all([type(annot) == crowsetta.Annotation for annot in annots])


def test_PHN2csv(tmp_path, PHNs):
def test_PHN2csv(tmp_path, wav_nist_phns):
"""same unit-test as above, but here
test function still works when .phn extension is capitalized
and audio files are alternate .WAV format"""
Expand All @@ -103,7 +103,7 @@ def test_PHN2csv(tmp_path, PHNs):
# and those are tested above and in other test modules,
# here just need to make sure this function doesn't fail
csv_filename = tmp_path / 'test.csv'
crowsetta.phn.phn2csv(PHNs, csv_filename)
crowsetta.phn.phn2csv(wav_nist_phns, csv_filename)
# make sure file was created
assert csv_filename.exists()

Expand All @@ -118,12 +118,12 @@ def test_PHN2csv(tmp_path, PHNs):
filenames_from_csv.append(
os.path.basename(row['annot_path'])
)
for phn_name in PHNs:
for phn_name in wav_nist_phns:
assert os.path.basename(phn_name) in filenames_from_csv


def test_annot2PHN(tmp_path, PHNs):
for phn in PHNs:
def test_annot2PHN(tmp_path, wav_nist_phns):
for phn in wav_nist_phns:
annot = crowsetta.phn.phn2annot(phn, round_times=False)
annot_path = Path(tmp_path).joinpath(Path(phn).name)
# copy wav file to tmp_path so we can open the annot
Expand Down

0 comments on commit 05f5403

Please sign in to comment.