mirror of https://github.com/saimn/sigal.git
2 changed files with 76 additions and 73 deletions
@ -1,37 +1,42 @@
|
||||
# -*- coding:utf-8 -*- |
||||
|
||||
import os |
||||
|
||||
try: |
||||
import unittest2 as unittest |
||||
except ImportError: |
||||
import unittest # NOQA |
||||
import pytest |
||||
|
||||
from sigal.settings import read_settings, get_thumb |
||||
|
||||
|
||||
class TestSettings(unittest.TestCase): |
||||
"Read a settings file and check that the configuration is well done." |
||||
@pytest.fixture(scope='module') |
||||
def settings(): |
||||
"""Read the sample config file.""" |
||||
path = os.path.abspath(os.path.dirname(__file__)) |
||||
return read_settings(os.path.join(path, 'sample', 'sigal.conf.py')) |
||||
|
||||
|
||||
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' |
||||
|
||||
|
||||
def test_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')] |
||||
for src, ref in tests: |
||||
assert get_thumb(settings, src) == ref |
||||
|
||||
def setUp(self): |
||||
"Read the sample config file" |
||||
self.path = os.path.abspath(os.path.dirname(__file__)) |
||||
default_conf = os.path.join(self.path, 'sample', 'sigal.conf.py') |
||||
self.settings = read_settings(default_conf) |
||||
|
||||
def test_sizes(self): |
||||
"Test that image sizes are correctly read" |
||||
self.assertTupleEqual(self.settings['img_size'], (640, 480)) |
||||
self.assertTupleEqual(self.settings['thumb_size'], (200, 150)) |
||||
def test_img_sizes(tmpdir): |
||||
"""Test that image size is swaped if needed.""" |
||||
|
||||
def test_settings(self): |
||||
self.assertEqual(self.settings['thumb_suffix'], '.tn') |
||||
conf = tmpdir.join('sigal.conf.py') |
||||
conf.write("""# -*- coding: utf-8 -*- |
||||
|
||||
def test_thumb(self): |
||||
"""Test the get_thumb function.""" |
||||
thumb_size = (150, 200) |
||||
""") |
||||
|
||||
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: |
||||
self.assertEqual(get_thumb(self.settings, src), ref) |
||||
settings = read_settings(str(conf)) |
||||
assert settings['thumb_size'] == (200, 150) |
||||
|
||||
Loading…
Reference in new issue