From 9b14c1b6bf4402b6a9dc6d9d691c665e17c05aac Mon Sep 17 00:00:00 2001 From: Yih-Dar <2521628+ydshieh@users.noreply.github.com> Date: Tue, 6 Dec 2022 15:48:49 +0100 Subject: [PATCH] Fix `AutomaticSpeechRecognitionPipelineTests.run_pipeline_test` (#20597) * Remove assert exception not triggered * Fix wrong expected exception string * fix * use assertRaisesRegex Co-authored-by: ydshieh --- .../test_pipelines_automatic_speech_recognition.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/tests/pipelines/test_pipelines_automatic_speech_recognition.py b/tests/pipelines/test_pipelines_automatic_speech_recognition.py index 09765f1790..5dd1c1748e 100644 --- a/tests/pipelines/test_pipelines_automatic_speech_recognition.py +++ b/tests/pipelines/test_pipelines_automatic_speech_recognition.py @@ -118,15 +118,9 @@ class AutomaticSpeechRecognitionPipelineTests(unittest.TestCase, metaclass=Pipel }, ) else: - # Non CTC models cannot use chunk_length - with self.assertRaises(ValueError) as v: - outputs = speech_recognizer(audio, chunk_length_s=10) - self.assertEqual(v.exception, "") - # Non CTC models cannot use return_timestamps - with self.assertRaises(ValueError) as v: + with self.assertRaisesRegex(ValueError, "^We cannot return_timestamps yet on non-ctc models !$"): outputs = speech_recognizer(audio, return_timestamps="char") - self.assertEqual(v.exception, "") @require_torch @slow @@ -148,9 +142,8 @@ class AutomaticSpeechRecognitionPipelineTests(unittest.TestCase, metaclass=Pipel self.assertEqual(output, {"text": "(Applaudissements)"}) # Non CTC models cannot use return_timestamps - with self.assertRaises(ValueError) as v: + with self.assertRaisesRegex(ValueError, "^We cannot return_timestamps yet on non-ctc models !$"): _ = speech_recognizer(waveform, return_timestamps="char") - self.assertEqual(str(v.exception), "We cannot return_timestamps yet on non-ctc models !") @require_torch def test_small_model_pt_seq2seq(self):