Files
sigal/tests/test_settings.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

55 lines
1.6 KiB
Python
Raw Normal View History

import os
2020-03-15 22:58:03 -03:00
from sigal.settings import get_thumb, read_settings
CURRENT_DIR = os.path.abspath(os.path.dirname(__file__))
2012-10-29 23:12:54 +01:00
def test_read_settings(settings):
"""Test that the settings are correctly read."""
2023-02-12 17:31:08 +01:00
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")
2013-05-14 00:38:03 +02:00
def test_get_thumb(settings):
"""Test the get_thumb function."""
tests = [
2023-02-12 17:31:08 +01:00
("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
2013-08-18 23:13:34 +02:00
tests = [
2023-02-12 17:31:08 +01:00
("example.webm", "thumbnails/example.tn.jpg"),
("test/example.mp4", "test/thumbnails/example.tn.jpg"),
("test/t/example.avi", "test/t/thumbnails/example.tn.jpg"),
2013-08-18 23:13:34 +02:00
]
for src, ref in tests:
assert get_thumb(settings, src) == ref
def test_img_sizes(tmpdir):
"""Test that image size is swaped if needed."""
2023-02-12 17:31:08 +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
settings = read_settings(str(conf))
2023-02-12 17:31:08 +01:00
assert settings["thumb_size"] == (200, 150)
def test_theme_path(tmpdir):
"""Test that image size is swaped if needed."""
2023-02-12 17:31:08 +01:00
tmpdir.join("theme").mkdir()
tmpdir.join("theme").join("templates").mkdir()
conf = tmpdir.join("sigal.conf.py")
2018-08-27 00:15:17 +02:00
conf.write("theme = 'theme'")
settings = read_settings(str(conf))
2023-02-12 17:31:08 +01:00
assert settings["theme"] == tmpdir.join("theme")