Added tests, fixed bug in export_db
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
import pytest
|
||||
|
||||
TEST_HEIC = "tests/test-images/IMG_3092.heic"
|
||||
TEST_RAW = "tests/test-images/DSC03584.dng"
|
||||
|
||||
|
||||
def test_copy_file_valid():
|
||||
# copy file with valid src, dest
|
||||
@@ -23,8 +25,8 @@ def test_copy_file_invalid():
|
||||
from osxphotos.fileutil import FileUtil
|
||||
|
||||
temp_dir = tempfile.TemporaryDirectory(prefix="osxphotos_")
|
||||
src = "tests/test-images/wedding_DOES_NOT_EXIST.jpg"
|
||||
with pytest.raises(Exception) as e:
|
||||
src = "tests/test-images/wedding_DOES_NOT_EXIST.jpg"
|
||||
assert FileUtil.copy(src, temp_dir.name)
|
||||
assert e.type == FileNotFoundError
|
||||
|
||||
@@ -69,14 +71,31 @@ def test_unlink_file():
|
||||
FileUtil.unlink(dest)
|
||||
assert not os.path.isfile(dest)
|
||||
|
||||
|
||||
def test_convert_to_jpeg():
|
||||
""" test convert_to_jpeg """
|
||||
import pathlib
|
||||
import tempfile
|
||||
from osxphotos.fileutil import FileUtil
|
||||
|
||||
temp_dir = tempfile.TemporaryDirectory(prefix="osxphotos_")
|
||||
temp_dir = tempfile.TemporaryDirectory(prefix="osxphotos_")
|
||||
with temp_dir:
|
||||
imgfile = pathlib.Path(TEST_HEIC)
|
||||
outfile = pathlib.Path(temp_dir.name) / f"{imgfile.stem}.jpeg"
|
||||
assert FileUtil.convert_to_jpeg(imgfile, outfile)
|
||||
assert outfile.is_file()
|
||||
assert outfile.is_file()
|
||||
|
||||
|
||||
def test_convert_to_jpeg_quality():
|
||||
""" test convert_to_jpeg with compression_quality """
|
||||
import pathlib
|
||||
import tempfile
|
||||
from osxphotos.fileutil import FileUtil
|
||||
|
||||
temp_dir = tempfile.TemporaryDirectory(prefix="osxphotos_")
|
||||
with temp_dir:
|
||||
imgfile = pathlib.Path(TEST_RAW)
|
||||
outfile = pathlib.Path(temp_dir.name) / f"{imgfile.stem}.jpeg"
|
||||
assert FileUtil.convert_to_jpeg(imgfile, outfile, compression_quality=0.1)
|
||||
assert outfile.is_file()
|
||||
assert outfile.stat().st_size < 1000000
|
||||
|
||||
Reference in New Issue
Block a user