gh-113 Check for a file extension before doing a string in tuple conditional

This commit is contained in:
Jaisen Mathai 2016-04-19 21:24:41 -07:00
parent b986c779e5
commit bd32c87b37
No known key found for this signature in database
GPG Key ID: 054172834C952A76
3 changed files with 15 additions and 3 deletions

View File

@ -187,9 +187,10 @@ class Base(object):
extension = os.path.splitext(_file)[1][1:].lower() extension = os.path.splitext(_file)[1][1:].lower()
for i in classes: if len(extension) > 0:
if(extension in i.extensions): for i in classes:
return i(_file) if(extension in i.extensions):
return i(_file)
return None return None

View File

View File

@ -15,6 +15,11 @@ sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.realp
import helper import helper
from elodie.media.base import Base 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' os.environ['TZ'] = 'GMT'
@ -33,3 +38,9 @@ def test_set_album_from_folder_invalid_file():
assert status == False, status 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