示例#1
0
def test_process_video(tmpdir):
    base, ext = os.path.splitext(TEST_VIDEO)

    settings = create_settings(video_format='ogv', use_orig=True,
                               orig_link=True)
    process_video(SRCFILE, str(tmpdir), settings)
    dstfile = str(tmpdir.join(base + '.ogv'))
    assert os.path.realpath(dstfile) == SRCFILE

    settings = create_settings(video_format='mjpg')
    assert process_video(SRCFILE, str(tmpdir), settings) == Status.FAILURE

    settings = create_settings(thumb_video_delay=-1)
    assert process_video(SRCFILE, str(tmpdir), settings) == Status.FAILURE
示例#2
0
文件: test_image.py 项目: kuyan/sigal
def test_generate_image_processor(tmpdir):
    "Test generate_image with a wrong processor name."

    init_logging()
    dstfile = str(tmpdir.join(TEST_IMAGE))
    with pytest.raises(SystemExit):
        settings = create_settings(img_size=(200, 200), img_processor="WrongMethod")
        generate_image(SRCFILE, dstfile, settings)
示例#3
0
def test_generate_image(tmpdir):
    "Test the generate_image function."

    dstfile = str(tmpdir.join(TEST_IMAGE))
    for size in [(600, 600), (300, 200)]:
        settings = create_settings(img_size=size, img_processor='ResizeToFill')
        generate_image(SRCFILE, dstfile, settings)
        im = Image.open(dstfile)
        assert im.size == size
示例#4
0
文件: test_image.py 项目: matze/sigal
def test_generate_image_passthrough_symlink(tmpdir):
    "Test the generate_image function with use_orig=True and orig_link=True."

    dstfile = str(tmpdir.join(TEST_IMAGE))
    settings = create_settings(use_orig=True, orig_link=True)
    generate_image(SRCFILE, dstfile, settings)
    # Check the file was symlinked
    assert os.path.islink(dstfile)
    assert os.path.samefile(SRCFILE, dstfile)
示例#5
0
def test_generate_image_processor(tmpdir):
    "Test generate_image with a wrong processor name."

    init_logging('sigal')
    dstfile = str(tmpdir.join(TEST_IMAGE))
    settings = create_settings(img_size=(200, 200),
                               img_processor='WrongMethod')

    with pytest.raises(SystemExit):
        generate_image(SRCFILE, dstfile, settings)
示例#6
0
def test_process_video(tmpdir):
    base, ext = os.path.splitext(TEST_VIDEO)

    settings = create_settings(
        video_format='ogv',
        use_orig=True,
        orig_link=True,
        source=os.path.join(SRCDIR, 'video'),
        destination=str(tmpdir),
    )
    video = Video(TEST_VIDEO, '.', settings)
    process_video(video)
    dstfile = str(tmpdir.join(base + '.ogv'))
    assert os.path.realpath(dstfile) == SRCFILE

    settings = create_settings(video_format='mjpg')
    assert process_video(video) == Status.FAILURE

    settings = create_settings(thumb_video_delay=-1)
    assert process_video(video) == Status.FAILURE
示例#7
0
文件: test_image.py 项目: tanty/sigal
def test_generate_image_imgformat(tmpdir):
    "Test the effects of the img_format setting on generate_image."

    dstfile = str(tmpdir.join(TEST_IMAGE))
    for i, outfmt in enumerate(["JPEG", "PNG", "TIFF"]):
        settings = create_settings(img_size=(300,300), img_processor='ResizeToFill',
                                   copy_exif_data=True, img_format=outfmt)
        options = {'quality': 85}
        generate_image(SRCFILE, dstfile, settings, options=options)
        im = Image.open(dstfile)
        assert im.format == outfmt
示例#8
0
def test_generate_image(tmpdir):
    "Test the generate_image function."

    dstfile = str(tmpdir.join(TEST_IMAGE))
    for i, size in enumerate([(600, 600), (300, 200)]):
        settings = create_settings(img_size=size, img_processor='ResizeToFill',
                                   copy_exif_data=True)
        options = None if i == 0 else {'quality': 85}
        generate_image(SRCFILE, dstfile, settings, options=options)
        im = Image.open(dstfile)
        assert im.size == size
