From a66fc7ca4142930cc1973526c8139565e6acbdf1 Mon Sep 17 00:00:00 2001 From: Jaisen Mathai Date: Wed, 23 Mar 2016 09:34:35 -0700 Subject: [PATCH] gh-31 Remove raise SkipTest for geolocation tests due to precision loss --- elodie/media/photo.py | 2 +- elodie/tests/helper.py | 3 +++ elodie/tests/media/audio_test.py | 13 ++++++------- elodie/tests/media/photo_test.py | 13 ++++++------- elodie/tests/media/video_test.py | 13 ++++++------- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/elodie/media/photo.py b/elodie/media/photo.py index 1f599b9..e97eae3 100644 --- a/elodie/media/photo.py +++ b/elodie/media/photo.py @@ -27,7 +27,7 @@ class Photo(Media): __name__ = 'Photo' #: Valid extensions for photo files. - extensions = ('jpg', 'jpeg', 'nef', 'dng', 'gif') + extensions = ('nef', 'dng', 'gif', 'jpg', 'jpeg') def __init__(self, source=None): super(Photo, self).__init__(source) diff --git a/elodie/tests/helper.py b/elodie/tests/helper.py index 3c7afea..5e07309 100644 --- a/elodie/tests/helper.py +++ b/elodie/tests/helper.py @@ -118,6 +118,9 @@ def time_convert(s_time): # with relative tolerance c def isclose(a, b, rel_tol = 1e-8): + if not isinstance(a, (int, float)) or not isinstance(b, (int, float)): + return False + diff = abs(a - b) return (diff <= abs(rel_tol * a) and diff <= abs(rel_tol * b)) diff --git a/elodie/tests/media/audio_test.py b/elodie/tests/media/audio_test.py index b0a0fa7..6192ea7 100644 --- a/elodie/tests/media/audio_test.py +++ b/elodie/tests/media/audio_test.py @@ -102,7 +102,6 @@ def test_set_location(): if not can_edit_exif(): raise SkipTest('avmetareadwrite executable not found') - raise SkipTest('gh-31, precision is lost in conversion from decimal to dms') temporary_folder, folder = helper.create_working_folder() origin = '%s/audio.m4a' % folder @@ -111,9 +110,10 @@ def test_set_location(): audio = Audio(origin) origin_metadata = audio.get_metadata() - # Verify that original photo has no location information - #assert origin_metadata['latitude'] is None, origin_metadata['latitude'] - #assert origin_metadata['longitude'] is None, origin_metadata['longitude'] + # Verify that original audio has different location info that what we + # will be setting and checking + assert not helper.isclose(origin_metadata['latitude'], 11.1111111111), origin_metadata['latitude'] + assert not helper.isclose(origin_metadata['longitude'], 99.9999999999), origin_metadata['longitude'] status = audio.set_location(11.1111111111, 99.9999999999) @@ -124,9 +124,8 @@ def test_set_location(): shutil.rmtree(folder) - # @TODO: understand why the decimal to degree conversion loses accuracy - assert metadata['latitude'] == 11.1111111111, metadata['latitude'] - assert metadata['longitude'] == 99.9999999999, metadata['longitude'] + assert helper.isclose(metadata['latitude'], 11.1111111111), metadata['latitude'] + assert helper.isclose(metadata['longitude'], 99.9999999999), metadata['longitude'] def test_set_title(): if not can_edit_exif(): diff --git a/elodie/tests/media/photo_test.py b/elodie/tests/media/photo_test.py index d371477..221364a 100644 --- a/elodie/tests/media/photo_test.py +++ b/elodie/tests/media/photo_test.py @@ -168,7 +168,6 @@ def test_set_date_taken(): assert date_taken == helper.time_convert((2013, 9, 30, 7, 6, 5, 0, 273, 0)), metadata['date_taken'] def test_set_location(): - raise SkipTest('gh-31, precision is lost in conversion from decimal to dms') temporary_folder, folder = helper.create_working_folder() origin = '%s/photo.jpg' % folder @@ -177,9 +176,10 @@ def test_set_location(): photo = Photo(origin) origin_metadata = photo.get_metadata() - # Verify that original photo has no location information - assert origin_metadata['latitude'] is None, origin_metadata['latitude'] - assert origin_metadata['longitude'] is None, origin_metadata['longitude'] + # Verify that original photo has different location info that what we + # will be setting and checking + assert not helper.isclose(origin_metadata['latitude'], 11.1111111111), origin_metadata['latitude'] + assert not helper.isclose(origin_metadata['longitude'], 99.9999999999), origin_metadata['longitude'] status = photo.set_location(11.1111111111, 99.9999999999) @@ -190,9 +190,8 @@ def test_set_location(): shutil.rmtree(folder) - # @TODO: understand why the decimal to degree conversion loses accuracy - assert metadata['latitude'] == 11.1111111111, metadata['latitude'] - assert metadata['longitude'] == 99.9999999999, metadata['longitude'] + assert helper.isclose(metadata['latitude'], 11.1111111111), metadata['latitude'] + assert helper.isclose(metadata['longitude'], 99.9999999999), metadata['longitude'] def test_set_title(): temporary_folder, folder = helper.create_working_folder() diff --git a/elodie/tests/media/video_test.py b/elodie/tests/media/video_test.py index 2ae9560..118c58d 100644 --- a/elodie/tests/media/video_test.py +++ b/elodie/tests/media/video_test.py @@ -101,7 +101,6 @@ def test_set_location(): if not can_edit_exif(): raise SkipTest('avmetareadwrite executable not found') - raise SkipTest('gh-31, precision is lost in conversion from decimal to dms') temporary_folder, folder = helper.create_working_folder() origin = '%s/video.mov' % folder @@ -110,9 +109,10 @@ def test_set_location(): video = Video(origin) origin_metadata = video.get_metadata() - # Verify that original photo has no location information - #assert origin_metadata['latitude'] is None, origin_metadata['latitude'] - #assert origin_metadata['longitude'] is None, origin_metadata['longitude'] + # Verify that original video has different location info that what we + # will be setting and checking + assert not helper.isclose(origin_metadata['latitude'], 11.1111111111), origin_metadata['latitude'] + assert not helper.isclose(origin_metadata['longitude'], 99.9999999999), origin_metadata['longitude'] status = video.set_location(11.1111111111, 99.9999999999) @@ -123,9 +123,8 @@ def test_set_location(): shutil.rmtree(folder) - # @TODO: understand why the decimal to degree conversion loses accuracy - assert metadata['latitude'] == 11.1111111111, metadata['latitude'] - assert metadata['longitude'] == 99.9999999999, metadata['longitude'] + assert helper.isclose(metadata['latitude'], 11.1111111111), metadata['latitude'] + assert helper.isclose(metadata['longitude'], 99.9999999999), metadata['longitude'] def test_set_title(): if not can_edit_exif():