From 09fc31066641de01bb674983e5b4af71c3ea69e2 Mon Sep 17 00:00:00 2001 From: Christian Brickhouse Date: Wed, 20 Mar 2024 14:36:41 -0700 Subject: [PATCH] Tests for by_phrase and speaker warning --- tests/test_formatter.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/tests/test_formatter.py b/tests/test_formatter.py index aa92ceb..0509e57 100644 --- a/tests/test_formatter.py +++ b/tests/test_formatter.py @@ -1,7 +1,9 @@ import math import json import numpy.testing as nptest +import pytest import textgrid +import warnings import formatter @@ -9,18 +11,34 @@ 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', ]