From bd32c87b37e735bf54ef9b33e417dec40574a0b8 Mon Sep 17 00:00:00 2001 From: Jaisen Mathai Date: Tue, 19 Apr 2016 21:24:41 -0700 Subject: [PATCH] gh-113 Check for a file extension before doing a string in tuple conditional --- elodie/media/base.py | 7 ++++--- elodie/tests/files/withoutextension | 0 elodie/tests/media/base_test.py | 11 +++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 elodie/tests/files/withoutextension diff --git a/elodie/media/base.py b/elodie/media/base.py index 73b662a..7cf27c4 100644 --- a/elodie/media/base.py +++ b/elodie/media/base.py @@ -187,9 +187,10 @@ class Base(object): extension = os.path.splitext(_file)[1][1:].lower() - for i in classes: - if(extension in i.extensions): - return i(_file) + if len(extension) > 0: + for i in classes: + if(extension in i.extensions): + return i(_file) return None diff --git a/elodie/tests/files/withoutextension b/elodie/tests/files/withoutextension new file mode 100644 index 0000000..e69de29 diff --git a/elodie/tests/media/base_test.py b/elodie/tests/media/base_test.py index cbceb3c..955d76b 100644 --- a/elodie/tests/media/base_test.py +++ b/elodie/tests/media/base_test.py @@ -15,6 +15,11 @@ sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.realp import helper from elodie.media.base import Base +from elodie.media.media import Media +from elodie.media.audio import Audio +from elodie.media.text import Text +from elodie.media.photo import Photo +from elodie.media.video import Video os.environ['TZ'] = 'GMT' @@ -33,3 +38,9 @@ def test_set_album_from_folder_invalid_file(): assert status == False, status +def test_get_class_by_file_without_extension(): + base_file = helper.get_file('withoutextension') + + cls = Base.get_class_by_file(base_file, [Audio, Text, Photo, Video]) + + assert cls is None, cls