コード例 #1
0
ファイル: test_extended_caching.py プロジェクト: saimn/sigal
def test_load_exif(settings, tmpdir):
    settings['destination'] = str(tmpdir)
    gal1 = Gallery(settings, ncpu=1)
    gal1.albums["exifTest"].medias[2].exif = "blafoo"
    # set mod_date in future, to force these values
    gal1.metadataCache = {
        "exifTest/21.jpg": {
            "exif": "Foo",
            "mod_date": 100000000000
        },
        "exifTest/22.jpg": {
            "exif": "Bar",
            "mod_date": 100000000000
        },
    }

    extended_caching.load_metadata(gal1.albums["exifTest"])

    assert gal1.albums["exifTest"].medias[0].exif == "Foo"
    assert gal1.albums["exifTest"].medias[1].exif == "Bar"
    assert gal1.albums["exifTest"].medias[2].exif == "blafoo"

    # check if setting gallery.metadataCache works
    gal2 = Gallery(settings, ncpu=1)
    extended_caching.save_cache(gal1)
    extended_caching.load_metadata(gal2.albums["exifTest"])

    assert gal2.albums["exifTest"].medias[0].exif == "Foo"
    assert gal2.albums["exifTest"].medias[1].exif == "Bar"
    assert gal2.albums["exifTest"].medias[2].exif == "blafoo"
コード例 #2
0
def test_restore_cache(settings, tmpdir):
    settings['destination'] = str(tmpdir)
    gal1 = Gallery(settings, ncpu=1)
    gal2 = Gallery(settings, ncpu=1)
    extended_caching.save_cache(gal1)
    extended_caching._restore_cache(gal2)
    assert gal1.exifCache == gal2.exifCache
コード例 #3
0
def test_encrypt(settings, tmpdir, disconnect_signals):
    settings['destination'] = str(tmpdir)
    if "sigal.plugins.encrypt" not in settings["plugins"]:
        settings['plugins'] += ["sigal.plugins.encrypt"]

    settings['encrypt_options'] = {
        'password': '******',
        'ask_password': True,
        'gcm_tag': 'AuTheNTiCatIoNtAG',
        'kdf_salt': 'saltysaltsweetysweet',
        'kdf_iters': 10000,
        'encrypt_symlinked_originals': False,
    }

    init_plugins(settings)
    gal = Gallery(settings)
    gal.build()

    # check the encrypt cache exists
    cachePath = os.path.join(settings["destination"], ".encryptCache")
    assert os.path.isfile(cachePath)

    encryptCache = None
    with open(cachePath, "rb") as cacheFile:
        encryptCache = pickle.load(cacheFile)
    assert isinstance(encryptCache, dict)

    testAlbum = gal.albums["encryptTest"]
    key, tag = get_key_tag(settings)

    for media in testAlbum:
        # check if sizes are stored in cache
        assert cache_key(media) in encryptCache
        assert "size" in encryptCache[cache_key(media)]
        assert "thumb_size" in encryptCache[cache_key(media)]
        assert "encrypted" in encryptCache[cache_key(media)]

        encryptedImages = [media.dst_path, media.thumb_path]
        if settings["keep_orig"]:
            encryptedImages.append(
                os.path.join(settings["destination"], media.path, media.big))

        # check if images are encrypted by trying to decrypt
        for image in encryptedImages:
            with open(image, "rb") as infile:
                with BytesIO() as outfile:
                    endec.decrypt(key, infile, outfile, tag)

    # check static files have been copied
    static = os.path.join(settings["destination"], 'static')
    assert os.path.isfile(os.path.join(static, "decrypt.js"))
    assert os.path.isfile(os.path.join(static, "keycheck.txt"))
    assert os.path.isfile(os.path.join(settings["destination"], "sw.js"))

    # check keycheck file
    with open(os.path.join(settings["destination"], 'static', "keycheck.txt"),
              "rb") as infile:
        with BytesIO() as outfile:
            endec.decrypt(key, infile, outfile, tag)
