From 10e078baa586c8e17dc36a713eda7c4d36d1f09b Mon Sep 17 00:00:00 2001 From: Jaisen Mathai Date: Sun, 4 Sep 2016 16:10:30 -0700 Subject: [PATCH] gh-124 Add support for cr2 files --- elodie/media/photo.py | 2 +- elodie/tests/media/photo_test.py | 54 ++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/elodie/media/photo.py b/elodie/media/photo.py index 5d994e6..d85c6f8 100644 --- a/elodie/media/photo.py +++ b/elodie/media/photo.py @@ -30,7 +30,7 @@ class Photo(Media): __name__ = 'Photo' #: Valid extensions for photo files. - extensions = ('arw', 'dng', 'gif', 'jpeg', 'jpg', 'nef', 'rw2') + extensions = ('arw', 'cr2', 'dng', 'gif', 'jpeg', 'jpg', 'nef', 'rw2') def __init__(self, source=None): super(Photo, self).__init__(source) diff --git a/elodie/tests/media/photo_test.py b/elodie/tests/media/photo_test.py index d9dfa66..24ce4ad 100644 --- a/elodie/tests/media/photo_test.py +++ b/elodie/tests/media/photo_test.py @@ -498,3 +498,57 @@ def test_set_metadata_on_arw(): assert metadata['date_taken'] == helper.time_convert((2007, 4, 8, 17, 41, 18, 6, 98, 0)), metadata['date_taken'] assert helper.isclose(metadata['latitude'], 11.1111111111), metadata['latitude'] assert helper.isclose(metadata['longitude'], 99.9999999999), metadata['longitude'] + +def test_get_metadata_from_cr2(): + temporary_folder, folder = helper.create_working_folder() + + photo_file = helper.get_file('photo.cr2') + origin = '%s/photo.cr2' % folder + + if not photo_file: + photo_file = helper.download_file('photo.cr2', folder) + if not photo_file or not os.path.isfile(photo_file): + raise SkipTest('cr2 file not downlaoded') + + # downloading for each test is costly so we save it in the working directory + file_path_save_as = helper.get_file_path('photo.cr2') + if os.path.isfile(photo_file): + shutil.copyfile(photo_file, file_path_save_as) + + shutil.copyfile(photo_file, origin) + + photo = Photo(origin) + metadata = photo.get_metadata() + + shutil.rmtree(folder) + + assert metadata['date_taken'] == helper.time_convert((2005, 10, 29, 16, 14, 44, 5, 302, 0)), metadata['date_taken'] + +def test_set_metadata_on_cr2(): + temporary_folder, folder = helper.create_working_folder() + + photo_file = helper.get_file('photo.cr2') + origin = '%s/photo.cr2' % folder + + if not photo_file: + photo_file = helper.download_file('photo.cr2', folder) + if not photo_file or not os.path.isfile(photo_file): + raise SkipTest('cr2 file not downlaoded') + + shutil.copyfile(photo_file, origin) + + photo = Photo(origin) + origin_metadata = photo.get_metadata() + + status = photo.set_location(11.1111111111, 99.9999999999) + + assert status == True, status + + photo_new = Photo(origin) + metadata = photo_new.get_metadata() + + shutil.rmtree(folder) + + assert metadata['date_taken'] == helper.time_convert((2005, 10, 29, 16, 14, 44, 5, 302, 0)), metadata['date_taken'] + assert helper.isclose(metadata['latitude'], 11.1111111111), metadata['latitude'] + assert helper.isclose(metadata['longitude'], 99.9999999999), metadata['longitude']