gallery: add tests for the filelist method, + correct import of PIL
This commit is contained in:
@@ -67,8 +67,8 @@ def main():
|
||||
settings['copyright'] = args.copyright
|
||||
|
||||
# create gallery
|
||||
gallery = Gallery(settings)
|
||||
gallery.build(args.input_dir, args.output_dir, force=args.force)
|
||||
gallery = Gallery(settings, args.input_dir)
|
||||
gallery.build(args.output_dir, force=args.force)
|
||||
|
||||
r = Theme(settings, args.output_dir)
|
||||
r.render()
|
||||
|
||||
@@ -23,8 +23,8 @@ Prepare images: resize images, and create thumbnails with some options
|
||||
"""
|
||||
|
||||
import os
|
||||
import Image
|
||||
import ImageDraw
|
||||
|
||||
from PIL import Image, ImageDraw
|
||||
from shutil import copy2
|
||||
|
||||
DESCRIPTION_FILE = "album_description"
|
||||
@@ -32,8 +32,9 @@ DESCRIPTION_FILE = "album_description"
|
||||
class Gallery:
|
||||
"Prepare images"
|
||||
|
||||
def __init__(self, settings):
|
||||
def __init__(self, settings, input_dir):
|
||||
self.settings = settings
|
||||
self.input_dir = os.path.abspath(input_dir)
|
||||
|
||||
def filelist(self):
|
||||
"get the list of directories with files of particular extensions"
|
||||
@@ -43,10 +44,9 @@ class Gallery:
|
||||
if os.path.splitext(f)[1] in self.settings['fileextlist']]
|
||||
yield dirpath, dirnames, imglist
|
||||
|
||||
def build(self, input_dir, output_dir, force=False):
|
||||
def build(self, output_dir, force=False):
|
||||
"create image gallery"
|
||||
|
||||
self.input_dir = os.path.abspath(input_dir)
|
||||
self.output_dir = os.path.abspath(output_dir)
|
||||
self.force = force
|
||||
|
||||
|
||||
29
tests/test_image.py
Normal file
29
tests/test_image.py
Normal file
@@ -0,0 +1,29 @@
|
||||
#! /usr/bin/env python2
|
||||
# -*- coding:utf-8 -*-
|
||||
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from sigal.image import Gallery
|
||||
from sigal.settings import read_settings
|
||||
|
||||
class TestSettings(unittest.TestCase):
|
||||
"Read a settings file and check that the configuration is well done."
|
||||
|
||||
def setUp(self):
|
||||
"Read the sample config file"
|
||||
self.path = os.path.dirname(__file__)
|
||||
default_conf = os.path.join(self.path, 'sample', 'sigal.conf')
|
||||
settings = read_settings(default_conf)
|
||||
self.gallery = Gallery(settings, os.path.join(self.path, 'sample'))
|
||||
|
||||
def test_filelist(self):
|
||||
file_generator = self.gallery.filelist()
|
||||
dirpath, dirnames, imglist = file_generator.next()
|
||||
self.assertEqual(dirpath, os.path.join(self.path, 'sample'))
|
||||
self.assertListEqual(imglist, [])
|
||||
|
||||
reflist = [os.path.join(self.path, 'sample', 'dir2', f)
|
||||
for f in ['test1.jpg', 'test2.jpg']]
|
||||
dirpath, dirnames, imglist = file_generator.next()
|
||||
self.assertListEqual(imglist, reflist)
|
||||
Reference in New Issue
Block a user