コード例 #4
0
ファイル: test_plugins.py プロジェクト: saimn/sigal
def test_titleregexp(settings, tmpdir, disconnect_signals):

    if "sigal.plugins.titleregexp" not in settings["plugins"]:
        settings['plugins'] += ["sigal.plugins.titleregexp"]

    init_plugins(settings)
    gal = Gallery(settings)
    gal.build()

    assert gal.albums.get('dir1').albums[1].title == "titleregexp 02"
コード例 #5
0
ファイル: test_gallery.py プロジェクト: MPavleski/sigal
def test_ignores(settings, tmpdir):
    tmp = str(tmpdir)
    settings['destination'] = tmp
    settings['ignore_directories'] = ['*test2']
    settings['ignore_files'] = ['dir2/Hubble*', '*.png']
    gal = Gallery(settings, ncpu=1)
    gal.build()

    assert 'test2' not in os.listdir(join(tmp, 'dir1'))
    assert 'archlinux-kiss-1024x640.png' not in os.listdir(
        join(tmp, 'dir1', 'test1'))
    assert 'Hubble Interacting Galaxy NGC 5257.jpg' not in os.listdir(
        join(tmp, 'dir2'))
コード例 #6
0
def test_gallery_max_img_pixels(settings, tmpdir, monkeypatch):
    "Test the Gallery class with the max_img_pixels setting."
    # monkeypatch is used here to reset the value to the PIL default.
    # This value does not matter, other than it is "large"
    # to show that settings['max_img_pixels'] works.
    monkeypatch.setattr('PIL.Image.MAX_IMAGE_PIXELS', 100_000_000)

    with open(str(tmpdir.join('my.css')), mode='w') as f:
        f.write('color: red')

    settings['destination'] = str(tmpdir)
    settings['user_css'] = str(tmpdir.join('my.css'))
    settings['max_img_pixels'] = 5000

    logger = logging.getLogger('sigal')
    logger.setLevel(logging.DEBUG)
    try:
        with pytest.raises(PILImage.DecompressionBombError):
            gal = Gallery(settings, ncpu=1)
            gal.build()

        settings['max_img_pixels'] = 100_000_000
        gal = Gallery(settings, ncpu=1)
        gal.build()
    finally:
        logger.setLevel(logging.INFO)
コード例 #7
0
ファイル: test_gallery.py プロジェクト: dubisheng/sigal
def test_gallery(settings, tmpdir):
    "Test the Gallery class."

    with open(str(tmpdir.join('my.css')), mode='w') as f:
        f.write('color: red')

    settings['destination'] = str(tmpdir)
    settings['user_css'] = str(tmpdir.join('my.css'))
    settings['webm_options'] = ['-missing-option', 'foobar']

    gal = Gallery(settings, ncpu=1)
    gal.build()

    mycss = os.path.join(settings['destination'], 'static', 'my.css')
    assert os.path.isfile(mycss)

    out_html = os.path.join(settings['destination'], 'index.html')
    assert os.path.isfile(out_html)

    with open(out_html) as f:
        html = f.read()

    assert '<title>Sigal test gallery</title>' in html
    assert '<link rel="stylesheet" href="static/my.css">' in html

    logger = logging.getLogger('sigal')
    logger.setLevel(logging.DEBUG)
    try:
        gal = Gallery(settings, ncpu=1)
        with pytest.raises(SubprocessException):
            gal.build()
    finally:
        logger.setLevel(logging.INFO)
コード例 #8
0
ファイル: test_gallery.py プロジェクト: iyotake/sigal
def test_gallery(settings, tmpdir):
    "Test the Gallery class."

    settings['destination'] = str(tmpdir)
    gal = Gallery(settings, ncpu=1)
    gal.build()

    out_html = os.path.join(settings['destination'], 'index.html')
    assert os.path.isfile(out_html)

    with open(out_html, 'r') as f:
        html = f.read()

    assert '<title>Sigal test gallery</title>' in html
