Refactored UTI utils to get ready for Monterey
This commit is contained in:
@@ -44,7 +44,7 @@ def generate_sidecars(dbname, uuid_dict):
|
||||
file.write(xmp)
|
||||
|
||||
# with extension
|
||||
ext = osxphotos.utils.get_preferred_uti_extension(photo.uti)
|
||||
ext = osxphotos.uti.get_preferred_uti_extension(photo.uti)
|
||||
ext = "jpg" if ext == "jpeg" else ext
|
||||
sidecar = str(pathlib.Path(SIDECAR_DIR) / f"{uuid}_ext.xmp")
|
||||
xmp = photo._xmp_sidecar(extension=ext)
|
||||
|
||||
64
tests/test_uti.py
Normal file
64
tests/test_uti.py
Normal file
@@ -0,0 +1,64 @@
|
||||
""" test uti.py """
|
||||
|
||||
import pytest
|
||||
|
||||
import osxphotos.uti
|
||||
from osxphotos.uti import (
|
||||
_get_uti_from_mdls,
|
||||
get_preferred_uti_extension,
|
||||
get_uti_for_extension,
|
||||
)
|
||||
|
||||
EXT_DICT = {"heic": "public.heic", "jpg": "public.jpeg"}
|
||||
UTI_DICT = {"public.heic": "heic", "public.jpeg": "jpeg"}
|
||||
|
||||
|
||||
def test_get_preferred_uti_extension():
|
||||
"""test get_preferred_uti_extension"""
|
||||
for uti in UTI_DICT:
|
||||
assert get_preferred_uti_extension(uti) == UTI_DICT[uti]
|
||||
|
||||
|
||||
def test_get_uti_for_extension():
|
||||
"""get get_uti_for_extension"""
|
||||
for ext in EXT_DICT:
|
||||
assert get_uti_for_extension(ext) == EXT_DICT[ext]
|
||||
|
||||
|
||||
def test_get_preferred_uti_extension_no_obj():
|
||||
"""test get_preferred_uti_extension when running on macOS >= 12"""
|
||||
OLD_VER = osxphotos.uti.OS_VER
|
||||
osxphotos.uti.OS_VER = 12
|
||||
for uti in UTI_DICT:
|
||||
assert get_preferred_uti_extension(uti) == UTI_DICT[uti]
|
||||
osxphotos.uti.OS_VER = OLD_VER
|
||||
|
||||
|
||||
def test_get_uti_for_extension_no_obj():
|
||||
"""get get_uti_for_extension when running on macOS >= 12"""
|
||||
OLD_VER = osxphotos.uti.OS_VER
|
||||
osxphotos.uti.OS_VER = 12
|
||||
for ext in EXT_DICT:
|
||||
assert get_uti_for_extension(ext) == EXT_DICT[ext]
|
||||
osxphotos.uti.OS_VER = OLD_VER
|
||||
|
||||
|
||||
def test_get_uti_from_mdls():
|
||||
"""get _get_uti_from_mdls"""
|
||||
for ext in EXT_DICT:
|
||||
assert _get_uti_from_mdls(ext) == EXT_DICT[ext]
|
||||
|
||||
|
||||
def test_get_uti_not_in_dict():
|
||||
"""get UTI when objc is not available and it's not in the EXT_UTI_DICT"""
|
||||
# monkey patch the EXT_UTI_DICT
|
||||
OLD_VER = osxphotos.uti.OS_VER
|
||||
osxphotos.uti.OS_VER = 12
|
||||
osxphotos.uti.EXT_UTI_DICT = {}
|
||||
osxphotos.uti.UTI_EXT_DICT = {}
|
||||
for ext in EXT_DICT:
|
||||
assert get_uti_for_extension(ext) == EXT_DICT[ext]
|
||||
osxphotos.uti.OS_VER = OLD_VER
|
||||
|
||||
# re-initialize the cached dicts
|
||||
osxphotos.uti._load_uti_dict()
|
||||
@@ -54,14 +54,6 @@ def test_db_is_locked_unlocked():
|
||||
|
||||
assert not osxphotos.utils._db_is_locked(DB_UNLOCKED_10_15)
|
||||
|
||||
|
||||
def test_get_preferred_uti_extension():
|
||||
from osxphotos.utils import get_preferred_uti_extension
|
||||
|
||||
for uti, extension in UTI_DICT.items():
|
||||
assert get_preferred_uti_extension(uti) == extension
|
||||
|
||||
|
||||
def test_findfiles():
|
||||
import tempfile
|
||||
import os.path
|
||||
|
||||
Reference in New Issue
Block a user