gh-40 Create test generator for testing various RAW formats
This commit is contained in:
parent
1ad3d16da6
commit
5f5ba73934
|
@ -30,7 +30,7 @@ class Photo(Media):
|
||||||
__name__ = 'Photo'
|
__name__ = 'Photo'
|
||||||
|
|
||||||
#: Valid extensions for photo files.
|
#: 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):
|
def __init__(self, source=None):
|
||||||
super(Photo, self).__init__(source)
|
super(Photo, self).__init__(source)
|
||||||
|
|
|
@ -23,11 +23,14 @@ def test_photo_extensions():
|
||||||
photo = Photo()
|
photo = Photo()
|
||||||
extensions = photo.extensions
|
extensions = photo.extensions
|
||||||
|
|
||||||
|
assert 'arw' in extensions
|
||||||
|
assert 'cr2' in extensions
|
||||||
|
assert 'dng' in extensions
|
||||||
|
assert 'gif' in extensions
|
||||||
assert 'jpg' in extensions
|
assert 'jpg' in extensions
|
||||||
assert 'jpeg' in extensions
|
assert 'jpeg' in extensions
|
||||||
assert 'nef' in extensions
|
assert 'nef' in extensions
|
||||||
assert 'dng' in extensions
|
assert 'rw2' in extensions
|
||||||
assert 'gif' in extensions
|
|
||||||
|
|
||||||
valid_extensions = Photo.get_valid_extensions()
|
valid_extensions = Photo.get_valid_extensions()
|
||||||
|
|
||||||
|
@ -282,19 +285,41 @@ def test_set_title_non_ascii():
|
||||||
|
|
||||||
assert metadata['title'] == unicode_title, metadata['title']
|
assert metadata['title'] == unicode_title, metadata['title']
|
||||||
|
|
||||||
def test_get_metadata_from_nef():
|
# This is a test generator that will test reading and writing to
|
||||||
|
# various RAW formats. Each sample file has a different date which
|
||||||
|
# is the only information which needs to be added to run the tests
|
||||||
|
# for that file type.
|
||||||
|
# https://nose.readthedocs.io/en/latest/writing_tests.html#test-generators
|
||||||
|
def test_various_types():
|
||||||
|
types = Photo.extensions
|
||||||
|
#extensions = ('arw', 'cr2', 'dng', 'gif', 'jpeg', 'jpg', 'nef', 'rw2')
|
||||||
|
dates = {
|
||||||
|
'arw': (2007, 4, 8, 17, 41, 18, 6, 98, 0),
|
||||||
|
'cr2': (2005, 10, 29, 16, 14, 44, 5, 302, 0),
|
||||||
|
'dng': (2009, 10, 20, 9, 10, 46, 1, 293, 0),
|
||||||
|
'nef': (2008, 10, 24, 9, 12, 56, 4, 298, 0),
|
||||||
|
'rw2': (2014, 11, 19, 23, 7, 44, 2, 323, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
for type in types:
|
||||||
|
if type in dates:
|
||||||
|
yield (_test_photo_type_get, type, dates[type])
|
||||||
|
yield (_test_photo_type_set, type, dates[type])
|
||||||
|
|
||||||
|
def _test_photo_type_get(type, date):
|
||||||
temporary_folder, folder = helper.create_working_folder()
|
temporary_folder, folder = helper.create_working_folder()
|
||||||
|
|
||||||
photo_file = helper.get_file('photo.nef')
|
photo_name = 'photo.{}'.format(type)
|
||||||
origin = '%s/photo.nef' % folder
|
photo_file = helper.get_file(photo_name)
|
||||||
|
origin = '{}/{}'.format(folder, photo_name)
|
||||||
|
|
||||||
if not photo_file:
|
if not photo_file:
|
||||||
photo_file = helper.download_file('photo.nef', folder)
|
photo_file = helper.download_file(photo_name, folder)
|
||||||
if not photo_file or not os.path.isfile(photo_file):
|
if not photo_file or not os.path.isfile(photo_file):
|
||||||
raise SkipTest('nef file not downlaoded')
|
raise SkipTest('nef file not downlaoded')
|
||||||
|
|
||||||
# downloading for each test is costly so we save it in the working directory
|
# downloading for each test is costly so we save it in the working directory
|
||||||
file_path_save_as = helper.get_file_path('photo.nef')
|
file_path_save_as = helper.get_file_path(photo_name)
|
||||||
if os.path.isfile(photo_file):
|
if os.path.isfile(photo_file):
|
||||||
shutil.copyfile(photo_file, file_path_save_as)
|
shutil.copyfile(photo_file, file_path_save_as)
|
||||||
|
|
||||||
|
@ -305,18 +330,19 @@ def test_get_metadata_from_nef():
|
||||||
|
|
||||||
shutil.rmtree(folder)
|
shutil.rmtree(folder)
|
||||||
|
|
||||||
assert metadata['date_taken'] == helper.time_convert((2008, 10, 24, 9, 12, 56, 4, 298, 0)), metadata['date_taken']
|
assert metadata['date_taken'] == helper.time_convert(date), '{} date {}'.format(type, metadata['date_taken'])
|
||||||
|
|
||||||
def test_set_metadata_on_nef():
|
def _test_photo_type_set(type, date):
|
||||||
temporary_folder, folder = helper.create_working_folder()
|
temporary_folder, folder = helper.create_working_folder()
|
||||||
|
|
||||||
photo_file = helper.get_file('photo.nef')
|
photo_name = 'photo.{}'.format(type)
|
||||||
origin = '%s/photo.nef' % folder
|
photo_file = helper.get_file(photo_name)
|
||||||
|
origin = '{}/{}'.format(folder, photo_name)
|
||||||
|
|
||||||
if not photo_file:
|
if not photo_file:
|
||||||
photo_file = helper.download_file('photo.nef', folder)
|
photo_file = helper.download_file(photo_name, folder)
|
||||||
if not photo_file or not os.path.isfile(photo_file):
|
if not photo_file or not os.path.isfile(photo_file):
|
||||||
raise SkipTest('nef file not downlaoded')
|
raise SkipTest('{} file not downlaoded'.format(type))
|
||||||
|
|
||||||
shutil.copyfile(photo_file, origin)
|
shutil.copyfile(photo_file, origin)
|
||||||
|
|
||||||
|
@ -332,169 +358,6 @@ def test_set_metadata_on_nef():
|
||||||
|
|
||||||
shutil.rmtree(folder)
|
shutil.rmtree(folder)
|
||||||
|
|
||||||
assert metadata['date_taken'] == helper.time_convert((2008, 10, 24, 9, 12, 56, 4, 298, 0)), metadata['date_taken']
|
assert metadata['date_taken'] == helper.time_convert(date), '{} date {}'.format(type, metadata['date_taken'])
|
||||||
assert helper.isclose(metadata['latitude'], 11.1111111111), metadata['latitude']
|
assert helper.isclose(metadata['latitude'], 11.1111111111), '{} lat {}'.format(type, metadata['latitude'])
|
||||||
assert helper.isclose(metadata['longitude'], 99.9999999999), metadata['longitude']
|
assert helper.isclose(metadata['longitude'], 99.9999999999), '{} lon {}'.format(type, metadata['latitude'])
|
||||||
|
|
||||||
def test_get_metadata_from_dng():
|
|
||||||
temporary_folder, folder = helper.create_working_folder()
|
|
||||||
|
|
||||||
photo_file = helper.get_file('photo.dng')
|
|
||||||
origin = '%s/photo.dng' % folder
|
|
||||||
|
|
||||||
if not photo_file:
|
|
||||||
photo_file = helper.download_file('photo.dng', folder)
|
|
||||||
if not photo_file or not os.path.isfile(photo_file):
|
|
||||||
raise SkipTest('dng 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.dng')
|
|
||||||
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((2009, 10, 20, 9, 10, 46, 1, 293, 0)), metadata['date_taken']
|
|
||||||
|
|
||||||
def test_set_metadata_on_dng():
|
|
||||||
temporary_folder, folder = helper.create_working_folder()
|
|
||||||
|
|
||||||
photo_file = helper.get_file('photo.dng')
|
|
||||||
origin = '%s/photo.dng' % folder
|
|
||||||
|
|
||||||
if not photo_file:
|
|
||||||
photo_file = helper.download_file('photo.dng', folder)
|
|
||||||
if not photo_file or not os.path.isfile(photo_file):
|
|
||||||
raise SkipTest('dng 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((2009, 10, 20, 9, 10, 46, 1, 293, 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_rw2():
|
|
||||||
temporary_folder, folder = helper.create_working_folder()
|
|
||||||
|
|
||||||
photo_file = helper.get_file('photo.rw2')
|
|
||||||
origin = '%s/photo.rw2' % folder
|
|
||||||
|
|
||||||
if not photo_file:
|
|
||||||
photo_file = helper.download_file('photo.rw2', folder)
|
|
||||||
if not photo_file or not os.path.isfile(photo_file):
|
|
||||||
raise SkipTest('rw2 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.rw2')
|
|
||||||
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((2014, 11, 19, 23, 7, 44, 2, 323, 0)), metadata['date_taken']
|
|
||||||
|
|
||||||
def test_set_metadata_on_rw2():
|
|
||||||
raise SkipTest('gh-94 Writing to RW2 images is not supported')
|
|
||||||
temporary_folder, folder = helper.create_working_folder()
|
|
||||||
|
|
||||||
photo_file = helper.get_file('photo.rw2')
|
|
||||||
origin = '%s/photo.rw2' % folder
|
|
||||||
|
|
||||||
if not photo_file:
|
|
||||||
photo_file = helper.download_file('photo.rw2', folder)
|
|
||||||
if not photo_file or not os.path.isfile(photo_file):
|
|
||||||
raise SkipTest('rw2 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((2014, 11, 19, 23, 7, 44, 2, 323, 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_arw():
|
|
||||||
temporary_folder, folder = helper.create_working_folder()
|
|
||||||
|
|
||||||
photo_file = helper.get_file('photo.arw')
|
|
||||||
origin = '%s/photo.arw' % folder
|
|
||||||
|
|
||||||
if not photo_file:
|
|
||||||
photo_file = helper.download_file('photo.arw', folder)
|
|
||||||
if not photo_file or not os.path.isfile(photo_file):
|
|
||||||
raise SkipTest('arw 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.arw')
|
|
||||||
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((2007, 4, 8, 17, 41, 18, 6, 98, 0)), metadata['date_taken']
|
|
||||||
|
|
||||||
def test_set_metadata_on_arw():
|
|
||||||
temporary_folder, folder = helper.create_working_folder()
|
|
||||||
|
|
||||||
photo_file = helper.get_file('photo.arw')
|
|
||||||
origin = '%s/photo.arw' % folder
|
|
||||||
|
|
||||||
if not photo_file:
|
|
||||||
photo_file = helper.download_file('photo.arw', folder)
|
|
||||||
if not photo_file or not os.path.isfile(photo_file):
|
|
||||||
raise SkipTest('arw 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((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']
|
|
||||||
|
|
Loading…
Reference in New Issue