コード例 #9
0
def test_ignores(settings, tmpdir):
    tmp = str(tmpdir)
    settings['destination'] = tmp
    settings['ignore_directories'] = ['*test2', 'accentué']
    settings['ignore_files'] = ['dir2/Hubble*', '*.png', '*CMB_*']
    gal = Gallery(settings, ncpu=1)
    gal.build()

    assert 'test2' not in os.listdir(join(tmp, 'dir1'))
    assert 'accentué' not in os.listdir(tmp)
    assert 'CMB_Timeline300_no_WMAP.jpg' not in os.listdir(
        join(tmp, 'dir1', 'test1'))
    assert 'Hubble Interacting Galaxy NGC 5257.jpg' not in os.listdir(
        join(tmp, 'dir2'))
コード例 #10
0
ファイル: test_gallery.py プロジェクト: MPavleski/sigal
def test_gallery(settings, tmpdir):
    "Test the Gallery class."

    settings['destination'] = str(tmpdir)
    gal = Gallery(settings, ncpu=1)
    gal.build()

    out_html = os.path.join(settings['destination'], 'index.html')
    assert os.path.isfile(out_html)

    with open(out_html, 'r') as f:
        html = f.read()

    assert '<title>Sigal test gallery</title>' in html
コード例 #11
0
def test_load_exif(settings, remove_cache):
    gal1 = Gallery(settings, ncpu=1)
    gal1.albums["exifTest"].medias[2].exif = "blafoo"
    gal1.exifCache = {"exifTest/21.jpg": "Foo", "exifTest/22.jpg": "Bar"}

    extended_caching.load_exif(gal1.albums["exifTest"])

    assert gal1.albums["exifTest"].medias[0].exif == "Foo"
    assert gal1.albums["exifTest"].medias[1].exif == "Bar"
    assert gal1.albums["exifTest"].medias[2].exif == "blafoo"

    # check if setting gallery.exifCache works
    gal2 = Gallery(settings, ncpu=1)
    extended_caching.save_cache(gal1)
    extended_caching.load_exif(gal2.albums["exifTest"])
コード例 #12
0
ファイル: test_extended_caching.py プロジェクト: saimn/sigal
def test_restore_cache(settings, tmpdir):
    settings['destination'] = str(tmpdir)
    gal1 = Gallery(settings, ncpu=1)
    gal2 = Gallery(settings, ncpu=1)
    extended_caching.save_cache(gal1)
    extended_caching._restore_cache(gal2)
    assert gal1.metadataCache == gal2.metadataCache

    # test bad cache
    cachePath = os.path.join(settings['destination'], ".metadata_cache")
    with open(cachePath, 'w') as f:
        f.write('bad pickle file')

    extended_caching._restore_cache(gal2)
    assert gal2.metadataCache == {}
コード例 #13
0
def test_medias_sort(settings):
    gal = Gallery(settings, ncpu=1)
    album = REF['dir1/test2']

    settings['medias_sort_reverse'] = True
    a = Album('dir1/test2', settings, album['subdirs'], album['medias'], gal)
    a.sort_medias(settings['medias_sort_attr'])
    assert [im.dst_filename
            for im in a.images] == list(reversed(album['medias']))

    settings['medias_sort_attr'] = 'date'
    settings['medias_sort_reverse'] = False
    a = Album('dir1/test2', settings, album['subdirs'], album['medias'], gal)
    a.sort_medias(settings['medias_sort_attr'])
    assert a.medias[0].src_filename == '22.jpg'

    settings['medias_sort_attr'] = 'meta.order'
    settings['medias_sort_reverse'] = False
    a = Album('dir1/test2', settings, album['subdirs'], album['medias'], gal)
    a.sort_medias(settings['medias_sort_attr'])
    assert [im.dst_filename for im in a.images] == [
        '21.tiff',
        '22.jpg',
        'CMB_Timeline300_no_WMAP.jpg',
    ]
