2012-05-15 00:49:13 +02:00
|
|
|
import os
|
|
|
|
|
|
2020-03-15 22:58:03 -03:00
|
|
|
from sigal.settings import get_thumb, read_settings
|
2012-05-15 00:49:13 +02:00
|
|
|
|
2013-05-07 23:46:22 +02:00
|
|
|
CURRENT_DIR = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
|
|
2012-10-29 23:12:54 +01:00
|
|
|
|
2013-03-12 13:58:28 +01:00
|
|
|
def test_read_settings(settings):
|
|
|
|
|
"""Test that the settings are correctly read."""
|
|
|
|
|
assert settings['img_size'] == (640, 480)
|
|
|
|
|
assert settings['thumb_size'] == (200, 150)
|
|
|
|
|
assert settings['thumb_suffix'] == '.tn'
|
2013-05-07 23:46:22 +02:00
|
|
|
assert settings['source'] == os.path.join(CURRENT_DIR, 'sample', 'pictures')
|
2013-03-12 13:58:28 +01:00
|
|
|
|
|
|
|
|
|
2013-05-14 00:38:03 +02:00
|
|
|
def test_get_thumb(settings):
|
2013-03-12 13:58:28 +01:00
|
|
|
"""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'),
|
|
|
|
|
]
|
|
|
|
|
for src, ref in tests:
|
|
|
|
|
assert get_thumb(settings, src) == ref
|
2012-05-15 00:49:13 +02:00
|
|
|
|
2013-08-18 23:13:34 +02:00
|
|
|
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
|
|
|
|
|
|
2012-05-15 00:49:13 +02:00
|
|
|
|
2013-03-12 13:58:28 +01:00
|
|
|
def test_img_sizes(tmpdir):
|
|
|
|
|
"""Test that image size is swaped if needed."""
|
2012-05-15 00:49:13 +02:00
|
|
|
|
2013-03-12 13:58:28 +01:00
|
|
|
conf = tmpdir.join('sigal.conf.py')
|
2018-08-27 00:15:17 +02:00
|
|
|
conf.write("thumb_size = (150, 200)")
|
2013-02-19 22:59:50 +01:00
|
|
|
|
2013-03-12 13:58:28 +01:00
|
|
|
settings = read_settings(str(conf))
|
|
|
|
|
assert settings['thumb_size'] == (200, 150)
|
2013-05-07 23:46:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_theme_path(tmpdir):
|
|
|
|
|
"""Test that image size is swaped if needed."""
|
|
|
|
|
|
|
|
|
|
tmpdir.join('theme').mkdir()
|
2015-09-01 00:24:39 +02:00
|
|
|
tmpdir.join('theme').join('templates').mkdir()
|
2013-05-07 23:46:22 +02:00
|
|
|
conf = tmpdir.join('sigal.conf.py')
|
2018-08-27 00:15:17 +02:00
|
|
|
conf.write("theme = 'theme'")
|
2013-05-07 23:46:22 +02:00
|
|
|
|
|
|
|
|
settings = read_settings(str(conf))
|
|
|
|
|
assert settings['theme'] == tmpdir.join('theme')
|