示例#9
0
文件: test_image.py 项目: matze/sigal
def test_generate_image(tmpdir):
    "Test the generate_image function."

    dstfile = str(tmpdir.join(TEST_IMAGE))
    for i, size in enumerate([(600, 600), (300, 200)]):
        settings = create_settings(img_size=size, img_processor='ResizeToFill',
                                   copy_exif_data=True)
        options = None if i == 0 else {'quality': 85}
        generate_image(SRCFILE, dstfile, settings, options=options)
        im = Image.open(dstfile)
        assert im.size == size
示例#10
0
def test_generate_image_passthrough(tmpdir, image, path):
    "Test the generate_image function with use_orig=True."

    dstfile = str(tmpdir.join(image))
    settings = create_settings(use_orig=True)
    generate_image(path, dstfile, settings)
    # Check the file was copied, not (sym)linked
    st_src = os.stat(path)
    st_dst = os.stat(dstfile)
    assert st_src.st_size == st_dst.st_size
    assert not os.path.samestat(st_src, st_dst)
示例#11
0
文件: test_image.py 项目: matze/sigal
def test_generate_image_passthrough(tmpdir, image, path):
    "Test the generate_image function with use_orig=True."

    dstfile = str(tmpdir.join(image))
    settings = create_settings(use_orig=True)
    generate_image(path, dstfile, settings)
    # Check the file was copied, not (sym)linked
    st_src = os.stat(path)
    st_dst = os.stat(dstfile)
    assert st_src.st_size == st_dst.st_size
    assert not os.path.samestat(st_src, st_dst)
示例#12
0
def test_generate_video_dont_enlarge(tmpdir, fmt):
    """Video dimensions should not be enlarged."""

    base, ext = os.path.splitext(TEST_VIDEO)
    dstfile = str(tmpdir.join(base + '.' + fmt))
    settings = create_settings(video_size=(1000, 1000), video_format=fmt)
    generate_video(SRCFILE, dstfile, settings)
    size_src = video_size(SRCFILE)
    size_dst = video_size(dstfile)

    assert size_src == size_dst
示例#13
0
文件: test_image.py 项目: tg--/sigal
def test_process_image(tmpdir):
    "Test the process_image function."

    status = process_image('foo.txt', 'none.txt', {})
    assert status == Status.FAILURE

    settings = create_settings(img_processor='ResizeToFill', make_thumbs=False)
    status = process_image(SRCFILE, str(tmpdir), settings)
    assert status == Status.SUCCESS
    im = Image.open(os.path.join(str(tmpdir), TEST_IMAGE))
    assert im.size == settings['img_size']
示例#14
0
文件: test_image.py 项目: matze/sigal
def test_process_image(tmpdir):
    "Test the process_image function."

    status = process_image('foo.txt', 'none.txt', {})
    assert status == Status.FAILURE

    settings = create_settings(img_processor='ResizeToFill', make_thumbs=False)
    status = process_image(SRCFILE, str(tmpdir), settings)
    assert status == Status.SUCCESS
    im = Image.open(os.path.join(str(tmpdir), TEST_IMAGE))
    assert im.size == settings['img_size']
示例#15
0
def test_generate_video_dont_enlarge(tmpdir, fmt):
    """video dimensions should not be enlarged"""

    base, ext = os.path.splitext(TEST_VIDEO)
    dstfile = str(tmpdir.join(base + '.' + fmt))
    settings = create_settings(video_size=(1000, 1000), video_format=fmt)
    generate_video(SRCFILE, dstfile, settings,
                   options=settings.get(fmt + '_options'))
    size_src = video_size(SRCFILE)
    size_dst = video_size(dstfile)

    assert size_src == size_dst
示例#16
0
def test_generate_video_dont_enlarge(tmpdir):
    """video dimensions should not be enlarged"""

    base, ext = os.path.splitext(TEST_VIDEO)
    dstfile = str(tmpdir.join(base + '.webm'))
    settings = create_settings(video_size=(1000, 1000))
    generate_video(SRCFILE, dstfile, settings)

    size_src = video_size(SRCFILE)
    size_dst = video_size(dstfile)

    assert size_src == size_dst
