ordigi/tests/test_exiftool.py

189 lines
5.1 KiB
Python
Raw Permalink Normal View History

2021-08-08 11:35:47 +02:00
import json
import pytest
2021-08-13 21:11:24 +02:00
import ordigi.exiftool
from ordigi.exiftool import get_exiftool_path
2021-08-08 11:35:47 +02:00
TEST_FILE_ONE_KEYWORD = "samples/images/wedding.jpg"
TEST_FILE_BAD_IMAGE = "samples/images/badimage.jpeg"
TEST_FILE_WARNING = "samples/images/exiftool_warning.heic"
TEST_FILE_MULTI_KEYWORD = "samples/images/Tulips.jpg"
TEST_MULTI_KEYWORDS = [
"Top Shot",
"flowers",
"flower",
"design",
"Stock Photography",
"vibrant",
"plastic",
"Digital Nomad",
"close up",
"stock photo",
"outdoor",
"wedding",
"Reiseblogger",
"fake",
"colorful",
"Indoor",
"display",
"photography",
]
PHOTOS_DB = "tests/Test-10.15.4.photoslibrary"
EXIF_UUID = {
"6191423D-8DB8-4D4C-92BE-9BBBA308AAC4": {
"EXIF:DateTimeOriginal": "2019:07:04 16:24:01",
"EXIF:LensModel": "XF18-55mmF2.8-4 R LM OIS",
"IPTC:Keywords": [
"Digital Nomad",
"Indoor",
"Reiseblogger",
"Stock Photography",
"Top Shot",
"close up",
"colorful",
"design",
"display",
"fake",
"flower",
"outdoor",
"photography",
"plastic",
"stock photo",
"vibrant",
],
"IPTC:DocumentNotes": "https://flickr.com/e/l7FkSm4f2lQkSV3CG6xlv8Sde5uF3gVu4Hf0Qk11AnU%3D",
},
"E9BC5C36-7CD1-40A1-A72B-8B8FAC227D51": {
"EXIF:Make": "NIKON CORPORATION",
"EXIF:Model": "NIKON D810",
"IPTC:DateCreated": "2019:04:15",
},
}
EXIF_UUID_NO_GROUPS = {
"6191423D-8DB8-4D4C-92BE-9BBBA308AAC4": {
"DateTimeOriginal": "2019:07:04 16:24:01",
"LensModel": "XF18-55mmF2.8-4 R LM OIS",
"Keywords": [
"Digital Nomad",
"Indoor",
"Reiseblogger",
"Stock Photography",
"Top Shot",
"close up",
"colorful",
"design",
"display",
"fake",
"flower",
"outdoor",
"photography",
"plastic",
"stock photo",
"vibrant",
],
"DocumentNotes": "https://flickr.com/e/l7FkSm4f2lQkSV3CG6xlv8Sde5uF3gVu4Hf0Qk11AnU%3D",
},
"E9BC5C36-7CD1-40A1-A72B-8B8FAC227D51": {
"Make": "NIKON CORPORATION",
"Model": "NIKON D810",
"DateCreated": "2019:04:15",
},
}
EXIF_UUID_NONE = ["A1DD1F98-2ECD-431F-9AC9-5AFEFE2D3A5C"]
try:
exiftool = get_exiftool_path()
except:
exiftool = None
if exiftool is None:
pytest.skip("could not find exiftool in path", allow_module_level=True)
def test_get_exiftool_path():
2021-08-13 21:11:24 +02:00
exiftool = ordigi.exiftool.get_exiftool_path()
2021-08-08 11:35:47 +02:00
assert exiftool is not None
def test_version():
2021-08-13 21:11:24 +02:00
exif = ordigi.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD)
2021-08-08 11:35:47 +02:00
assert exif.version is not None
assert isinstance(exif.version, str)
def test_read():
2021-08-13 21:11:24 +02:00
exif = ordigi.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD)
2021-08-08 11:35:47 +02:00
assert exif.data["File:MIMEType"] == "image/jpeg"
assert exif.data["EXIF:ISO"] == 160
assert exif.data["IPTC:Keywords"] == "wedding"
def test_singleton():
2021-08-13 21:11:24 +02:00
exif1 = ordigi.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD)
exif2 = ordigi.exiftool.ExifTool(TEST_FILE_MULTI_KEYWORD)
2021-08-08 11:35:47 +02:00
assert exif1._process.pid == exif2._process.pid
def test_pid():
2021-08-13 21:11:24 +02:00
exif1 = ordigi.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD)
2021-08-08 11:35:47 +02:00
assert exif1.pid == exif1._process.pid
def test_exiftoolproc_process():
2021-08-13 21:11:24 +02:00
exif1 = ordigi.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD)
2021-08-08 11:35:47 +02:00
assert exif1._exiftoolproc.process is not None
def test_exiftoolproc_exiftool():
2021-08-13 21:11:24 +02:00
exif1 = ordigi.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD)
assert exif1._exiftoolproc.exiftool == ordigi.exiftool.get_exiftool_path()
2021-08-08 11:35:47 +02:00
def test_as_dict():
2021-08-13 21:11:24 +02:00
exif1 = ordigi.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD)
2021-08-08 11:35:47 +02:00
exifdata = exif1.asdict()
assert exifdata["XMP:TagsList"] == "wedding"
def test_as_dict_normalized():
2021-08-13 21:11:24 +02:00
exif1 = ordigi.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD)
2021-08-08 11:35:47 +02:00
exifdata = exif1.asdict(normalized=True)
assert exifdata["xmp:tagslist"] == "wedding"
assert "XMP:TagsList" not in exifdata
def test_as_dict_no_tag_groups():
2021-08-13 21:11:24 +02:00
exif1 = ordigi.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD)
2021-08-08 11:35:47 +02:00
exifdata = exif1.asdict(tag_groups=False)
assert exifdata["TagsList"] == "wedding"
def test_json():
2021-08-13 21:11:24 +02:00
exif1 = ordigi.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD)
2021-08-08 11:35:47 +02:00
exifdata = json.loads(exif1.json())
assert exifdata[0]["XMP:TagsList"] == "wedding"
def test_str():
2021-08-13 21:11:24 +02:00
exif1 = ordigi.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD)
2021-08-08 11:35:47 +02:00
assert "file: " in str(exif1)
assert "exiftool: " in str(exif1)
def test_exiftool_terminate():
""" Test that exiftool process is terminated when exiftool.terminate() is called """
2021-08-13 21:11:24 +02:00
exif1 = ordigi.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD)
2021-08-08 11:35:47 +02:00
2021-08-13 21:11:24 +02:00
assert ordigi.exiftool.exiftool_is_running()
2021-08-08 11:35:47 +02:00
2021-08-13 21:11:24 +02:00
ordigi.exiftool.terminate_exiftool()
2021-08-08 11:35:47 +02:00
2021-08-13 21:11:24 +02:00
assert not ordigi.exiftool.exiftool_is_running()
2021-08-08 11:35:47 +02:00
# verify we can create a new instance after termination
2021-08-13 21:11:24 +02:00
exif2 = ordigi.exiftool.ExifTool(TEST_FILE_ONE_KEYWORD)
2021-08-08 11:35:47 +02:00
assert exif2.asdict()["IPTC:Keywords"] == "wedding"