コード例 #14
0
ファイル: test_extended_caching.py プロジェクト: saimn/sigal
def test_load_exif(settings, remove_cache):
    gal1 = Gallery(settings, ncpu=1)
    gal1.albums["exifTest"].medias[2].exif = "blafoo"
    gal1.exifCache = {"exifTest/21.jpg": "Foo",
                      "exifTest/22.jpg": "Bar"}

    extended_caching.load_exif(gal1.albums["exifTest"])

    assert gal1.albums["exifTest"].medias[0].exif == "Foo"
    assert gal1.albums["exifTest"].medias[1].exif == "Bar"
    assert gal1.albums["exifTest"].medias[2].exif == "blafoo"

    # check if setting gallery.exifCache works
    gal2 = Gallery(settings, ncpu=1)
    extended_caching.save_cache(gal1)
    extended_caching.load_exif(gal2.albums["exifTest"])
コード例 #15
0
ファイル: test_gallery.py プロジェクト: dairiki/sigal
def test_albums_sort(settings):
    gal = Gallery(settings, ncpu=1)
    album = REF['dir1']
    subdirs = list(album['subdirs'])

    settings['albums_sort_reverse'] = False
    a = Album('dir1', settings, album['subdirs'], album['medias'], gal)
    a.sort_subdirs('')
    assert [alb.name for alb in a.albums] == subdirs

    settings['albums_sort_reverse'] = True
    a = Album('dir1', settings, album['subdirs'], album['medias'], gal)
    a.sort_subdirs('')
    assert [alb.name for alb in a.albums] == list(reversed(subdirs))

    titles = [im.title for im in a.albums]
    titles.sort()
    settings['albums_sort_reverse'] = False
    a = Album('dir1', settings, album['subdirs'], album['medias'], gal)
    a.sort_subdirs('title')
    assert [im.title for im in a.albums] == titles

    settings['albums_sort_reverse'] = True
    a = Album('dir1', settings, album['subdirs'], album['medias'], gal)
    a.sort_subdirs('title')
    assert [im.title for im in a.albums] == list(reversed(titles))
コード例 #16
0
def test_album(path, album, settings, tmpdir):
    # store current locale
    old_locale = locale.setlocale(locale.LC_ALL)

    # locale.setlocale(locale.LC_ALL, 'fr_FR')
    locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8')

    try:
        gal = Gallery(settings, ncpu=1)
        a = Album(path, settings, album['subdirs'], album['medias'], gal)

        assert a.title == album['title']
        assert a.name == album['name']
        assert a.subdirs == album['subdirs']
        assert a.thumbnail == album['thumbnail']
        if path == 'video':
            assert list(a.images) == []
            assert [m.filename for m in a.medias] == \
                [album['medias'][0].replace('.ogv', '.webm')]
        else:
            assert list(a.videos) == []
            assert [m.filename for m in a.medias] == album['medias']
        assert len(a) == len(album['medias'])
    finally:
        # restore locale back
        locale.setlocale(locale.LC_ALL, old_locale)
コード例 #17
0
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, ncpu=1)
    gal.build()

    out_html = os.path.join(settings['destination'], 'index.html')
    assert os.path.isfile(out_html)

    with open(out_html, 'r') as f:
        html = f.read()

    assert '<title>Sigal test gallery</title>' in html
コード例 #18
0
def make_gallery(source_dir='dir1', **kwargs):
    default_conf = os.path.join(SAMPLE_DIR, 'sigal.conf.py')
    settings = read_settings(default_conf)
    settings['source'] = os.path.join(SAMPLE_SOURCE, source_dir)
    settings.update(kwargs)
    init_plugins(settings)
    return Gallery(settings, ncpu=1)
コード例 #19
0
ファイル: test_gallery.py プロジェクト: iyotake/sigal
def test_albums_sort(settings):
    gal = Gallery(settings, ncpu=1)
    album = REF['dir1']

    settings['albums_sort_reverse'] = True
    a = Album('dir1', settings, album['subdirs'], album['medias'], gal)
    assert [im.filename for im in a.images] == list(reversed(album['medias']))
コード例 #20
0
def make_gallery(settings, tmpdir, method):
    settings['destination'] = str(tmpdir)
    if "sigal.plugins.compress_assets" not in settings["plugins"]:
        settings['plugins'] += ["sigal.plugins.compress_assets"]

    # Set method
    settings.setdefault('compress_assets_options', {})['method'] = method

    compress_options = compress_assets.DEFAULT_SETTINGS.copy()
    # The key was created by the previous setdefault if needed
    compress_options.update(settings['compress_assets_options'])

    init_plugins(settings)
    gal = Gallery(settings)
    gal.build()

    return compress_options