示例#17
0
def test_metadata(tmpdir):
    base, ext = os.path.splitext(TEST_VIDEO)

    settings = create_settings(
        video_format='ogv',
        use_orig=True,
        orig_link=True,
        source=os.path.join(SRCDIR, 'video'),
        destination=str(tmpdir),
    )
    video = Video(TEST_VIDEO, '.', settings)
    assert video.meta == {'date': ['2020-01-01T09:00:00']}
    assert video.date == datetime(2020, 1, 1, 9, 0)
示例#18
0
def test_generate_video_fit_width(tmpdir):
    """largest fitting dimension is width"""

    base, ext = os.path.splitext(TEST_VIDEO)
    dstfile = str(tmpdir.join(base + '.webm'))
    settings = create_settings(video_size=(100, 50))
    generate_video(SRCFILE, dstfile, settings)

    size_src = video_size(SRCFILE)
    size_dst = video_size(dstfile)

    assert size_dst[1] == 50
    # less than 2% error on ratio
    assert abs(size_dst[0]/size_dst[1] - size_src[0]/size_src[1]) < 2e-2
示例#19
0
def test_generate_video_fit_width(tmpdir, fmt):
    """largest fitting dimension is width"""

    base, ext = os.path.splitext(TEST_VIDEO)
    dstfile = str(tmpdir.join(base + '.' + fmt))
    settings = create_settings(video_size=(100, 50), video_format=fmt)
    generate_video(SRCFILE, dstfile, settings)

    size_src = video_size(SRCFILE)
    size_dst = video_size(dstfile)

    assert size_dst[1] == 50
    # less than 2% error on ratio
    assert abs(size_dst[0] / size_dst[1] - size_src[0] / size_src[1]) < 2e-2
示例#20
0
def test_generate_video_fit_height(tmpdir, fmt):
    """largest fitting dimension is height"""

    base, ext = os.path.splitext(TEST_VIDEO)
    dstfile = str(tmpdir.join(base + '.' + fmt))
    settings = create_settings(video_size=(50, 100), video_format=fmt)
    generate_video(SRCFILE, dstfile, settings,
                   options=settings[fmt + '_options'])

    size_src = video_size(SRCFILE)
    size_dst = video_size(dstfile)

    assert size_dst[0] == 50
    # less than 2% error on ratio
    assert abs(size_dst[0]/size_dst[1] - size_src[0]/size_src[1]) < 2e-2
示例#21
0
文件: test_image.py 项目: kuyan/sigal
def test_exif_gps(tmpdir):
    """Test reading out correct geo tags"""
    test_image = "flickr_jerquiaga_2394751088_cc-by-nc.jpg"
    src_file = os.path.join(CURRENT_DIR, "sample", "pictures", "dir1", "test1", test_image)
    dst_file = str(tmpdir.join(test_image))

    settings = create_settings(img_size=(400, 300), copy_exif_data=True)
    generate_image(src_file, dst_file, settings)
    raw, simple = get_exif_tags(dst_file)
    assert "gps" in simple

    lat = 35.266666
    lon = -117.216666

    assert abs(simple["gps"]["lat"] - lat) < 0.0001
    assert abs(simple["gps"]["lon"] - lon) < 0.0001
示例#22
0
def test_exif_copy(tmpdir):
    "Test if EXIF data can transfered copied to the resized image."

    test_image = "11.jpg"
    src_file = os.path.join(CURRENT_DIR, "sample", "pictures", "dir1", "test1", test_image)
    dst_file = str(tmpdir.join(test_image))

    settings = create_settings(img_size=(300, 400), copy_exif_data=True)
    generate_image(src_file, dst_file, settings)
    simple = get_exif_tags(get_exif_data(dst_file))
    assert simple["iso"] == 50

    settings["copy_exif_data"] = False
    generate_image(src_file, dst_file, settings)
    simple = get_exif_tags(get_exif_data(dst_file))
    assert not simple
