Skip to content

Commit

Permalink
test loading samples from a corrupted audio file
Browse files Browse the repository at this point in the history
Verify that the correct exception is raised by the C extension. I'm not
sure why I didn't cover this code path before. It only makes sense to
test this path in checksums(), because nframes() does not try to load
the samples (it only reads the header).

corrupted.flac is a copy of sample.flac where some of the values were
overwritten with garbage in a hex editor, so that testing the file with
"flac -t" results in an error.
  • Loading branch information
arcctgx committed Jul 14, 2024
1 parent 36a366f commit 524c52b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/_audio_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
CWD = os.path.abspath(os.path.dirname(__file__))
NOT_AUDIO_PATH = CWD + '/data/samples/not_audio'
SAMPLE_VORBIS_PATH = CWD + '/data/samples/sample.ogg'
CORRUPTED_AUDIO_PATH = CWD + '/data/samples/corrupted.flac'


class TestExceptionsChecksums(unittest.TestCase):
Expand Down Expand Up @@ -41,6 +42,10 @@ def test_unsupported_audio_format(self):
with self.assertRaisesRegex(TypeError, 'Unsupported audio format'):
_audio.checksums(SAMPLE_VORBIS_PATH, 1, 9)

def test_corrupted_audio(self):
with self.assertRaisesRegex(OSError, 'Failed to load audio samples'):
_audio.checksums(CORRUPTED_AUDIO_PATH, 1, 9)


class TestExceptionsNframes(unittest.TestCase):
"""Test exceptions raised when getting the number of audio frames in a file."""
Expand Down
Binary file added tests/data/samples/corrupted.flac
Binary file not shown.

0 comments on commit 524c52b

Please sign in to comment.