2012-11-07 01:01:12 +01:00
|
|
|
# -*- coding:utf-8 -*-
|
|
|
|
|
|
|
|
|
|
import os
|
2013-03-12 13:58:28 +01:00
|
|
|
import pytest
|
2012-11-07 01:01:12 +01:00
|
|
|
|
2014-01-15 23:25:24 +01:00
|
|
|
from sigal.gallery import Gallery, PathsDb, get_metadata
|
2012-11-07 01:01:12 +01:00
|
|
|
from sigal.settings import read_settings
|
|
|
|
|
|
|
|
|
|
CURRENT_DIR = os.path.dirname(__file__)
|
2013-02-16 17:29:24 +01:00
|
|
|
SAMPLE_DIR = os.path.join(CURRENT_DIR, 'sample')
|
2012-11-07 01:01:12 +01:00
|
|
|
|
2013-02-19 00:05:16 +01:00
|
|
|
REF = {
|
|
|
|
|
'dir1': {
|
|
|
|
|
'title': 'An example gallery',
|
2013-02-19 00:51:11 +01:00
|
|
|
'thumbnail': 'test1/11.jpg',
|
2013-07-18 16:36:46 +02:00
|
|
|
'medias': [],
|
2013-02-19 00:05:16 +01:00
|
|
|
},
|
|
|
|
|
'dir1/test1': {
|
2013-03-12 18:30:44 +01:00
|
|
|
'title': 'An example sub-category',
|
2013-02-19 00:05:16 +01:00
|
|
|
'thumbnail': '11.jpg',
|
2013-08-05 08:56:41 +02:00
|
|
|
'medias': ['11.jpg', 'archlinux-kiss-1024x640.png',
|
|
|
|
|
'flickr_jerquiaga_2394751088_cc-by-nc.jpg'],
|
2013-02-19 00:05:16 +01:00
|
|
|
},
|
|
|
|
|
'dir1/test2': {
|
|
|
|
|
'title': 'Test2',
|
|
|
|
|
'thumbnail': '21.jpg',
|
2013-07-18 16:36:46 +02:00
|
|
|
'medias': ['21.jpg', '22.jpg'],
|
2013-02-19 00:05:16 +01:00
|
|
|
},
|
|
|
|
|
'dir2': {
|
2013-08-04 01:12:29 +02:00
|
|
|
'title': 'Another example gallery with a very long name',
|
2013-02-19 00:05:16 +01:00
|
|
|
'thumbnail': 'm57_the_ring_nebula-587px.jpg',
|
2013-07-18 16:36:46 +02:00
|
|
|
'medias': ['exo20101028-b-full.jpg',
|
2013-10-01 00:36:54 +02:00
|
|
|
'm57_the_ring_nebula-587px.jpg',
|
|
|
|
|
'Hubble ultra deep field.jpg',
|
|
|
|
|
'Hubble Interacting Galaxy NGC 5257.jpg'],
|
2013-07-10 13:40:58 +02:00
|
|
|
},
|
|
|
|
|
u'accentué': {
|
|
|
|
|
'title': u'Accentué',
|
|
|
|
|
'thumbnail': u'hélicoïde.jpg',
|
2013-07-18 16:36:46 +02:00
|
|
|
'medias': [u'hélicoïde.jpg', 'superdupont_source_wikipedia_en.jpg'],
|
2013-07-17 00:43:37 +02:00
|
|
|
},
|
|
|
|
|
'video': {
|
|
|
|
|
'title': 'Video',
|
2013-12-27 23:25:30 +01:00
|
|
|
'thumbnail': 'stallman software-freedom-day-low.ogv',
|
|
|
|
|
'medias': ['stallman software-freedom-day-low.ogv']
|
2013-02-19 00:05:16 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-03-12 13:58:28 +01:00
|
|
|
@pytest.fixture(scope='module')
|
|
|
|
|
def paths():
|
|
|
|
|
"""Read the sample config file and build the PathsDb object."""
|
|
|
|
|
|
|
|
|
|
default_conf = os.path.join(SAMPLE_DIR, 'sigal.conf.py')
|
|
|
|
|
settings = read_settings(default_conf)
|
2013-07-17 00:43:37 +02:00
|
|
|
return PathsDb(os.path.join(SAMPLE_DIR, 'pictures'),
|
2013-10-01 00:36:54 +02:00
|
|
|
settings['img_ext_list'], settings['vid_ext_list'])
|
2013-03-12 13:58:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='module')
|
|
|
|
|
def db(paths):
|
|
|
|
|
paths.build()
|
|
|
|
|
return paths.db
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_filelist(db):
|
2013-10-01 00:36:54 +02:00
|
|
|
assert set(db.keys()) == set([
|
|
|
|
|
'paths_list', 'skipped_dir', '.', 'dir1', 'dir2', 'dir1/test1',
|
|
|
|
|
'dir1/test2', u'accentué', 'video'])
|
2013-03-12 13:58:28 +01:00
|
|
|
|
2013-10-01 00:36:54 +02:00
|
|
|
assert set(db['paths_list']) == set([
|
|
|
|
|
'.', 'dir1', 'dir1/test1', 'dir1/test2', 'dir2', u'accentué', 'video'])
|
2012-11-07 01:01:12 +01:00
|
|
|
|
2013-03-12 13:58:28 +01:00
|
|
|
assert set(db['skipped_dir']) == set(['empty', 'dir1/empty'])
|
2013-07-18 16:36:46 +02:00
|
|
|
assert db['.']['medias'] == []
|
2013-07-17 00:43:37 +02:00
|
|
|
assert set(db['.']['subdir']) == set([u'accentué', 'dir1', 'dir2',
|
2013-10-01 00:36:54 +02:00
|
|
|
'video'])
|
2012-11-07 01:01:12 +01:00
|
|
|
|
|
|
|
|
|
2013-03-12 13:58:28 +01:00
|
|
|
def test_title(db):
|
|
|
|
|
for p in REF.keys():
|
|
|
|
|
assert db[p]['title'] == REF[p]['title']
|
2012-11-07 01:01:12 +01:00
|
|
|
|
2013-02-08 12:30:29 +01:00
|
|
|
|
2013-03-12 13:58:28 +01:00
|
|
|
def test_thumbnail(db):
|
|
|
|
|
for p in REF.keys():
|
|
|
|
|
assert db[p]['thumbnail'] == REF[p]['thumbnail']
|
2012-11-07 01:01:12 +01:00
|
|
|
|
|
|
|
|
|
2013-07-18 16:36:46 +02:00
|
|
|
def test_medialist(db):
|
2013-03-12 13:58:28 +01:00
|
|
|
for p in REF.keys():
|
2013-07-18 16:36:46 +02:00
|
|
|
assert set(db[p]['medias']) == set(REF[p]['medias'])
|
2013-07-17 14:16:30 +02:00
|
|
|
|
|
|
|
|
|
2013-03-12 13:58:28 +01:00
|
|
|
def test_get_subdir(paths):
|
2013-11-09 00:38:13 +01:00
|
|
|
assert set(paths.get_subdirs('dir1/test1')) == set()
|
2013-03-12 13:58:28 +01:00
|
|
|
assert set(paths.get_subdirs('dir1')) == set(['dir1/test1', 'dir1/test2'])
|
2013-10-01 00:36:54 +02:00
|
|
|
assert set(paths.get_subdirs('.')) == set([
|
|
|
|
|
'dir1', 'dir2', 'dir1/test1', 'dir1/test2', u'accentué', 'video'])
|
2013-02-19 00:05:16 +01:00
|
|
|
|
2012-11-09 13:07:03 +01:00
|
|
|
|
2013-03-12 13:58:28 +01:00
|
|
|
def test_get_metadata():
|
|
|
|
|
"Test the get_metadata function."
|
2012-11-09 13:07:03 +01:00
|
|
|
|
2013-05-07 00:30:07 +02:00
|
|
|
m = get_metadata(os.path.join(SAMPLE_DIR, 'pictures', 'dir1'))
|
2013-03-12 13:58:28 +01:00
|
|
|
assert m['title'] == REF['dir1']['title']
|
|
|
|
|
assert m['thumbnail'] == ''
|
2012-11-09 13:07:03 +01:00
|
|
|
|
2013-05-07 00:30:07 +02:00
|
|
|
m = get_metadata(os.path.join(SAMPLE_DIR, 'pictures', 'dir2'))
|
2013-03-12 13:58:28 +01:00
|
|
|
assert m['title'] == REF['dir2']['title']
|
|
|
|
|
assert m['thumbnail'] == REF['dir2']['thumbnail']
|
2013-02-16 17:29:24 +01:00
|
|
|
|
|
|
|
|
|
2013-10-01 00:36:54 +02:00
|
|
|
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)
|
2013-12-18 00:55:21 +01:00
|
|
|
gal = Gallery(settings, ncpu=1)
|
2013-10-01 00:36:54 +02:00
|
|
|
gal.build()
|
|
|
|
|
|
|
|
|
|
out_html = os.path.join(settings['destination'], 'index.html')
|
|
|
|
|
assert os.path.isfile(out_html)
|
2013-02-16 17:29:24 +01:00
|
|
|
|
2013-10-01 00:36:54 +02:00
|
|
|
with open(out_html, 'r') as f:
|
|
|
|
|
html = f.read()
|
2013-02-16 17:29:24 +01:00
|
|
|
|
2013-10-01 00:36:54 +02:00
|
|
|
assert '<title>Sigal test gallery</title>' in html
|
2013-10-17 00:17:06 +02:00
|
|
|
|