exiv2/tests/bugfixes/github/test_issue_1893.py
David Houlder b385f2db1c
Canon cr3 previews (#1958)
* Extract THMB and PRVW images from Canon CR3 file

* Added test for Canon CR3 preview extraction.

Added test data Canon-R6-pruned.CR3 (first 492016 bytes of https://raw.pixls.us/getfile.php/4659/nice/Canon%20-%20Canon%20EOS%20R6%20-%203:2.CR3).

See https://github.com/Exiv2/exiv2/issues/1893

* Fixed format specifier

* Update src/bmffimage.cpp

Co-authored-by: Miloš Komarčević <4973094+kmilos@users.noreply.github.com>

* Update src/bmffimage.cpp

Co-authored-by: Miloš Komarčević <4973094+kmilos@users.noreply.github.com>

* retrigger checks

Co-authored-by: Miloš Komarčević <4973094+kmilos@users.noreply.github.com>
2021-10-17 22:28:05 +01:00

66 lines
2.0 KiB
Python

# -*- coding: utf-8 -*-
import system_tests
import unittest
from tempfile import TemporaryDirectory
import shutil
import hashlib
import os
# test needs system_tests.BT.vv['enable_bmff']=1
bSkip=system_tests.BT.verbose_version().get('enable_bmff')!='1'
if bSkip:
raise unittest.SkipTest('*** requires enable_bmff=1 ***')
file_basename = 'Canon-R6-pruned.CR3'
previews_expected = (
('Canon-R6-pruned-preview1.jpg', 'a182ef12ac883309b4dfc66b87eac1891286d3ae'),
('Canon-R6-pruned-preview2.jpg', '524a07f1797854e349ae140e2682ba37147fa6b2')
)
class issue_1893_cr3_preview(metaclass=system_tests.CaseMeta):
"""
Check that THMB and PRVW images are extracted from Canon CR3 files
"""
url = "https://github.com/Exiv2/exiv2/issues/1893"
filename = "$data_path/" + file_basename
commands=[] # see setUp()
if bSkip:
retval=[]
stdin=[]
stderr=[]
stdout=[]
print("*** test skipped. requires enable_bmff=1***")
else:
retval = [ 0, 0]
stderr = [ "",""]
stdin = [ "", ""]
stdout = ["""Preview 1: image/jpeg, 160x120 pixels, 16005 bytes
Preview 2: image/jpeg, 1620x1080 pixels, 389450 bytes
""", ""]
def post_tests_hook(self):
if self.commands:
for j, sha1 in previews_expected:
p = os.path.join(self.preview_image_tmp_dir.name, j)
self.assertTrue(os.path.isfile(p))
h = hashlib.sha1(open(p, 'rb').read()).hexdigest()
self.assertEqual(h, sha1)
def setUp(self):
if bSkip:
return
# Avoid polluting the test data directory with extracted previews
self.preview_image_tmp_dir = TemporaryDirectory()
shutil.copy(self.expand_variables(self.filename),
self.preview_image_tmp_dir.name)
p = os.path.join(
self.preview_image_tmp_dir.name,
file_basename)
self.commands = [
self.expand_variables("$exiv2 -pp ") + p,
self.expand_variables("$exiv2 -ep ") + p
]