From ffb3e846ece5d9c25588eca35e9f9ca1382a8ea2 Mon Sep 17 00:00:00 2001 From: Eric Joanis Date: Thu, 1 Feb 2024 12:27:52 -0500 Subject: [PATCH] test: quiet the test suites by quenching pointless DEBUG logs audio_utils.py: we only ever want to see errors from pydub, no debug info, so set the pydub.converter logger to WARNING. This mostly has the effect of quietting previously very verbose test suites, but in general we just don't want to see DEBUG and INFO from pydub, WARNING and ERROR messages are plenty. basic_test_case.py: don't start by setting the log level to DEBUG, and in tearDown(), when it's DEBUG reset it to INFO, so an individual case can trigger DEBUG, e.g., with --debug, and test the effect, without making the rest of the suite verbose. remaining wish item I can't solve: test_force_align.py calls align_audio with debug_aligner=True once, for coverage, but I cannot figure out how to capture the logs from SoundSwallower, its own C stdout/stderr do not seem to be redirectable from Python. --- readalongs/audio_utils.py | 4 ++++ test/basic_test_case.py | 8 +++++++- test/test_force_align.py | 4 ++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/readalongs/audio_utils.py b/readalongs/audio_utils.py index 7ba85f7c..ade658a3 100644 --- a/readalongs/audio_utils.py +++ b/readalongs/audio_utils.py @@ -4,12 +4,16 @@ in millisecond slices and lets us manipulate them as if they were simple lists. """ +import logging from typing import Union from pydub import AudioSegment from readalongs.log import LOGGER +# quiet pydub's logging +logging.getLogger("pydub.converter").setLevel(logging.WARNING) + def join_section(audio: AudioSegment, audio_to_insert: AudioSegment, start: int): """Given two AudioSegments, insert the second into the first at start (ms)""" diff --git a/test/basic_test_case.py b/test/basic_test_case.py index 5f10c27d..719feccc 100644 --- a/test/basic_test_case.py +++ b/test/basic_test_case.py @@ -1,5 +1,6 @@ """Common base class for the ReadAlongs test suites""" +import logging import tempfile from pathlib import Path from unittest import TestCase @@ -20,7 +21,6 @@ class BasicTestCase(TestCase): text_file = self.data_dir / "ej-fra.txt" """ - LOGGER.setLevel("DEBUG") data_dir = Path(__file__).parent / "data" # Set this to True to keep the temp dirs after running, for manual inspection @@ -59,3 +59,9 @@ def tearDown(self): """ if not self.keep_temp_dir_after_running: self.tempdirobj.cleanup() + + if LOGGER.level == logging.DEBUG: + # LOGGER.error("Logging level is DEBUG") + # Some test cases can set the logging level to DEBUG when they pass + # --debug to a CLI command, but don't let that affect subsequent tests. + LOGGER.setLevel(logging.INFO) diff --git a/test/test_force_align.py b/test/test_force_align.py index 43032357..d27e2d4c 100755 --- a/test/test_force_align.py +++ b/test/test_force_align.py @@ -1,7 +1,7 @@ #!/usr/bin/env python """ -Test force-alignment with SoundsSwallower FSG search from Python API +Test force-alignment with SoundSwallower FSG search from Python API """ import os @@ -26,7 +26,7 @@ class TestForceAlignment(BasicTestCase): - """Unit testing suite for forced-alignment with SoundsSwallower""" + """Unit testing suite for forced-alignment with SoundSwallower""" def test_align(self): """Basic alignment test case with XML input"""