示例#23
0
def test_generate_video_fit_height(tmpdir, fmt):
    """largest fitting dimension is height"""

    base, ext = os.path.splitext(TEST_VIDEO)
    dstfile = str(tmpdir.join(base + '.' + fmt))
    settings = create_settings(video_size=(80, 100), video_format=fmt)
    generate_video(SRCFILE,
                   dstfile,
                   settings,
                   options=settings[fmt + '_options'])

    size_src = video_size(SRCFILE)
    size_dst = video_size(dstfile)

    assert size_dst[0] == 80
    # less than 2% error on ratio
    assert abs(size_dst[0] / size_dst[1] - size_src[0] / size_src[1]) < 2e-2
示例#24
0
def test_exif_copy(tmpdir):
    "Test if EXIF data can transferred copied to the resized image."

    test_image = '11.jpg'
    src_file = os.path.join(CURRENT_DIR, 'sample', 'pictures', 'dir1', 'test1',
                            test_image)
    dst_file = str(tmpdir.join(test_image))

    settings = create_settings(img_size=(300, 400), copy_exif_data=True)
    generate_image(src_file, dst_file, settings)
    simple = get_exif_tags(get_exif_data(dst_file))
    assert simple['iso'] == 50

    settings['copy_exif_data'] = False
    generate_image(src_file, dst_file, settings)
    simple = get_exif_tags(get_exif_data(dst_file))
    assert not simple
示例#25
0
文件: test_image.py 项目: matze/sigal
def test_exif_copy(tmpdir):
    "Test if EXIF data can transfered copied to the resized image."

    test_image = '11.jpg'
    src_file = os.path.join(CURRENT_DIR, 'sample', 'pictures', 'dir1', 'test1',
                            test_image)
    dst_file = str(tmpdir.join(test_image))

    settings = create_settings(img_size=(300, 400), copy_exif_data=True)
    generate_image(src_file, dst_file, settings)
    simple = get_exif_tags(get_exif_data(dst_file))
    assert simple['iso'] == 50

    settings['copy_exif_data'] = False
    generate_image(src_file, dst_file, settings)
    simple = get_exif_tags(get_exif_data(dst_file))
    assert not simple
示例#26
0
def test_exif_gps(tmpdir):
    """Test reading out correct geo tags"""

    test_image = 'flickr_jerquiaga_2394751088_cc-by-nc.jpg'
    src_file = os.path.join(CURRENT_DIR, 'sample', 'pictures', 'dir1', 'test1',
                            test_image)
    dst_file = str(tmpdir.join(test_image))

    settings = create_settings(img_size=(400, 300), copy_exif_data=True)
    generate_image(src_file, dst_file, settings)
    simple = get_exif_tags(get_exif_data(dst_file))
    assert 'gps' in simple

    lat = 34.029167
    lon = -116.144167

    assert abs(simple['gps']['lat'] - lat) < 0.0001
    assert abs(simple['gps']['lon'] - lon) < 0.0001
示例#27
0
文件: test_image.py 项目: matze/sigal
def test_exif_gps(tmpdir):
    """Test reading out correct geo tags"""

    test_image = 'flickr_jerquiaga_2394751088_cc-by-nc.jpg'
    src_file = os.path.join(CURRENT_DIR, 'sample', 'pictures', 'dir1', 'test1',
                            test_image)
    dst_file = str(tmpdir.join(test_image))

    settings = create_settings(img_size=(400, 300), copy_exif_data=True)
    generate_image(src_file, dst_file, settings)
    simple = get_exif_tags(get_exif_data(dst_file))
    assert 'gps' in simple

    lat = 34.029167
    lon = -116.144167

    assert abs(simple['gps']['lat'] - lat) < 0.0001
    assert abs(simple['gps']['lon'] - lon) < 0.0001
