Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_media_iptc_override(settings):
img_with_md = Image('2.jpg', 'iptcTest', settings)
assert img_with_md.title == "Markdown title beats iptc"
# Markdown parsing adds formatting. Let's just focus on content
assert "Markdown description beats iptc" in img_with_md.description
img_no_md = Image('1.jpg', 'iptcTest', settings)
assert img_no_md.title == 'Haemostratulus clouds over Canberra - ' + \
'2005-12-28 at 03-25-07'
assert img_no_md.description == \
'"Haemo" because they look like haemoglobin ' + \
'cells and "stratulus" because I can\'t work out whether ' + \
'they\'re Stratus or Cumulus clouds.\nWe\'re driving down ' + \
'the main drag in Canberra so it\'s Parliament House that ' + \
'you can see at the end of the road.'
def test_media_iptc_override(settings):
img_with_md = Image('2.jpg', 'iptcTest', settings)
assert img_with_md.title == "Markdown title beats iptc"
# Markdown parsing adds formatting. Let's just focus on content
assert "Markdown description beats iptc" in img_with_md.description
img_no_md = Image('1.jpg', 'iptcTest', settings)
assert img_no_md.title == 'Haemostratulus clouds over Canberra - ' + \
'2005-12-28 at 03-25-07'
assert img_no_md.description == \
'"Haemo" because they look like haemoglobin ' + \
'cells and "stratulus" because I can\'t work out whether ' + \
'they\'re Stratus or Cumulus clouds.\nWe\'re driving down ' + \
'the main drag in Canberra so it\'s Parliament House that ' + \
'you can see at the end of the road.'
def test_image(settings, tmpdir):
settings['destination'] = str(tmpdir)
settings['datetime_format'] = '%d/%m/%Y'
m = Image('11.jpg', 'dir1/test1', settings)
assert m.date == datetime.datetime(2006, 1, 22, 10, 32, 42)
assert m.exif['datetime'] == '22/01/2006'
os.makedirs(join(settings['destination'], 'dir1', 'test1', 'thumbnails'))
assert m.thumbnail == join('thumbnails', '11.tn.jpg')
assert os.path.isfile(m.thumb_path)
assert m.big is None
settings['keep_orig'] = True
settings['destination'] = str(tmpdir)
m = Image('11.jpg', 'dir1/test1', settings)
assert m.big == 'original/11.jpg'
m = Video('example video.ogv', 'video', settings)
assert m.filename == 'example video.webm'
assert m.big_url == 'original/example%20video.ogv'
assert os.path.isfile(join(settings['destination'], m.path, m.big))
settings['use_orig'] = True
m = Image('21.jpg', 'dir1/test2', settings)
assert m.big == '21.jpg'
def test_media_orig(settings, tmpdir):
settings['keep_orig'] = False
m = Media('11.jpg', 'dir1/test1', settings)
assert m.big is None
settings['keep_orig'] = True
settings['destination'] = str(tmpdir)
m = Image('11.jpg', 'dir1/test1', settings)
assert m.big == 'original/11.jpg'
m = Video('example video.ogv', 'video', settings)
assert m.filename == 'example video.webm'
assert m.big_url == 'original/example%20video.ogv'
assert os.path.isfile(join(settings['destination'], m.path, m.big))
settings['use_orig'] = True
m = Image('21.jpg', 'dir1/test2', settings)
assert m.big == '21.jpg'
def _get_metadata(self):
super(Image, self)._get_metadata()
# If a title or description hasn't been obtained by other means, look
# for the information in IPTC fields
if self.title and self.description:
# Nothing to do - we already have title and description
return
try:
iptc_data = get_iptc_data(self.src_path)
except Exception as e:
self.logger.warning('Could not read IPTC data from %s: %s',
self.src_path, e)
else:
if not self.title and iptc_data.get('title'):
self.title = iptc_data['title']
if not self.description and iptc_data.get('description'):
self.description = iptc_data['description']
# optionally add index.html to the URLs
self.url_ext = self.output_file if settings['index_in_url'] else ''
self.index_url = url_from_path(os.path.relpath(
settings['destination'], self.dst_path)) + '/' + self.url_ext
#: List of all medias in the album (:class:`~sigal.gallery.Image` and
#: :class:`~sigal.gallery.Video`).
self.medias = medias = []
self.medias_count = defaultdict(int)
for f in filenames:
ext = splitext(f)[1]
if ext.lower() in settings['img_extensions']:
media = Image(f, self.path, settings)
elif ext.lower() in settings['video_extensions']:
media = Video(f, self.path, settings)
else:
continue
self.medias_count[media.type] += 1
medias.append(media)
signals.album_initialized.send(self)