Skip to content

Commit

Permalink
test: quiet the test suites by quenching pointless DEBUG logs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
joanise committed Feb 1, 2024
1 parent fbf9849 commit ffb3e84
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions readalongs/audio_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)"""
Expand Down
8 changes: 7 additions & 1 deletion test/basic_test_case.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Common base class for the ReadAlongs test suites"""

import logging
import tempfile
from pathlib import Path
from unittest import TestCase
Expand All @@ -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
Expand Down Expand Up @@ -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)
4 changes: 2 additions & 2 deletions test/test_force_align.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"""
Expand Down

0 comments on commit ffb3e84

Please sign in to comment.