Browse Source

Add test and docs

pull/449/head
Simon Conseil 4 years ago
parent
commit
e18ece5ae9
  1. 3
      docs/image_information.rst
  2. 18
      sigal/gallery.py
  3. 1
      tests/sample/pictures/video/example video.md
  4. 16
      tests/test_video.py

3
docs/image_information.rst

@ -6,6 +6,7 @@ Additional information on an image can be given in a file using the `markdown`_
syntax, named ``<imagename>.md`` (example: ``IMG_5206.md``)::
Title: My awesome photo
Date: 2020-01-01T09:00:00
And a description with *Markdown* syntax.
@ -13,6 +14,8 @@ EXIF data is directly extracted, see :ref:`simple-exif-data`. Some meta-data
keys are used by Sigal to get the useful informations on the gallery:
- *Title*: the image title.
- *Date*: the file date, useful when it cannot be read from the EXIF metadata,
e.g. for videos and some image formats.
Any additional meta-data is available in the templates. For instance::

18
sigal/gallery.py

@ -307,16 +307,16 @@ class Video(Media):
@cached_property
def date(self):
"""The date from the Date metadata if available, or from the file date."""
if 'date' in self.meta:
try:
self.logger.debug("Reading date from image metadata : %s",
self.src_filename)
return datetime.fromisoformat(self.meta['date'][0])
except Exception:
self.logger.debug("Reading date from image metadata failed : %s",
self.src_filename)
# If no date is found in the metadata, return the file date.
assetdate = datetime.now()
try:
assetdate = datetime.fromisoformat(self.meta['date'][0])
except:
self.logger.debug(
"Either self.meta.data was not set, or was in an incorrect format : %s",
self.src_filename)
assetdate = self._get_file_date()
return assetdate
return self._get_file_date()
class Album:

1
tests/sample/pictures/video/example video.md

@ -0,0 +1 @@
Date: 2020-01-01T09:00:00

16
tests/test_video.py

@ -1,4 +1,5 @@
import os
from datetime import datetime
from unittest.mock import patch
import pytest
@ -48,6 +49,21 @@ def test_process_video(tmpdir):
assert process_video(video) == Status.FAILURE
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)
@pytest.mark.parametrize("fmt", ['webm', 'mp4'])
def test_generate_video_fit_height(tmpdir, fmt):
"""largest fitting dimension is height"""

Loading…
Cancel
Save