コード例 #21
0
ファイル: test_plugins.py プロジェクト: saimn/sigal
def test_nonmedia_files(settings, tmpdir, disconnect_signals):

    settings['destination'] = str(tmpdir)
    settings['plugins'] += ['sigal.plugins.nonmedia_files']

    init_plugins(settings)

    gal = Gallery(settings)
    gal.build()

    outfile = os.path.join(settings['destination'], 'nonmedia_files', 'dummy.pdf')
    assert os.path.isfile(outfile)

    outthumb = os.path.join(
        settings['destination'], 'nonmedia_files', 'thumbnails', 'dummy.tn.jpg'
    )
    assert os.path.isfile(outthumb)
コード例 #22
0
def test_nomedia_plugin(settings, tmpdir):

    settings['destination'] = str(tmpdir)
    if "plugins" in settings:
        if not "sigal.plugins.nomedia" in settings["plugins"]:
            settings['plugins'] += ["sigal.plugins.nomedia"]
    else:
        settings["plugins"] = ["sigal.plugins.nomedia"]

    init_plugins(settings)
    gal = Gallery(settings)
    gal.build()

    for path, dirs, files in os.walk(os.path.join(str(tmpdir), "nomedia")):
        assert "ignore" not in path

        for file in files:
            assert "ignore" not in file
コード例 #23
0
ファイル: test_nomedia_plugin.py プロジェクト: matze/sigal
def test_nomedia_plugin(settings, tmpdir):

    settings['destination'] = str(tmpdir)
    if "plugins"in settings:
        if not "sigal.plugins.nomedia" in settings["plugins"]:
            settings['plugins'] += ["sigal.plugins.nomedia"]
    else:
        settings["plugins"] = ["sigal.plugins.nomedia"]

    init_plugins(settings)
    gal = Gallery(settings)
    gal.build()

    for path, dirs, files in os.walk(os.path.join(str(tmpdir), "nomedia")):
        assert "ignore" not in path

        for file in files:
            assert "ignore" not in file
コード例 #24
0
def make_gallery(settings, tmpdir, method):
    settings['destination'] = str(tmpdir)
    # Really speed up testing
    settings['use_orig'] = True
    if "sigal.plugins.compress_assets" not in settings["plugins"]:
        settings['plugins'] += ["sigal.plugins.compress_assets"]

    # Set method
    settings.setdefault('compress_assets_options', {})['method'] = method

    compress_options = compress_assets.DEFAULT_SETTINGS.copy()
    # The key was created by the previous setdefault if needed
    compress_options.update(settings['compress_assets_options'])

    init_plugins(settings)
    gal = Gallery(settings)
    gal.build()

    return compress_options
コード例 #25
0
ファイル: test_gallery.py プロジェクト: saimn/sigal
def test_custom_theme(settings, tmp_path, caplog):

    theme_path = tmp_path / 'mytheme'
    tpl_path = theme_path / 'templates'

    settings['destination'] = str(tmp_path / 'build')
    settings['source'] = os.path.join(settings['source'], 'encryptTest')
    settings['theme'] = str(theme_path)
    settings['title'] = 'My gallery'

    gal = Gallery(settings, ncpu=1)

    with pytest.raises(Exception, match='Impossible to find the theme'):
        gal.build()

    tpl_path.mkdir(parents=True)
    (theme_path / 'static').mkdir(parents=True)

    with pytest.raises(SystemExit):
        gal.build()
        assert caplog.records[0].message.startswith(
            'The template album.html was not found in template folder')

    with open(tpl_path / 'album.html', mode='w') as f:
        f.write(""" {{ settings.title|myfilter }} """)
    with open(tpl_path / 'album_list.html', mode='w') as f:
        f.write(""" {{ settings.title|myfilter }} """)
    with open(theme_path / 'filters.py', mode='w') as f:
        f.write("""
def myfilter(value):
    return f'{value} is very nice'
""")

    gal = Gallery(settings, ncpu=1)
    gal.build()

    out_html = os.path.join(settings['destination'], 'index.html')
    assert os.path.isfile(out_html)

    with open(out_html) as f:
        html = f.read()

    assert 'My gallery is very nice' in html
