Browse Source

Refactor, tests and pep8 for the gallery module.

pull/43/head
Simon Conseil 13 years ago
parent
commit
7916d5e4cc
  1. 16
      sigal/gallery.py
  2. 49
      tests/test_gallery.py

16
sigal/gallery.py

@ -36,9 +36,7 @@ from clint.textui import progress, colored
from os.path import join
from PIL import Image as PILImage
import sigal.image
import sigal.video
from . import compat
from . import compat, image, video
from .settings import get_thumb
from .writer import Writer
@ -172,8 +170,6 @@ class PathsDb(object):
self.db[path]['thumbnail'] = self.db[path]['medias'][0]
return
self.db[path]['thumbnail'] = ''
class Gallery(object):
"Prepare images"
@ -299,11 +295,11 @@ def process_image(filepath, outpath, settings):
if settings['keep_orig']:
shutil.copy(filepath, join(outpath, settings['orig_dir'], filename))
sigal.image.generate_image(filepath, outname, settings, options=options)
image.generate_image(filepath, outname, settings, options=options)
if settings['make_thumbs']:
thumb_name = join(outpath, get_thumb(settings, filename))
sigal.image.generate_thumbnail(
image.generate_thumbnail(
outname, thumb_name, settings['thumb_size'],
fit=settings['thumb_fit'], options=options)
@ -319,12 +315,12 @@ def process_video(filepath, outpath, settings):
shutil.copy(filepath, join(outpath, settings['orig_dir'], filename))
# TODO: Add specific video size settings
sigal.video.generate_video(filepath, outname, settings['img_size'],
settings['webm_options'])
video.generate_video(filepath, outname, settings['img_size'],
settings['webm_options'])
if settings['make_thumbs']:
thumb_name = join(outpath, get_thumb(settings, filename))
sigal.video.generate_thumbnail(
video.generate_thumbnail(
outname, thumb_name, settings['thumb_size'],
fit=settings['thumb_fit'], options=settings['jpg_options'])

49
tests/test_gallery.py

@ -3,7 +3,7 @@
import os
import pytest
from sigal.gallery import PathsDb, get_metadata
from sigal.gallery import Gallery, PathsDb, get_metadata
from sigal.settings import read_settings
CURRENT_DIR = os.path.dirname(__file__)
@ -30,9 +30,9 @@ REF = {
'title': 'Another example gallery with a very long name',
'thumbnail': 'm57_the_ring_nebula-587px.jpg',
'medias': ['exo20101028-b-full.jpg',
'm57_the_ring_nebula-587px.jpg',
'Hubble ultra deep field.jpg',
'Hubble Interacting Galaxy NGC 5257.jpg'],
'm57_the_ring_nebula-587px.jpg',
'Hubble ultra deep field.jpg',
'Hubble Interacting Galaxy NGC 5257.jpg'],
},
u'accentué': {
'title': u'Accentué',
@ -54,7 +54,7 @@ def paths():
default_conf = os.path.join(SAMPLE_DIR, 'sigal.conf.py')
settings = read_settings(default_conf)
return PathsDb(os.path.join(SAMPLE_DIR, 'pictures'),
settings['img_ext_list'], settings['vid_ext_list'])
settings['img_ext_list'], settings['vid_ext_list'])
@pytest.fixture(scope='module')
@ -64,16 +64,17 @@ def db(paths):
def test_filelist(db):
assert set(db.keys()) == set(['paths_list', 'skipped_dir', '.',
'dir1', 'dir2', 'dir1/test1', 'dir1/test2', u'accentué', 'video'])
assert set(db.keys()) == set([
'paths_list', 'skipped_dir', '.', 'dir1', 'dir2', 'dir1/test1',
'dir1/test2', u'accentué', 'video'])
assert set(db['paths_list']) == set(['.', 'dir1', 'dir1/test1',
'dir1/test2', 'dir2', u'accentué', 'video'])
assert set(db['paths_list']) == set([
'.', 'dir1', 'dir1/test1', 'dir1/test2', 'dir2', u'accentué', 'video'])
assert set(db['skipped_dir']) == set(['empty', 'dir1/empty'])
assert db['.']['medias'] == []
assert set(db['.']['subdir']) == set([u'accentué', 'dir1', 'dir2',
'video'])
'video'])
def test_title(db):
@ -93,9 +94,8 @@ def test_medialist(db):
def test_get_subdir(paths):
assert set(paths.get_subdirs('dir1')) == set(['dir1/test1', 'dir1/test2'])
assert set(paths.get_subdirs('.')) == set(['dir1', 'dir2', 'dir1/test1',
'dir1/test2', u'accentué',
'video'])
assert set(paths.get_subdirs('.')) == set([
'dir1', 'dir2', 'dir1/test1', 'dir1/test2', u'accentué', 'video'])
def test_get_metadata():
@ -110,14 +110,19 @@ def test_get_metadata():
assert m['thumbnail'] == REF['dir2']['thumbnail']
# class TestGallery(unittest.TestCase):
# "Test the Gallery class."
def test_gallery(tmpdir):
"Test the Gallery class."
default_conf = os.path.join(SAMPLE_DIR, 'sigal.conf.py')
settings = read_settings(default_conf)
settings['destination'] = str(tmpdir)
gal = Gallery(settings)
gal.build()
out_html = os.path.join(settings['destination'], 'index.html')
assert os.path.isfile(out_html)
# @classmethod
# def setUp(cls):
# """Read the sample config file."""
with open(out_html, 'r') as f:
html = f.read()
# default_conf = os.path.join(CURRENT_DIR, 'sample', 'sigal.conf.py')
# settings = read_settings(default_conf)
# cls.gal = Gallery(settings, os.path.join(CURRENT_DIR, 'sample'),
# os.path.join(CURRENT_DIR, 'output'))
assert '<title>Sigal test gallery</title>' in html

Loading…
Cancel
Save