From c3d7015d9dc01cd6b522ca8def4ea97fce0702ed Mon Sep 17 00:00:00 2001 From: boyska Date: Tue, 8 Aug 2017 13:40:04 +0200 Subject: [PATCH] FIX randomdir broken by files with unknown mimetype --- larigira/fsutils.py | 2 ++ larigira/tests/test_audiogen_randomdir.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/larigira/fsutils.py b/larigira/fsutils.py index 0cdbf41..2d5e9ab 100644 --- a/larigira/fsutils.py +++ b/larigira/fsutils.py @@ -20,6 +20,8 @@ def multi_fnmatch(fname, extensions): def is_audio(fname): mimetype = mimetypes.guess_type(fname)[0] + if mimetype is None: + return False return mimetype.split('/')[0] == 'audio' diff --git a/larigira/tests/test_audiogen_randomdir.py b/larigira/tests/test_audiogen_randomdir.py index 95944ae..89faf6f 100644 --- a/larigira/tests/test_audiogen_randomdir.py +++ b/larigira/tests/test_audiogen_randomdir.py @@ -43,3 +43,17 @@ def test_same_name(tmpdir): p.write('') assert len(candidates([P(tmpdir)])) == 2 + + +def test_unknown_mime_ignore(tmpdir): + p = tmpdir.join("foo.???") + p.write('') + assert len(candidates([P(tmpdir)])) == 0 + + +def test_unknown_mime_nocrash(tmpdir): + p = tmpdir.join("foo.???") + p.write('') + p = tmpdir.join("foo.ogg") + p.write('') + assert len(candidates([P(tmpdir)])) == 1