コード例 #26
0
ファイル: test_gallery.py プロジェクト: iyotake/sigal
def test_album_medias(settings):
    gal = Gallery(settings, ncpu=1)

    album = REF['dir1/test1']
    a = Album('dir1/test1', settings, album['subdirs'], album['medias'], gal)
    assert list(im.filename for im in a.images) == album['medias']
    assert list(a.videos) == []

    album = REF['video']
    a = Album('video', settings, album['subdirs'], album['medias'], gal)
    assert list(im.filename for im in a.videos) == album['medias']
    assert list(a.images) == []
コード例 #27
0
ファイル: test_plugins.py プロジェクト: saimn/sigal
def test_plugins(settings, tmpdir, disconnect_signals):

    settings['destination'] = str(tmpdir)
    if "sigal.plugins.nomedia" not in settings["plugins"]:
        settings['plugins'] += ["sigal.plugins.nomedia"]
    if "sigal.plugins.media_page" not in settings["plugins"]:
        settings['plugins'] += ["sigal.plugins.media_page"]

    init_plugins(settings)
    gal = Gallery(settings)
    gal.build()

    out_html = os.path.join(settings['destination'],
                            'dir2', 'KeckObservatory20071020.jpg.html')
    assert os.path.isfile(out_html)

    for path, dirs, files in os.walk(os.path.join(str(tmpdir), "nomedia")):
        assert "ignore" not in path

        for file in files:
            assert "ignore" not in file
コード例 #28
0
def test_plugins(settings, tmpdir, disconnect_signals):

    settings['destination'] = str(tmpdir)
    if "sigal.plugins.nomedia" not in settings["plugins"]:
        settings['plugins'] += ["sigal.plugins.nomedia"]
    if "sigal.plugins.media_page" not in settings["plugins"]:
        settings['plugins'] += ["sigal.plugins.media_page"]

    init_plugins(settings)
    gal = Gallery(settings)
    gal.build()

    out_html = os.path.join(settings['destination'],
                            'dir2', 'KeckObservatory20071020.jpg.html')
    assert os.path.isfile(out_html)

    for path, dirs, files in os.walk(os.path.join(str(tmpdir), "nomedia")):
        assert "ignore" not in path

        for file in files:
            assert "ignore" not in file
コード例 #29
0
ファイル: test_gallery.py プロジェクト: saimn/sigal
def test_albums_sort(settings):
    gal = Gallery(settings, ncpu=1)
    album = REF['dir1']
    subdirs = list(album['subdirs'])

    settings['albums_sort_reverse'] = False
    a = Album('dir1', settings, album['subdirs'], album['medias'], gal)
    a.sort_subdirs('')
    assert [alb.name for alb in a.albums] == subdirs

    settings['albums_sort_reverse'] = True
    a = Album('dir1', settings, album['subdirs'], album['medias'], gal)
    a.sort_subdirs('')
    assert [alb.name for alb in a.albums] == list(reversed(subdirs))

    titles = [im.title for im in a.albums]
    titles.sort()
    settings['albums_sort_reverse'] = False
    a = Album('dir1', settings, album['subdirs'], album['medias'], gal)
    a.sort_subdirs('title')
    assert [im.title for im in a.albums] == titles

    settings['albums_sort_reverse'] = True
    a = Album('dir1', settings, album['subdirs'], album['medias'], gal)
    a.sort_subdirs('title')
    assert [im.title for im in a.albums] == list(reversed(titles))

    orders = ['01', '02', '03']
    orders.sort()
    settings['albums_sort_reverse'] = False
    a = Album('dir1', settings, album['subdirs'], album['medias'], gal)
    a.sort_subdirs('meta.order')
    assert [d.meta['order'][0] for d in a.albums] == orders

    settings['albums_sort_reverse'] = True
    a = Album('dir1', settings, album['subdirs'], album['medias'], gal)
    a.sort_subdirs('meta.order')
    assert [d.meta['order'][0] for d in a.albums] == list(reversed(orders))

    settings['albums_sort_reverse'] = False
    a = Album('dir1', settings, album['subdirs'], album['medias'], gal)
    a.sort_subdirs(['meta.partialorder', 'meta.order'])
    assert [d.name for d in a.albums] == list(['test1', 'test2', 'test3'])

    settings['albums_sort_reverse'] = False
    a = Album('dir1', settings, album['subdirs'], album['medias'], gal)
    a.sort_subdirs(['meta.partialorderb', 'name'])
    assert [d.name for d in a.albums] == list(['test2', 'test3', 'test1'])

    settings['albums_sort_reverse'] = True
    a = Album('dir1', settings, album['subdirs'], album['medias'], gal)
    a.sort_subdirs(['meta.partialorderb', 'name'])
    assert [d.name for d in a.albums] == list(['test1', 'test3', 'test2'])
