def test_media_iptc_override(settings): img_with_md = Image('2.jpg', 'iptcTest', settings) assert img_with_md.title == "Markdown title beats iptc" # Markdown parsing adds formatting. Let's just focus on content assert "Markdown description beats iptc" in img_with_md.description img_no_md = Image('1.jpg', 'iptcTest', settings) assert img_no_md.title == 'Haemostratulus clouds over Canberra - ' + \ '2005-12-28 at 03-25-07' assert img_no_md.description == \ '"Haemo" because they look like haemoglobin ' + \ 'cells and "stratulus" because I can\'t work out whether ' + \ 'they\'re Stratus or Cumulus clouds.\nWe\'re driving down ' + \ 'the main drag in Canberra so it\'s Parliament House that ' + \ 'you can see at the end of the road.'
def test_process_image(tmpdir): "Test the process_image function." status = process_image(Image('foo.txt', 'bar', create_settings())) assert status == Status.FAILURE settings = create_settings( img_processor='ResizeToFill', make_thumbs=False, source=os.path.join(SRCDIR, 'dir2'), destination=str(tmpdir), ) image = Image(TEST_IMAGE, '.', settings) status = process_image(image) assert status == Status.SUCCESS im = PILImage.open(os.path.join(str(tmpdir), TEST_IMAGE)) assert im.size == settings['img_size']
def test_image(settings, tmpdir): settings['destination'] = str(tmpdir) m = Image('11.jpg', 'dir1/test1', settings) assert m.exif['datetime'] == u'Sunday, 22. January 2006' os.makedirs(join(settings['destination'], 'dir1', 'test1', 'thumbnails')) assert m.thumbnail == join('thumbnails', '11.tn.jpg') assert os.path.isfile(m.thumb_path)
def test_image(settings, tmpdir): settings['destination'] = str(tmpdir) settings['datetime_format'] = '%d/%m/%Y' m = Image('11.jpg', 'dir1/test1', settings) assert m.date == datetime.datetime(2006, 1, 22, 10, 32, 42) assert m.exif['datetime'] == '22/01/2006' os.makedirs(join(settings['destination'], 'dir1', 'test1', 'thumbnails')) assert m.thumbnail == join('thumbnails', '11.tn.jpg') assert os.path.isfile(m.thumb_path)
def test_media_orig(settings, tmpdir): settings['keep_orig'] = False m = Media('11.jpg', 'dir1/test1', settings) assert m.big is None settings['keep_orig'] = True settings['destination'] = str(tmpdir) m = Image('11.jpg', 'dir1/test1', settings) assert m.big == 'original/11.jpg' m = Video('stallman software-freedom-day-low.ogv', 'video', settings) assert m.filename == 'stallman software-freedom-day-low.webm' assert m.big == 'original/stallman software-freedom-day-low.ogv' assert os.path.isfile(join(settings['destination'], m.path, m.big)) settings['use_orig'] = True m = Image('21.jpg', 'dir1/test2', settings) assert m.big == '21.jpg'
def test_media_orig(settings, tmpdir): settings['keep_orig'] = False m = Media('11.jpg', 'dir1/test1', settings) assert m.big is None settings['keep_orig'] = True settings['destination'] = str(tmpdir) m = Image('11.jpg', 'dir1/test1', settings) assert m.big == 'original/11.jpg' m = Video('example video.ogv', 'video', settings) assert m.filename == 'example video.webm' assert m.big_url == 'original/example%20video.ogv' assert os.path.isfile(join(settings['destination'], m.path, m.big)) settings['use_orig'] = True m = Image('21.jpg', 'dir1/test2', settings) assert m.big == '21.jpg'
def test_media_orig(settings): settings['keep_orig'] = False m = Media('11.jpg', 'dir1/test1', settings) assert m.big is None settings['keep_orig'] = True m = Image('11.jpg', 'dir1/test1', settings) assert m.big == 'original/11.jpg' m = Video('file.ogv', 'video', settings) assert m.filename == 'file.webm' assert m.big == 'original/file.ogv'
def test_save_cache(settings, tmpdir): settings['destination'] = str(tmpdir) gal = Gallery(settings, ncpu=1) extended_caching.save_cache(gal) cachePath = os.path.join(settings['destination'], ".metadata_cache") assert os.path.isfile(cachePath) with open(cachePath, "rb") as cacheFile: cache = pickle.load(cacheFile) # test exif album = gal.albums["exifTest"] cache_img = cache["exifTest/21.jpg"] assert cache_img["exif"] == album.medias[0].exif assert 'markdown_metadata' not in cache_img assert cache_img["file_metadata"] == album.medias[0].file_metadata cache_img = cache["exifTest/22.jpg"] assert cache_img["exif"] == album.medias[1].exif assert 'markdown_metadata' not in cache_img assert cache_img["file_metadata"] == album.medias[1].file_metadata cache_img = cache["exifTest/noexif.png"] assert cache_img["exif"] == album.medias[2].exif assert 'markdown_metadata' not in cache_img assert cache_img["file_metadata"] == album.medias[2].file_metadata # test iptc and md album = gal.albums["iptcTest"] assert cache["iptcTest/_index"][ "markdown_metadata"] == album.markdown_metadata cache_img = cache["iptcTest/1.jpg"] assert cache_img["file_metadata"] == album.medias[0].file_metadata assert 'markdown_metadata' not in cache_img cache_img = cache["iptcTest/2.jpg"] assert cache_img["markdown_metadata"] == album.medias[1].markdown_metadata # test if file disappears gal.albums["exifTest"].medias.append( Image("foooo.jpg", "exifTest", settings)) extended_caching.save_cache(gal) with open(cachePath, "rb") as cacheFile: cache = pickle.load(cacheFile) assert "exifTest/foooo.jpg" not in cache
def test_media_img_format(settings): settings['img_format'] = 'jpeg' m = Image('11.tiff', 'dir1/test1', settings) path = join('dir1', 'test1') thumb = join('thumbnails', '11.tn.jpeg') assert m.dst_filename == '11.jpeg' assert m.src_path == join(settings['source'], path, '11.tiff') assert m.dst_path == join(settings['destination'], path, '11.jpeg') assert m.thumb_name == thumb assert m.thumb_path == join(settings['destination'], path, thumb) assert m.title == "Foo Bar" assert m.description == "<p>This is a funny description of this image</p>" file_path = join(path, '11.tiff') assert repr(m) == f"<Image>('{file_path}')" assert str(m) == file_path
def test_load_metadata_missing(settings, tmpdir): settings['destination'] = str(tmpdir) gal = Gallery(settings, ncpu=1) extended_caching.save_cache(gal) assert gal.metadataCache # test if file disappears gal.albums["exifTest"].medias.append( Image("foooo.jpg", "exifTest", settings)) # set mod_date to -1 to force cache update gal.metadataCache = { "exifTest/_index": { "mod_date": -1, }, "exifTest/21.jpg": { "exif": "Foo", "mod_date": -1 }, "exifTest/foooo.jpg": { "exif": "Foo" }, "dir1/test2/22.jpg": { "exif": "Bar", "mod_date": 100000000000, "meta_mod_date": -1, "markdown_metadata": "Bar", }, } # errors should all be caught extended_caching.load_metadata(gal.albums["exifTest"]) assert gal.albums["exifTest"].medias[0].exif != "Foo" assert gal.albums["exifTest"].medias[-1].exif != "Foo" extended_caching.load_metadata(gal.albums["dir1/test2"]) assert gal.albums["dir1/test2"].medias[1].exif == "Bar" assert gal.albums["dir1/test2"].medias[1].markdown_metadata != "Bar"