Use black
This commit is contained in:
@@ -1,37 +1,43 @@
|
||||
author = 'John Doe'
|
||||
title = 'Sigal test gallery ☺'
|
||||
source = 'pictures'
|
||||
thumb_suffix = '.tn'
|
||||
author = "John Doe"
|
||||
title = "Sigal test gallery ☺"
|
||||
source = "pictures"
|
||||
thumb_suffix = ".tn"
|
||||
keep_orig = True
|
||||
thumb_video_delay = 5
|
||||
# img_format = 'jpeg'
|
||||
|
||||
links = [('Example link', 'http://example.org'),
|
||||
('Another link', 'http://example.org')]
|
||||
links = [
|
||||
("Example link", "http://example.org"),
|
||||
("Another link", "http://example.org"),
|
||||
]
|
||||
|
||||
files_to_copy = (('../watermark.png', 'watermark.png'),)
|
||||
files_to_copy = (("../watermark.png", "watermark.png"),)
|
||||
|
||||
plugins = [
|
||||
'sigal.plugins.adjust',
|
||||
'sigal.plugins.copyright',
|
||||
'sigal.plugins.extended_caching',
|
||||
'sigal.plugins.feeds',
|
||||
'sigal.plugins.nomedia',
|
||||
'sigal.plugins.watermark',
|
||||
'sigal.plugins.zip_gallery',
|
||||
"sigal.plugins.adjust",
|
||||
"sigal.plugins.copyright",
|
||||
"sigal.plugins.extended_caching",
|
||||
"sigal.plugins.feeds",
|
||||
"sigal.plugins.nomedia",
|
||||
"sigal.plugins.watermark",
|
||||
"sigal.plugins.zip_gallery",
|
||||
]
|
||||
copyright = '© An example copyright message'
|
||||
adjust_options = {'color': 0.9, 'brightness': 1.0,
|
||||
'contrast': 1.0, 'sharpness': 0.0}
|
||||
watermark = 'watermark.png'
|
||||
copyright = "© An example copyright message"
|
||||
adjust_options = {
|
||||
"color": 0.9,
|
||||
"brightness": 1.0,
|
||||
"contrast": 1.0,
|
||||
"sharpness": 0.0,
|
||||
}
|
||||
watermark = "watermark.png"
|
||||
watermark_position = (10, 10)
|
||||
watermark_opacity = 0.3
|
||||
|
||||
theme = 'colorbox'
|
||||
theme = "colorbox"
|
||||
thumb_size = (200, 150)
|
||||
|
||||
rss_feed = {'feed_url': 'http://127.0.0.1:8000/feed.rss', 'nb_items': 10}
|
||||
atom_feed = {'feed_url': 'http://127.0.0.1:8000/feed.atom', 'nb_items': 10}
|
||||
rss_feed = {"feed_url": "http://127.0.0.1:8000/feed.rss", "nb_items": 10}
|
||||
atom_feed = {"feed_url": "http://127.0.0.1:8000/feed.atom", "nb_items": 10}
|
||||
|
||||
# theme = 'photoswipe'
|
||||
# theme = 'galleria'
|
||||
|
||||
@@ -19,8 +19,9 @@ def test_init(tmpdir):
|
||||
|
||||
result = runner.invoke(init, [config_file])
|
||||
assert result.exit_code == 1
|
||||
assert result.output == ("Found an existing config file, will abort to "
|
||||
"keep it safe.\n")
|
||||
assert (
|
||||
result.output == "Found an existing config file, will abort to keep it safe.\n"
|
||||
)
|
||||
|
||||
|
||||
def test_build(tmpdir, disconnect_signals):
|
||||
@@ -33,10 +34,11 @@ def test_build(tmpdir, disconnect_signals):
|
||||
try:
|
||||
result = runner.invoke(init, [config_file])
|
||||
assert result.exit_code == 0
|
||||
os.symlink(join(TESTGAL, 'watermark.png'),
|
||||
join(tmpdir, 'watermark.png'))
|
||||
os.symlink(join(TESTGAL, 'pictures', 'dir2', 'KeckObservatory20071020.jpg'),
|
||||
join(tmpdir, 'pictures', 'KeckObservatory20071020.jpg'))
|
||||
os.symlink(join(TESTGAL, 'watermark.png'), join(tmpdir, 'watermark.png'))
|
||||
os.symlink(
|
||||
join(TESTGAL, 'pictures', 'dir2', 'KeckObservatory20071020.jpg'),
|
||||
join(tmpdir, 'pictures', 'KeckObservatory20071020.jpg'),
|
||||
)
|
||||
|
||||
result = runner.invoke(build, ['-n', 1, '--debug'])
|
||||
assert result.exit_code == 1
|
||||
@@ -46,8 +48,7 @@ def test_build(tmpdir, disconnect_signals):
|
||||
result = runner.invoke(build, ['foo', '-n', 1, '--debug'])
|
||||
assert result.exit_code == 1
|
||||
|
||||
result = runner.invoke(build, ['pictures', 'pictures/out',
|
||||
'-n', 1, '--debug'])
|
||||
result = runner.invoke(build, ['pictures', 'pictures/out', '-n', 1, '--debug'])
|
||||
assert result.exit_code == 1
|
||||
|
||||
with open(config_file) as f:
|
||||
@@ -72,12 +73,13 @@ atom_feed = {'feed_url': 'http://example.org/feed.atom', 'nb_items': 10}
|
||||
with open(config_file, 'w') as f:
|
||||
f.write(text)
|
||||
|
||||
result = runner.invoke(build, ['pictures', 'build',
|
||||
'--title', 'Testing build',
|
||||
'-n', 1, '--debug'])
|
||||
result = runner.invoke(
|
||||
build, ['pictures', 'build', '--title', 'Testing build', '-n', 1, '--debug']
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
assert os.path.isfile(join(tmpdir, 'build', 'thumbnails',
|
||||
'KeckObservatory20071020.jpg'))
|
||||
assert os.path.isfile(
|
||||
join(tmpdir, 'build', 'thumbnails', 'KeckObservatory20071020.jpg')
|
||||
)
|
||||
assert os.path.isfile(join(tmpdir, 'build', 'feed.atom'))
|
||||
assert os.path.isfile(join(tmpdir, 'build', 'feed.rss'))
|
||||
assert os.path.isfile(join(tmpdir, 'build', 'watermark.png'))
|
||||
@@ -121,8 +123,9 @@ def test_set_meta(tmpdir):
|
||||
result = runner.invoke(set_meta, [str(testdir), "title", "testing"])
|
||||
assert result.exit_code == 2
|
||||
|
||||
result = runner.invoke(set_meta, [str(testdir.join("non-existant.jpg")),
|
||||
"title", "testing"])
|
||||
result = runner.invoke(
|
||||
set_meta, [str(testdir.join("non-existant.jpg")), "title", "testing"]
|
||||
)
|
||||
assert result.exit_code == 1
|
||||
|
||||
result = runner.invoke(set_meta, [str(testfile), "title", "testing"])
|
||||
|
||||
@@ -36,44 +36,53 @@ def walk_destination(destination, suffixes, compress_suffix):
|
||||
for path, dirs, files in os.walk(destination):
|
||||
for file in files:
|
||||
original_filename = os.path.join(path, file)
|
||||
compressed_filename = '{}.{}'.format(os.path.join(path, file),
|
||||
compress_suffix)
|
||||
compressed_filename = '{}.{}'.format(
|
||||
os.path.join(path, file), compress_suffix
|
||||
)
|
||||
path_exists = os.path.exists(compressed_filename)
|
||||
file_ext = os.path.splitext(file)[1][1:]
|
||||
if file_ext in suffixes:
|
||||
assert path_exists
|
||||
assert (os.stat(original_filename).st_mtime <=
|
||||
os.stat(compressed_filename).st_mtime)
|
||||
assert (
|
||||
os.stat(original_filename).st_mtime
|
||||
<= os.stat(compressed_filename).st_mtime
|
||||
)
|
||||
else:
|
||||
assert not path_exists
|
||||
|
||||
|
||||
@pytest.mark.parametrize("method,compress_suffix,test_import",
|
||||
[('gzip', 'gz', None),
|
||||
('zopfli', 'gz', 'zopfli.gzip'),
|
||||
('brotli', 'br', 'brotli')])
|
||||
def test_compress(disconnect_signals, settings, tmpdir, method,
|
||||
compress_suffix, test_import):
|
||||
@pytest.mark.parametrize(
|
||||
"method,compress_suffix,test_import",
|
||||
[('gzip', 'gz', None), ('zopfli', 'gz', 'zopfli.gzip'), ('brotli', 'br', 'brotli')],
|
||||
)
|
||||
def test_compress(
|
||||
disconnect_signals, settings, tmpdir, method, compress_suffix, test_import
|
||||
):
|
||||
if test_import:
|
||||
pytest.importorskip(test_import)
|
||||
|
||||
# Compress twice to test compression skip based on mtime
|
||||
for _ in range(2):
|
||||
compress_options = make_gallery(settings, tmpdir, method)
|
||||
walk_destination(settings['destination'],
|
||||
compress_options['suffixes'],
|
||||
compress_suffix)
|
||||
walk_destination(
|
||||
settings['destination'], compress_options['suffixes'], compress_suffix
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("method,compress_suffix,mask",
|
||||
[('zopfli', 'gz', 'zopfli.gzip'),
|
||||
('brotli', 'br', 'brotli'),
|
||||
('__does_not_exist__', 'br', None)])
|
||||
def test_failed_compress(disconnect_signals, settings, tmpdir,
|
||||
method, compress_suffix, mask):
|
||||
@pytest.mark.parametrize(
|
||||
"method,compress_suffix,mask",
|
||||
[
|
||||
('zopfli', 'gz', 'zopfli.gzip'),
|
||||
('brotli', 'br', 'brotli'),
|
||||
('__does_not_exist__', 'br', None),
|
||||
],
|
||||
)
|
||||
def test_failed_compress(
|
||||
disconnect_signals, settings, tmpdir, method, compress_suffix, mask
|
||||
):
|
||||
# See https://medium.com/python-pandemonium/how-to-test-your-imports-1461c1113be1
|
||||
with mock.patch.dict(sys.modules, {mask: None}):
|
||||
make_gallery(settings, tmpdir, method)
|
||||
walk_destination(settings['destination'],
|
||||
[], # No file should be compressed
|
||||
compress_suffix)
|
||||
walk_destination(
|
||||
settings['destination'], [], compress_suffix # No file should be compressed
|
||||
)
|
||||
|
||||
@@ -13,9 +13,7 @@ CURRENT_DIR = os.path.dirname(__file__)
|
||||
def get_key_tag(settings):
|
||||
options = settings["encrypt_options"]
|
||||
key = endec.kdf_gen_key(
|
||||
options["password"],
|
||||
options["kdf_salt"],
|
||||
options["kdf_iters"]
|
||||
options["password"], options["kdf_salt"], options["kdf_iters"]
|
||||
)
|
||||
tag = options["gcm_tag"].encode("utf-8")
|
||||
return (key, tag)
|
||||
@@ -32,7 +30,7 @@ def test_encrypt(settings, tmpdir, disconnect_signals):
|
||||
'gcm_tag': 'AuTheNTiCatIoNtAG',
|
||||
'kdf_salt': 'saltysaltsweetysweet',
|
||||
'kdf_iters': 10000,
|
||||
'encrypt_symlinked_originals': False
|
||||
'encrypt_symlinked_originals': False,
|
||||
}
|
||||
|
||||
init_plugins(settings)
|
||||
@@ -58,13 +56,11 @@ def test_encrypt(settings, tmpdir, disconnect_signals):
|
||||
assert "thumb_size" in encryptCache[cache_key(media)]
|
||||
assert "encrypted" in encryptCache[cache_key(media)]
|
||||
|
||||
encryptedImages = [
|
||||
media.dst_path,
|
||||
media.thumb_path
|
||||
]
|
||||
encryptedImages = [media.dst_path, media.thumb_path]
|
||||
if settings["keep_orig"]:
|
||||
encryptedImages.append(os.path.join(settings["destination"],
|
||||
media.path, media.big))
|
||||
encryptedImages.append(
|
||||
os.path.join(settings["destination"], media.path, media.big)
|
||||
)
|
||||
|
||||
# check if images are encrypted by trying to decrypt
|
||||
for image in encryptedImages:
|
||||
@@ -79,7 +75,8 @@ def test_encrypt(settings, tmpdir, disconnect_signals):
|
||||
assert os.path.isfile(os.path.join(settings["destination"], "sw.js"))
|
||||
|
||||
# check keycheck file
|
||||
with open(os.path.join(settings["destination"],
|
||||
'static', "keycheck.txt"), "rb") as infile:
|
||||
with open(
|
||||
os.path.join(settings["destination"], 'static', "keycheck.txt"), "rb"
|
||||
) as infile:
|
||||
with BytesIO() as outfile:
|
||||
endec.decrypt(key, infile, outfile, tag)
|
||||
|
||||
@@ -37,8 +37,7 @@ def test_load_exif(settings, tmpdir):
|
||||
settings['destination'] = str(tmpdir)
|
||||
gal1 = Gallery(settings, ncpu=1)
|
||||
gal1.albums["exifTest"].medias[2].exif = "blafoo"
|
||||
gal1.exifCache = {"exifTest/21.jpg": "Foo",
|
||||
"exifTest/22.jpg": "Bar"}
|
||||
gal1.exifCache = {"exifTest/21.jpg": "Foo", "exifTest/22.jpg": "Bar"}
|
||||
|
||||
extended_caching.load_exif(gal1.albums["exifTest"])
|
||||
|
||||
|
||||
@@ -24,9 +24,12 @@ REF = {
|
||||
'name': 'test1',
|
||||
'thumbnail': 'test1/thumbnails/11.tn.jpg',
|
||||
'subdirs': [],
|
||||
'medias': ['11.jpg', 'CMB_Timeline300_no_WMAP.jpg',
|
||||
'flickr_jerquiaga_2394751088_cc-by-nc.jpg',
|
||||
'example.gif'],
|
||||
'medias': [
|
||||
'11.jpg',
|
||||
'CMB_Timeline300_no_WMAP.jpg',
|
||||
'flickr_jerquiaga_2394751088_cc-by-nc.jpg',
|
||||
'example.gif',
|
||||
],
|
||||
},
|
||||
'dir1/test2': {
|
||||
'title': 'test2',
|
||||
@@ -47,10 +50,12 @@ REF = {
|
||||
'name': 'dir2',
|
||||
'thumbnail': 'dir2/thumbnails/m57_the_ring_nebula-587px.tn.jpg',
|
||||
'subdirs': [],
|
||||
'medias': ['KeckObservatory20071020.jpg',
|
||||
'Hubble Interacting Galaxy NGC 5257.jpg',
|
||||
'Hubble ultra deep field.jpg',
|
||||
'm57_the_ring_nebula-587px.jpg'],
|
||||
'medias': [
|
||||
'KeckObservatory20071020.jpg',
|
||||
'Hubble Interacting Galaxy NGC 5257.jpg',
|
||||
'Hubble ultra deep field.jpg',
|
||||
'm57_the_ring_nebula-587px.jpg',
|
||||
],
|
||||
},
|
||||
'accentué': {
|
||||
'title': 'accentué',
|
||||
@@ -64,14 +69,14 @@ REF = {
|
||||
'name': 'video',
|
||||
'thumbnail': 'video/thumbnails/example%20video.tn.jpg',
|
||||
'subdirs': [],
|
||||
'medias': ['example video.ogv']
|
||||
'medias': ['example video.ogv'],
|
||||
},
|
||||
'webp': {
|
||||
'title': 'webp',
|
||||
'name': 'webp',
|
||||
'thumbnail': 'webp/thumbnails/_MG_7805_lossy80.tn.webp',
|
||||
'subdirs': [],
|
||||
'medias': ['_MG_7805_lossy80.webp', '_MG_7808_lossy80.webp']
|
||||
'medias': ['_MG_7805_lossy80.webp', '_MG_7808_lossy80.webp'],
|
||||
},
|
||||
}
|
||||
|
||||
@@ -122,10 +127,13 @@ def test_media_iptc_override(settings):
|
||||
# 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 '
|
||||
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 '
|
||||
@@ -190,8 +198,9 @@ def test_album(path, album, settings, tmpdir):
|
||||
assert a.thumbnail == album['thumbnail']
|
||||
if path == 'video':
|
||||
assert list(a.images) == []
|
||||
assert [m.dst_filename for m in a.medias] == \
|
||||
[album['medias'][0].replace('.ogv', '.webm')]
|
||||
assert [m.dst_filename for m in a.medias] == [
|
||||
album['medias'][0].replace('.ogv', '.webm')
|
||||
]
|
||||
else:
|
||||
assert list(a.videos) == []
|
||||
assert [m.dst_filename for m in a.medias] == album['medias']
|
||||
@@ -258,7 +267,10 @@ def test_medias_sort(settings):
|
||||
a = Album('dir1/test2', settings, album['subdirs'], album['medias'], gal)
|
||||
a.sort_medias(settings['medias_sort_attr'])
|
||||
assert [im.dst_filename for im in a.images] == [
|
||||
'21.tiff', '22.jpg', 'CMB_Timeline300_no_WMAP.jpg']
|
||||
'21.tiff',
|
||||
'22.jpg',
|
||||
'CMB_Timeline300_no_WMAP.jpg',
|
||||
]
|
||||
|
||||
|
||||
def test_gallery(settings, tmpdir):
|
||||
@@ -340,7 +352,5 @@ def test_ignores(settings, tmpdir):
|
||||
|
||||
assert 'test2' not in os.listdir(join(tmp, 'dir1'))
|
||||
assert 'accentué' not in os.listdir(tmp)
|
||||
assert 'CMB_Timeline300_no_WMAP.jpg' not in os.listdir(
|
||||
join(tmp, 'dir1', 'test1'))
|
||||
assert 'Hubble Interacting Galaxy NGC 5257.jpg' not in os.listdir(
|
||||
join(tmp, 'dir2'))
|
||||
assert 'CMB_Timeline300_no_WMAP.jpg' not in os.listdir(join(tmp, 'dir1', 'test1'))
|
||||
assert 'Hubble Interacting Galaxy NGC 5257.jpg' not in os.listdir(join(tmp, 'dir2'))
|
||||
|
||||
@@ -6,8 +6,15 @@ from PIL import Image as PILImage
|
||||
|
||||
from sigal import init_logging
|
||||
from sigal.gallery import Image
|
||||
from sigal.image import (generate_image, generate_thumbnail, get_exif_data,
|
||||
get_exif_tags, get_iptc_data, get_size, process_image)
|
||||
from sigal.image import (
|
||||
generate_image,
|
||||
generate_thumbnail,
|
||||
get_exif_data,
|
||||
get_exif_tags,
|
||||
get_iptc_data,
|
||||
get_size,
|
||||
process_image,
|
||||
)
|
||||
from sigal.settings import Status, create_settings
|
||||
|
||||
CURRENT_DIR = os.path.dirname(__file__)
|
||||
@@ -25,10 +32,12 @@ def test_process_image(tmpdir):
|
||||
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))
|
||||
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
|
||||
@@ -41,8 +50,9 @@ def test_generate_image(tmpdir):
|
||||
|
||||
dstfile = str(tmpdir.join(TEST_IMAGE))
|
||||
for i, size in enumerate([(600, 600), (300, 200)]):
|
||||
settings = create_settings(img_size=size, img_processor='ResizeToFill',
|
||||
copy_exif_data=True)
|
||||
settings = create_settings(
|
||||
img_size=size, img_processor='ResizeToFill', copy_exif_data=True
|
||||
)
|
||||
options = None if i == 0 else {'quality': 85}
|
||||
generate_image(SRCFILE, dstfile, settings, options=options)
|
||||
im = PILImage.open(dstfile)
|
||||
@@ -54,10 +64,12 @@ def test_generate_image_imgformat(tmpdir):
|
||||
|
||||
dstfile = str(tmpdir.join(TEST_IMAGE))
|
||||
for i, outfmt in enumerate(["JPEG", "PNG", "TIFF"]):
|
||||
settings = create_settings(img_size=(300, 300),
|
||||
img_processor='ResizeToFill',
|
||||
copy_exif_data=True,
|
||||
img_format=outfmt)
|
||||
settings = create_settings(
|
||||
img_size=(300, 300),
|
||||
img_processor='ResizeToFill',
|
||||
copy_exif_data=True,
|
||||
img_format=outfmt,
|
||||
)
|
||||
options = {'quality': 85}
|
||||
generate_image(SRCFILE, dstfile, settings, options=options)
|
||||
im = PILImage.open(dstfile)
|
||||
@@ -70,7 +82,9 @@ def test_resize_image_portrait(tmpdir):
|
||||
settings = create_settings(img_size=size)
|
||||
|
||||
portrait_image = 'm57_the_ring_nebula-587px.jpg'
|
||||
portrait_src = os.path.join(CURRENT_DIR, 'sample', 'pictures', 'dir2', portrait_image)
|
||||
portrait_src = os.path.join(
|
||||
CURRENT_DIR, 'sample', 'pictures', 'dir2', portrait_image
|
||||
)
|
||||
portrait_dst = str(tmpdir.join(portrait_image))
|
||||
|
||||
generate_image(portrait_src, portrait_dst, settings)
|
||||
@@ -82,7 +96,9 @@ def test_resize_image_portrait(tmpdir):
|
||||
assert im.size[0] == 200
|
||||
|
||||
landscape_image = 'KeckObservatory20071020.jpg'
|
||||
landscape_src = os.path.join(CURRENT_DIR, 'sample', 'pictures', 'dir2', landscape_image)
|
||||
landscape_src = os.path.join(
|
||||
CURRENT_DIR, 'sample', 'pictures', 'dir2', landscape_image
|
||||
)
|
||||
landscape_dst = str(tmpdir.join(landscape_image))
|
||||
|
||||
generate_image(landscape_src, landscape_dst, settings)
|
||||
@@ -90,8 +106,9 @@ def test_resize_image_portrait(tmpdir):
|
||||
assert im.size[1] == 200
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("image", "path"), [(TEST_IMAGE, SRCFILE),
|
||||
(TEST_GIF_IMAGE, SRC_GIF_FILE)])
|
||||
@pytest.mark.parametrize(
|
||||
("image", "path"), [(TEST_IMAGE, SRCFILE), (TEST_GIF_IMAGE, SRC_GIF_FILE)]
|
||||
)
|
||||
def test_generate_image_passthrough(tmpdir, image, path):
|
||||
"Test the generate_image function with use_orig=True."
|
||||
|
||||
@@ -121,8 +138,7 @@ def test_generate_image_processor(tmpdir):
|
||||
|
||||
init_logging('sigal')
|
||||
dstfile = str(tmpdir.join(TEST_IMAGE))
|
||||
settings = create_settings(img_size=(200, 200),
|
||||
img_processor='WrongMethod')
|
||||
settings = create_settings(img_size=(200, 200), img_processor='WrongMethod')
|
||||
|
||||
with pytest.raises(SystemExit):
|
||||
generate_image(SRCFILE, dstfile, settings)
|
||||
@@ -130,8 +146,11 @@ def test_generate_image_processor(tmpdir):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("image", "path", "wide_size", "high_size"),
|
||||
[(TEST_IMAGE, SRCFILE, (200, 133), (150, 100)),
|
||||
(TEST_GIF_IMAGE, SRC_GIF_FILE, (134, 150), (150, 168))])
|
||||
[
|
||||
(TEST_IMAGE, SRCFILE, (200, 133), (150, 100)),
|
||||
(TEST_GIF_IMAGE, SRC_GIF_FILE, (134, 150), (150, 168)),
|
||||
],
|
||||
)
|
||||
def test_generate_thumbnail(tmpdir, image, path, wide_size, high_size):
|
||||
"Test the generate_thumbnail function."
|
||||
|
||||
@@ -141,8 +160,7 @@ def test_generate_thumbnail(tmpdir, image, path, wide_size, high_size):
|
||||
im = PILImage.open(dstfile)
|
||||
assert im.size == size
|
||||
|
||||
for size, thumb_size in [((200, 150), wide_size),
|
||||
((150, 200), high_size)]:
|
||||
for size, thumb_size in [((200, 150), wide_size), ((150, 200), high_size)]:
|
||||
generate_thumbnail(path, dstfile, size, fit=False)
|
||||
im = PILImage.open(dstfile)
|
||||
assert im.size == thumb_size
|
||||
@@ -150,8 +168,9 @@ def test_generate_thumbnail(tmpdir, image, path, wide_size, high_size):
|
||||
|
||||
def test_get_exif_tags():
|
||||
test_image = '11.jpg'
|
||||
src_file = os.path.join(CURRENT_DIR, 'sample', 'pictures', 'dir1', 'test1',
|
||||
test_image)
|
||||
src_file = os.path.join(
|
||||
CURRENT_DIR, 'sample', 'pictures', 'dir1', 'test1', test_image
|
||||
)
|
||||
data = get_exif_data(src_file)
|
||||
simple = get_exif_tags(data, datetime_format='%d/%m/%Y')
|
||||
assert simple['fstop'] == 3.9
|
||||
@@ -171,11 +190,16 @@ def test_get_exif_tags():
|
||||
assert 'focal' not in simple
|
||||
assert simple['exposure'] == '10'
|
||||
|
||||
data = {'ExposureTime': '--', 'DateTimeOriginal': '---',
|
||||
'GPSInfo': {'GPSLatitude': ((34, 0), (1, 0), (4500, 100)),
|
||||
'GPSLatitudeRef': 'N',
|
||||
'GPSLongitude': ((116, 0), (8, 0), (3900, 100)),
|
||||
'GPSLongitudeRef': 'W'}}
|
||||
data = {
|
||||
'ExposureTime': '--',
|
||||
'DateTimeOriginal': '---',
|
||||
'GPSInfo': {
|
||||
'GPSLatitude': ((34, 0), (1, 0), (4500, 100)),
|
||||
'GPSLatitudeRef': 'N',
|
||||
'GPSLongitude': ((116, 0), (8, 0), (3900, 100)),
|
||||
'GPSLongitudeRef': 'W',
|
||||
},
|
||||
}
|
||||
simple = get_exif_tags(data)
|
||||
assert 'exposure' not in simple
|
||||
assert 'datetime' not in simple
|
||||
@@ -184,28 +208,30 @@ def test_get_exif_tags():
|
||||
|
||||
def test_get_iptc_data(caplog):
|
||||
test_image = '1.jpg'
|
||||
src_file = os.path.join(CURRENT_DIR, 'sample', 'pictures', 'iptcTest',
|
||||
test_image)
|
||||
src_file = os.path.join(CURRENT_DIR, 'sample', 'pictures', 'iptcTest', test_image)
|
||||
data = get_iptc_data(src_file)
|
||||
# Title
|
||||
assert data["title"] == 'Haemostratulus clouds over Canberra - ' + \
|
||||
'2005-12-28 at 03-25-07'
|
||||
assert (
|
||||
data["title"]
|
||||
== 'Haemostratulus clouds over Canberra - ' + '2005-12-28 at 03-25-07'
|
||||
)
|
||||
# Description
|
||||
assert data["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.'
|
||||
assert (
|
||||
data["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.'
|
||||
)
|
||||
# This file has no IPTC data
|
||||
test_image = '21.jpg'
|
||||
src_file = os.path.join(CURRENT_DIR, 'sample', 'pictures', 'exifTest',
|
||||
test_image)
|
||||
src_file = os.path.join(CURRENT_DIR, 'sample', 'pictures', 'exifTest', test_image)
|
||||
assert get_iptc_data(src_file) == {}
|
||||
|
||||
# Headline
|
||||
test_image = '3.jpg'
|
||||
src_file = os.path.join(CURRENT_DIR, 'sample', 'pictures', 'iptcTest',
|
||||
test_image)
|
||||
src_file = os.path.join(CURRENT_DIR, 'sample', 'pictures', 'iptcTest', test_image)
|
||||
data = get_iptc_data(src_file)
|
||||
assert data["headline"] == 'Ring Nebula, M57'
|
||||
|
||||
@@ -239,8 +265,9 @@ def test_exif_copy(tmpdir):
|
||||
"Test if EXIF data can transferred copied to the resized image."
|
||||
|
||||
test_image = '11.jpg'
|
||||
src_file = os.path.join(CURRENT_DIR, 'sample', 'pictures', 'dir1', 'test1',
|
||||
test_image)
|
||||
src_file = os.path.join(
|
||||
CURRENT_DIR, 'sample', 'pictures', 'dir1', 'test1', test_image
|
||||
)
|
||||
dst_file = str(tmpdir.join(test_image))
|
||||
|
||||
settings = create_settings(img_size=(300, 400), copy_exif_data=True)
|
||||
@@ -258,8 +285,9 @@ def test_exif_gps(tmpdir):
|
||||
"""Test reading out correct geo tags"""
|
||||
|
||||
test_image = 'flickr_jerquiaga_2394751088_cc-by-nc.jpg'
|
||||
src_file = os.path.join(CURRENT_DIR, 'sample', 'pictures', 'dir1', 'test1',
|
||||
test_image)
|
||||
src_file = os.path.join(
|
||||
CURRENT_DIR, 'sample', 'pictures', 'dir1', 'test1', test_image
|
||||
)
|
||||
dst_file = str(tmpdir.join(test_image))
|
||||
|
||||
settings = create_settings(img_size=(400, 300), copy_exif_data=True)
|
||||
@@ -278,8 +306,9 @@ def test_get_size(tmpdir):
|
||||
"""Test reading out image size"""
|
||||
|
||||
test_image = 'flickr_jerquiaga_2394751088_cc-by-nc.jpg'
|
||||
src_file = os.path.join(CURRENT_DIR, 'sample', 'pictures', 'dir1', 'test1',
|
||||
test_image)
|
||||
src_file = os.path.join(
|
||||
CURRENT_DIR, 'sample', 'pictures', 'dir1', 'test1', test_image
|
||||
)
|
||||
|
||||
result = get_size(src_file)
|
||||
assert result == {'height': 800, 'width': 600}
|
||||
|
||||
@@ -18,8 +18,9 @@ def test_plugins(settings, tmpdir, disconnect_signals):
|
||||
gal = Gallery(settings)
|
||||
gal.build()
|
||||
|
||||
out_html = os.path.join(settings['destination'],
|
||||
'dir2', 'KeckObservatory20071020.jpg.html')
|
||||
out_html = os.path.join(
|
||||
settings['destination'], 'dir2', 'KeckObservatory20071020.jpg.html'
|
||||
)
|
||||
assert os.path.isfile(out_html)
|
||||
|
||||
for path, dirs, files in os.walk(os.path.join(str(tmpdir), "nomedia")):
|
||||
@@ -39,10 +40,10 @@ def test_nonmedia_files(settings, tmpdir, disconnect_signals):
|
||||
gal = Gallery(settings)
|
||||
gal.build()
|
||||
|
||||
outfile = os.path.join(settings['destination'],
|
||||
'nonmedia_files', 'dummy.pdf')
|
||||
outfile = os.path.join(settings['destination'], 'nonmedia_files', 'dummy.pdf')
|
||||
assert os.path.isfile(outfile)
|
||||
|
||||
outthumb = os.path.join(settings['destination'],
|
||||
'nonmedia_files', 'thumbnails', 'dummy.tn.jpg')
|
||||
outthumb = os.path.join(
|
||||
settings['destination'], 'nonmedia_files', 'thumbnails', 'dummy.tn.jpg'
|
||||
)
|
||||
assert os.path.isfile(outthumb)
|
||||
|
||||
@@ -10,21 +10,24 @@ def test_read_settings(settings):
|
||||
assert settings['img_size'] == (640, 480)
|
||||
assert settings['thumb_size'] == (200, 150)
|
||||
assert settings['thumb_suffix'] == '.tn'
|
||||
assert settings['source'] == os.path.join(CURRENT_DIR, 'sample',
|
||||
'pictures')
|
||||
assert settings['source'] == os.path.join(CURRENT_DIR, 'sample', 'pictures')
|
||||
|
||||
|
||||
def test_get_thumb(settings):
|
||||
"""Test the get_thumb function."""
|
||||
tests = [('example.jpg', 'thumbnails/example.tn.jpg'),
|
||||
('test/example.jpg', 'test/thumbnails/example.tn.jpg'),
|
||||
('test/t/example.jpg', 'test/t/thumbnails/example.tn.jpg')]
|
||||
tests = [
|
||||
('example.jpg', 'thumbnails/example.tn.jpg'),
|
||||
('test/example.jpg', 'test/thumbnails/example.tn.jpg'),
|
||||
('test/t/example.jpg', 'test/t/thumbnails/example.tn.jpg'),
|
||||
]
|
||||
for src, ref in tests:
|
||||
assert get_thumb(settings, src) == ref
|
||||
|
||||
tests = [('example.webm', 'thumbnails/example.tn.jpg'),
|
||||
('test/example.mp4', 'test/thumbnails/example.tn.jpg'),
|
||||
('test/t/example.avi', 'test/t/thumbnails/example.tn.jpg')]
|
||||
tests = [
|
||||
('example.webm', 'thumbnails/example.tn.jpg'),
|
||||
('test/example.mp4', 'test/thumbnails/example.tn.jpg'),
|
||||
('test/t/example.avi', 'test/t/thumbnails/example.tn.jpg'),
|
||||
]
|
||||
for src, ref in tests:
|
||||
assert get_thumb(settings, src) == ref
|
||||
|
||||
|
||||
@@ -66,8 +66,7 @@ def test_read_markdown():
|
||||
m = utils.read_markdown(src)
|
||||
assert m['title'] == "Foo Bar"
|
||||
assert m['meta']['location'][0] == "Bavaria"
|
||||
assert m['description'] == \
|
||||
"<p>This is a funny description of this image</p>"
|
||||
assert m['description'] == "<p>This is a funny description of this image</p>"
|
||||
|
||||
|
||||
def test_read_markdown_empty_file(tmpdir):
|
||||
|
||||
@@ -5,8 +5,7 @@ import pytest
|
||||
|
||||
from sigal.gallery import Video
|
||||
from sigal.settings import Status, create_settings
|
||||
from sigal.video import (generate_thumbnail, generate_video, process_video,
|
||||
video_size)
|
||||
from sigal.video import generate_thumbnail, generate_video, process_video, video_size
|
||||
|
||||
CURRENT_DIR = os.path.dirname(__file__)
|
||||
SRCDIR = os.path.join(CURRENT_DIR, 'sample', 'pictures')
|
||||
@@ -30,10 +29,13 @@ def test_generate_thumbnail(tmpdir):
|
||||
def test_process_video(tmpdir):
|
||||
base, ext = os.path.splitext(TEST_VIDEO)
|
||||
|
||||
settings = create_settings(video_format='ogv',
|
||||
use_orig=True, orig_link=True,
|
||||
source=os.path.join(SRCDIR, 'video'),
|
||||
destination=str(tmpdir))
|
||||
settings = create_settings(
|
||||
video_format='ogv',
|
||||
use_orig=True,
|
||||
orig_link=True,
|
||||
source=os.path.join(SRCDIR, 'video'),
|
||||
destination=str(tmpdir),
|
||||
)
|
||||
video = Video(TEST_VIDEO, '.', settings)
|
||||
process_video(video)
|
||||
dstfile = str(tmpdir.join(base + '.ogv'))
|
||||
@@ -102,9 +104,12 @@ def test_second_pass_video(mock_generate_video_pass, fmt, tmpdir):
|
||||
dstfile = str(tmpdir.join(base + '.' + fmt))
|
||||
settings_1 = '-c:v libvpx-vp9 -b:v 0 -crf 30 -pass 1 -an -f null dev/null'
|
||||
settings_2 = f'-c:v libvpx-vp9 -b:v 0 -crf 30 -pass 2 -f {fmt}'
|
||||
settings_opts = {'video_size': (100, 50), 'video_format': fmt,
|
||||
fmt + '_options': settings_1.split(" "),
|
||||
fmt + '_options_second_pass': settings_2.split(" ")}
|
||||
settings_opts = {
|
||||
'video_size': (100, 50),
|
||||
'video_format': fmt,
|
||||
fmt + '_options': settings_1.split(" "),
|
||||
fmt + '_options_second_pass': settings_2.split(" "),
|
||||
}
|
||||
|
||||
settings = create_settings(**settings_opts)
|
||||
generate_video(SRCFILE, dstfile, settings)
|
||||
|
||||
@@ -28,9 +28,12 @@ def test_zipped_correctly(tmpdir):
|
||||
assert os.path.isfile(zipf)
|
||||
|
||||
zip_file = zipfile.ZipFile(zipf, 'r')
|
||||
expected = ('11.jpg', 'CMB_Timeline300_no_WMAP.jpg',
|
||||
'flickr_jerquiaga_2394751088_cc-by-nc.jpg',
|
||||
'example.gif')
|
||||
expected = (
|
||||
'11.jpg',
|
||||
'CMB_Timeline300_no_WMAP.jpg',
|
||||
'flickr_jerquiaga_2394751088_cc-by-nc.jpg',
|
||||
'example.gif',
|
||||
)
|
||||
|
||||
for filename in zip_file.namelist():
|
||||
assert filename in expected
|
||||
@@ -44,8 +47,9 @@ def test_not_zipped(tmpdir):
|
||||
# test that the zip file is not created when the .nozip_gallery file
|
||||
# is present
|
||||
outpath = str(tmpdir)
|
||||
gallery = make_gallery(destination=outpath, zip_gallery='archive.zip',
|
||||
source_dir='dir2')
|
||||
gallery = make_gallery(
|
||||
destination=outpath, zip_gallery='archive.zip', source_dir='dir2'
|
||||
)
|
||||
gallery.build()
|
||||
assert not os.path.isfile(os.path.join(outpath, 'archive.zip'))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user