コード例 #30
0
ファイル: test_gallery.py プロジェクト: saimn/sigal
def test_gallery(settings, tmpdir):
    "Test the Gallery class."

    settings['destination'] = str(tmpdir)
    settings['webm_options'] = ['-missing-option', 'foobar']

    gal = Gallery(settings, ncpu=1)
    gal.build()

    out_html = os.path.join(settings['destination'], 'index.html')
    assert os.path.isfile(out_html)

    with open(out_html, 'r') as f:
        html = f.read()

    assert '<title>Sigal test gallery</title>' in html

    logger = logging.getLogger('sigal')
    logger.setLevel(logging.DEBUG)
    try:
        gal = Gallery(settings, ncpu=1)
        with pytest.raises(SubprocessException):
            gal.build()
    finally:
        logger.setLevel(logging.INFO)
コード例 #31
0
ファイル: test_gallery.py プロジェクト: iyotake/sigal
def test_medias_sort(settings):
    gal = Gallery(settings, ncpu=1)
    album = REF['dir1/test2']

    settings['medias_sort_reverse'] = True
    a = Album('dir1/test2', settings, album['subdirs'], album['medias'], gal)
    assert [im.filename for im in a.images] == list(reversed(album['medias']))

    settings['medias_sort_attr'] = 'date'
    settings['medias_sort_reverse'] = False
    a = Album('dir1/test2', settings, album['subdirs'], album['medias'], gal)
    assert [im.filename for im in a.images] == ['22.jpg', '21.jpg',
                                                'archlinux-kiss-1024x640.png']
コード例 #32
0
ファイル: test_gallery.py プロジェクト: saimn/sigal
def test_gallery(settings, tmp_path, caplog):
    "Test the Gallery class."

    caplog.set_level('ERROR')
    settings['destination'] = str(tmp_path)
    settings['user_css'] = str(tmp_path / 'my.css')
    settings['webm_options'] = ['-missing-option', 'foobar']
    gal = Gallery(settings, ncpu=1)

    gal.build()
    assert re.match(r'CSS file .* could not be found',
                    caplog.records[3].message)

    with open(tmp_path / 'my.css', mode='w') as f:
        f.write('color: red')

    gal.build()

    mycss = os.path.join(settings['destination'], 'static', 'my.css')
    assert os.path.isfile(mycss)

    out_html = os.path.join(settings['destination'], 'index.html')
    assert os.path.isfile(out_html)

    with open(out_html) as f:
        html = f.read()

    assert '<title>Sigal test gallery - Sigal test gallery ☺</title>' in html
    assert '<link rel="stylesheet" href="static/my.css">' in html

    logger = logging.getLogger('sigal')
    logger.setLevel(logging.DEBUG)
    try:
        gal = Gallery(settings, ncpu=1)
        with pytest.raises(SubprocessException):
            gal.build()
    finally:
        logger.setLevel(logging.INFO)