示例#28
0
def test_second_pass_video(mock_generate_video_pass, fmt, tmpdir):
    """Video should be run through ffmpeg."""
    base, ext = os.path.splitext(TEST_VIDEO)
    dstfile = str(tmpdir.join(base + '.' + fmt))
    settings_1 = '-c:v libvpx-vp9 -b:v 0 -crf 30 -pass 1 -an -f null dev/null'
    settings_2 = '-c:v libvpx-vp9 -b:v 0 -crf 30 -pass 2 -f {}'.format(fmt)
    settings_opts = {
        'video_size': (100, 50),
        'video_format': fmt,
        fmt + '_options': settings_1.split(" "),
        fmt + '_options_second_pass': settings_2.split(" ")
    }

    settings = create_settings(**settings_opts)
    generate_video(SRCFILE, dstfile, settings)
    call_args_list = mock_generate_video_pass.call_args_list
    # The method is called twice
    assert len(call_args_list) == 2
    # The first call to the method should have 3 args, without the outname
    args, kwargs = call_args_list[0]
    assert len(args) == 3
    # The second call to the method should have 4 args, with the outname
    args, kwargs = call_args_list[1]
    assert len(args) == 4
示例#29
0
def test_resize_image_portrait(tmpdir):
    """Test that the area is the same regardless of aspect ratio."""
    size = (300, 200)
    settings = create_settings(img_size=size)

    portrait_image = 'm57_the_ring_nebula-587px.jpg'
    portrait_src = os.path.join(CURRENT_DIR, 'sample', 'pictures', 'dir2', portrait_image)
    portrait_dst = str(tmpdir.join(portrait_image))

    generate_image(portrait_src, portrait_dst, settings)
    im = Image.open(portrait_dst)

    # In the default mode, PILKit resizes in a way to never make an image
    # smaller than either of the lengths, the other is scaled accordingly.
    # Hence we test that the shorter side has the smallest length.
    assert im.size[0] == 200

    landscape_image = 'exo20101028-b-full.jpg'
    landscape_src = os.path.join(CURRENT_DIR, 'sample', 'pictures', 'dir2', landscape_image)
    landscape_dst = str(tmpdir.join(landscape_image))

    generate_image(landscape_src, landscape_dst, settings)
    im = Image.open(landscape_dst)
    assert im.size[1] == 200
示例#30
0
文件: test_image.py 项目: matze/sigal
def test_resize_image_portrait(tmpdir):
    """Test that the area is the same regardless of aspect ratio."""
    size = (300, 200)
    settings = create_settings(img_size=size)

    portrait_image = 'm57_the_ring_nebula-587px.jpg'
    portrait_src = os.path.join(CURRENT_DIR, 'sample', 'pictures', 'dir2', portrait_image)
    portrait_dst = str(tmpdir.join(portrait_image))

    generate_image(portrait_src, portrait_dst, settings)
    im = Image.open(portrait_dst)

    # In the default mode, PILKit resizes in a way to never make an image
    # smaller than either of the lengths, the other is scaled accordingly.
    # Hence we test that the shorter side has the smallest length.
    assert im.size[0] == 200

    landscape_image = 'exo20101028-b-full.jpg'
    landscape_src = os.path.join(CURRENT_DIR, 'sample', 'pictures', 'dir2', landscape_image)
    landscape_dst = str(tmpdir.join(landscape_image))

    generate_image(landscape_src, landscape_dst, settings)
    im = Image.open(landscape_dst)
    assert im.size[1] == 200
示例#31
0
    __tablename__ = "ImageMetadata"


class Images(db.Model):
    __tablename__ = "Images"
    image_info = relationship(
        ImageInformation,
        primaryjoin='foreign(Images.id) == remote(ImageInformation.imageid)')
    image_meta = relationship(
        ImageMetadata,
        primaryjoin='foreign(Images.id) == remote(ImageMetadata.imageid)')
    r_album = relationship(
        Albums, primaryjoin='foreign(Images.album) == remote(Albums.id)')


settings = create_settings(html_language="FR_fr", show_map=False)


class Theme:
    def __init__(self):
        self.url = "/static"


class Album:
    def __init__(self, name):
        self.name = name
        self.title = name
        self.url = "/albums/" + str(id)
        self.author = "Thomas Coquelin"
        self.description = "5 stars"
        self.medias = []