Skip to content

Commit

Permalink
Tests for by_phrase and speaker warning
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbrickhouse committed Mar 20, 2024
1 parent 057cafc commit 09fc310
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions tests/test_formatter.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,44 @@
import math
import json
import numpy.testing as nptest
import pytest
import textgrid
import warnings

import formatter

class TestFormatter():
Format = formatter.Formatter()

def test_to_TextGrid(self):
for input_fname, _ in self.provide_to_TextGrid():
for input_fname, by_phrase in self.provide_to_TextGrid():
with open(input_fname) as f:
case = json.load(f)
observed = self.Format.to_TextGrid(case, by_phrase=False)
observed = self.Format.to_TextGrid(case, by_phrase=by_phrase)

assert observed.maxTime is not None
assert len(observed.tiers) > 0

def test_no_speaker_warning(self):
for input_fname in self.provide_no_speaker_warning():
with open(input_fname) as f:
case = json.load(f)
with pytest.warns(UserWarning, match="No speaker for segment") as record:
_ = self.Format.to_TextGrid(case, by_phrase=False)

def provide_to_TextGrid(self):
return [
(
'tests/data/TestAudio_SnoopDogg_85SouthMedia_WhisperTimestampSegments.json',
''
True
),
(
'tests/data/TestAudio_SnoopDogg_85SouthMedia_WhisperTimestampSegments.json',
False
),
]

def provide_no_speaker_warning(self):
return [
'tests/data/TestAudio_SnoopDogg_85SouthMedia.json',
]

0 comments on commit 09fc310

Please sign in to comment.