コード例 #33
0
def test_save_cache(settings):
    gal = Gallery(settings, ncpu=1)
    extended_caching.save_cache(gal)

    cachePath = os.path.join(settings['destination'], ".exif_cache")

    assert os.path.isfile(cachePath)

    with open(cachePath, "rb") as cacheFile:
        cache = pickle.load(cacheFile)

    assert cache["exifTest/21.jpg"] == gal.albums["exifTest"].medias[0].exif
    assert cache["exifTest/22.jpg"] == gal.albums["exifTest"].medias[1].exif
    assert cache["exifTest/noexif.png"] == gal.albums["exifTest"].medias[2].exif
コード例 #34
0
ファイル: test_extended_caching.py プロジェクト: saimn/sigal
def test_load_metadata_missing(settings, tmpdir):
    settings['destination'] = str(tmpdir)
    gal = Gallery(settings, ncpu=1)
    extended_caching.save_cache(gal)
    assert gal.metadataCache

    # test if file disappears
    gal.albums["exifTest"].medias.append(
        Image("foooo.jpg", "exifTest", settings))

    # set mod_date to -1 to force cache update
    gal.metadataCache = {
        "exifTest/_index": {
            "mod_date": -1,
        },
        "exifTest/21.jpg": {
            "exif": "Foo",
            "mod_date": -1
        },
        "exifTest/foooo.jpg": {
            "exif": "Foo"
        },
        "dir1/test2/22.jpg": {
            "exif": "Bar",
            "mod_date": 100000000000,
            "meta_mod_date": -1,
            "markdown_metadata": "Bar",
        },
    }
    # errors should all be caught
    extended_caching.load_metadata(gal.albums["exifTest"])
    assert gal.albums["exifTest"].medias[0].exif != "Foo"
    assert gal.albums["exifTest"].medias[-1].exif != "Foo"

    extended_caching.load_metadata(gal.albums["dir1/test2"])
    assert gal.albums["dir1/test2"].medias[1].exif == "Bar"
    assert gal.albums["dir1/test2"].medias[1].markdown_metadata != "Bar"
コード例 #35
0
ファイル: test_extended_caching.py プロジェクト: saimn/sigal
def test_save_cache(settings, tmpdir):
    settings['destination'] = str(tmpdir)
    gal = Gallery(settings, ncpu=1)
    extended_caching.save_cache(gal)

    cachePath = os.path.join(settings['destination'], ".metadata_cache")

    assert os.path.isfile(cachePath)

    with open(cachePath, "rb") as cacheFile:
        cache = pickle.load(cacheFile)

    # test exif
    album = gal.albums["exifTest"]
    cache_img = cache["exifTest/21.jpg"]
    assert cache_img["exif"] == album.medias[0].exif
    assert 'markdown_metadata' not in cache_img
    assert cache_img["file_metadata"] == album.medias[0].file_metadata

    cache_img = cache["exifTest/22.jpg"]
    assert cache_img["exif"] == album.medias[1].exif
    assert 'markdown_metadata' not in cache_img
    assert cache_img["file_metadata"] == album.medias[1].file_metadata

    cache_img = cache["exifTest/noexif.png"]
    assert cache_img["exif"] == album.medias[2].exif
    assert 'markdown_metadata' not in cache_img
    assert cache_img["file_metadata"] == album.medias[2].file_metadata

    # test iptc and md
    album = gal.albums["iptcTest"]
    assert cache["iptcTest/_index"][
        "markdown_metadata"] == album.markdown_metadata

    cache_img = cache["iptcTest/1.jpg"]
    assert cache_img["file_metadata"] == album.medias[0].file_metadata
    assert 'markdown_metadata' not in cache_img

    cache_img = cache["iptcTest/2.jpg"]
    assert cache_img["markdown_metadata"] == album.medias[1].markdown_metadata

    # test if file disappears
    gal.albums["exifTest"].medias.append(
        Image("foooo.jpg", "exifTest", settings))
    extended_caching.save_cache(gal)
    with open(cachePath, "rb") as cacheFile:
        cache = pickle.load(cacheFile)
    assert "exifTest/foooo.jpg" not in cache