# Path: sigal/settings.py
# def get_thumb(settings, filename):
#     """Return the path to the thumb.
# 
#     examples:
#     >>> default_settings = create_settings()
#     >>> get_thumb(default_settings, "bar/foo.jpg")
#     "bar/thumbnails/foo.jpg"
#     >>> get_thumb(default_settings, "bar/foo.png")
#     "bar/thumbnails/foo.png"
# 
#     for videos, it returns a jpg file:
#     >>> get_thumb(default_settings, "bar/foo.webm")
#     "bar/thumbnails/foo.jpg"
#     """
# 
#     path, filen = os.path.split(filename)
#     name, ext = os.path.splitext(filen)
# 
#     if ext.lower() in settings['video_extensions']:
#         ext = '.jpg'
#     return join(
#         path,
#         settings['thumb_dir'],
#         settings['thumb_prefix'] + name + settings['thumb_suffix'] + ext,
#     )
# 
# def read_settings(filename=None):
#     """Read settings from a config file in the source_dir root."""
# 
#     logger = logging.getLogger(__name__)
#     logger.info("Reading settings ...")
#     settings = _DEFAULT_CONFIG.copy()
# 
#     if filename:
#         logger.debug("Settings file: %s", filename)
#         settings_path = os.path.dirname(filename)
#         tempdict = {}
# 
#         with open(filename) as f:
#             code = compile(f.read(), filename, 'exec')
#             exec(code, tempdict)
# 
#         settings.update(
#             (k, v) for k, v in tempdict.items() if k not in ['__builtins__']
#         )
# 
#         # Make the paths relative to the settings file
#         paths = ['source', 'destination', 'watermark']
# 
#         if os.path.isdir(join(settings_path, settings['theme'])) and os.path.isdir(
#             join(settings_path, settings['theme'], 'templates')
#         ):
#             paths.append('theme')
# 
#         for p in paths:
#             path = settings[p]
#             if path and not isabs(path):
#                 settings[p] = abspath(normpath(join(settings_path, path)))
#                 logger.debug("Rewrite %s : %s -> %s", p, path, settings[p])
# 
#     for key in ('img_size', 'thumb_size', 'video_size'):
#         if settings[key]:
#             w, h = settings[key]
#             if h > w:
#                 settings[key] = (h, w)
#                 logger.warning(
#                     "The %s setting should be specified with the largest value first.",
#                     key,
#                 )
# 
#     if not settings['img_processor']:
#         logger.info('No Processor, images will not be resized')
# 
#     logger.debug('Settings:\n%s', pformat(settings, width=120))
#     return settings


import os
from sigal.settings import get_thumb, read_settings
    for src, ref in tests:
        assert get_thumb(settings, src) == ref

    tests = [
        ('example.webm', 'thumbnails/example.tn.jpg'),
        ('test/example.mp4', 'test/thumbnails/example.tn.jpg'),
        ('test/t/example.avi', 'test/t/thumbnails/example.tn.jpg'),
    ]
    for src, ref in tests:
        assert get_thumb(settings, src) == ref


def test_img_sizes(tmpdir):
    """Test that image size is swaped if needed."""

    conf = tmpdir.join('sigal.conf.py')
    conf.write("thumb_size = (150, 200)")

    settings = read_settings(str(conf))
    assert settings['thumb_size'] == (200, 150)


def test_theme_path(tmpdir):
    """Test that image size is swaped if needed."""

    tmpdir.join('theme').mkdir()
    tmpdir.join('theme').join('templates').mkdir()
    conf = tmpdir.join('sigal.conf.py')
    conf.write("theme = 'theme'")


# Path: sigal/settings.py
# def get_thumb(settings, filename):
#     """Return the path to the thumb.
# 
#     examples:
#     >>> default_settings = create_settings()
#     >>> get_thumb(default_settings, "bar/foo.jpg")
#     "bar/thumbnails/foo.jpg"
#     >>> get_thumb(default_settings, "bar/foo.png")
#     "bar/thumbnails/foo.png"
# 
#     for videos, it returns a jpg file:
#     >>> get_thumb(default_settings, "bar/foo.webm")
#     "bar/thumbnails/foo.jpg"
#     """
# 
#     path, filen = os.path.split(filename)
#     name, ext = os.path.splitext(filen)
# 
#     if ext.lower() in settings['video_extensions']:
#         ext = '.jpg'
#     return join(
#         path,
#         settings['thumb_dir'],
#         settings['thumb_prefix'] + name + settings['thumb_suffix'] + ext,
#     )
# 
# def read_settings(filename=None):
#     """Read settings from a config file in the source_dir root."""
# 
#     logger = logging.getLogger(__name__)
#     logger.info("Reading settings ...")
#     settings = _DEFAULT_CONFIG.copy()
# 
#     if filename:
#         logger.debug("Settings file: %s", filename)
#         settings_path = os.path.dirname(filename)
#         tempdict = {}
# 
#         with open(filename) as f:
#             code = compile(f.read(), filename, 'exec')
#             exec(code, tempdict)
# 
#         settings.update(
#             (k, v) for k, v in tempdict.items() if k not in ['__builtins__']
#         )
# 
#         # Make the paths relative to the settings file
#         paths = ['source', 'destination', 'watermark']
# 
#         if os.path.isdir(join(settings_path, settings['theme'])) and os.path.isdir(
#             join(settings_path, settings['theme'], 'templates')
#         ):
#             paths.append('theme')
# 
#         for p in paths:
#             path = settings[p]
#             if path and not isabs(path):
#                 settings[p] = abspath(normpath(join(settings_path, path)))
#                 logger.debug("Rewrite %s : %s -> %s", p, path, settings[p])
# 
#     for key in ('img_size', 'thumb_size', 'video_size'):
#         if settings[key]:
#             w, h = settings[key]
#             if h > w:
#                 settings[key] = (h, w)
#                 logger.warning(
#                     "The %s setting should be specified with the largest value first.",
#                     key,
#                 )
# 
#     if not settings['img_processor']:
#         logger.info('No Processor, images will not be resized')
# 
#     logger.debug('Settings:\n%s', pformat(settings, width=120))
#     return settings


# Path: tests/test_settings.py
import os
from sigal.settings import get_thumb, read_settings

    for src, ref in tests:
        assert get_thumb(settings, src) == ref

    tests = [
        ('example.webm', 'thumbnails/example.tn.jpg'),
        ('test/example.mp4', 'test/thumbnails/example.tn.jpg'),
        ('test/t/example.avi', 'test/t/thumbnails/example.tn.jpg'),
    ]
    for src, ref in tests:
        assert get_thumb(settings, src) == ref


def test_img_sizes(tmpdir):
    """Test that image size is swaped if needed."""

    conf = tmpdir.join('sigal.conf.py')
    conf.write("thumb_size = (150, 200)")

    settings = read_settings(str(conf))
    assert settings['thumb_size'] == (200, 150)


def test_theme_path(tmpdir):
    """Test that image size is swaped if needed."""

    tmpdir.join('theme').mkdir()
    tmpdir.join('theme').join('templates').mkdir()
    conf = tmpdir.join('sigal.conf.py')
    conf.write("theme = 'theme'")


    settings = read_settings(str(conf))