Skip to content

Commit

Permalink
100% test coverage for Folder
Browse files Browse the repository at this point in the history
  • Loading branch information
RhetTbull committed Sep 14, 2020
1 parent c3dc56d commit a4c1b32
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 6 deletions.
Binary file modified photoscript.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion photoscript/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
""" version info """

__version__ = "0.0.17"
__version__ = "0.0.18"
18 changes: 13 additions & 5 deletions photoscript/photoscript.applescript
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

-- Naming scheme is _classname_methodname

(* max number of times to retry in case of error *)
(* max number of times to retry in case of error
some AppleScript calls appear to be flaky and don't always execute
so retry those up to MAX_RETRY if not succesful
*)
property MAX_RETRY : 5
property WAIT_FOR_PHOTOS : 300

Expand Down Expand Up @@ -707,7 +710,6 @@ on _folder_get_folder_for_id(_id)
_photoslibrary_waitforphotos(WAIT_FOR_PHOTOS)
set albums_folders to _photoslibrary_get_albums_folders()
set _folders to _folders of albums_folders
_photoslibrary_waitforphotos(WAIT_FOR_PHOTOS)
tell application "Photos"
repeat with _folder in _folders
set _folder_id to id of _folder
Expand Down Expand Up @@ -756,9 +758,15 @@ on _folder_set_name(_id, _title)
(* set name or title of folder *)
set folder_ to _folder_get_folder_for_id(_id)
_photoslibrary_waitforphotos(WAIT_FOR_PHOTOS)
tell application "Photos"
set name of folder_ to _title
end tell
set count_ to 0
repeat while count_ < MAX_RETRY
tell application "Photos"
set name of folder_ to _title
if name of folder_ = _title then
return _title
end if
end tell
end repeat
end _folder_set_name

on _folder_parent(_id)
Expand Down
1 change: 1 addition & 0 deletions tests/photoscript_config_catalina.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
FOLDER_1_UUID_OSXPHOTOS = "1FB9BF4B-3CF5-45DE-B4E7-C92047341196"
FOLDER_1_NAME = "Folder1"
FOLDER_1_LEN = 1
FOLDER_1_SUBFOLDERS = ["SubFolder1"]
FOLDER_2_UUID = "9BC83BEA-7598-4846-BBD7-AB14BE771825/L0/020"
FOLDER_2_NAME = "SubFolder1"
FOLDER_2_PATH_STR = "Folder1/SubFolder1"
Expand Down
60 changes: 60 additions & 0 deletions tests/test_3_folder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
""" Test Folder class """

from tests.photoscript_config_catalina import ALBUM_1_NAME, FOLDER_1_SUBFOLDERS
import pytest
from applescript import AppleScript
from tests.conftest import photoslib, suspend_capture, get_os_version
Expand All @@ -14,6 +15,7 @@
FOLDER_1_NAME,
FOLDER_1_UUID,
FOLDER_1_UUID_OSXPHOTOS,
FOLDER_1_SUBFOLDERS,
FOLDER_2_LEN,
FOLDER_2_NAME,
FOLDER_2_UUID,
Expand Down Expand Up @@ -153,11 +155,69 @@ def test_folder_path(photoslib):
assert isinstance(p, photoscript.Folder)
assert p.name == FOLDER_2_PATH[i]


def test_folder_albums(photoslib):
folder = photoslib.folder(FOLDER_3_NAME)
albums = folder.albums
assert sorted(album.name for album in albums) == sorted(FOLDER_3_ALBUMS)


def test_folder_album(photoslib):
folder = photoslib.folder(FOLDER_3_NAME)
album = folder.album(ALBUM_1_NAME)
assert album.name == ALBUM_1_NAME


def test_folder_album_bad_name(photoslib):
folder = photoslib.folder(FOLDER_3_NAME)
album = folder.album("FOOBAR")
assert album is None


def test_folder_subfolders(photoslib):
folder = photoslib.folder(FOLDER_1_NAME)
subfolders = folder.subfolders
assert sorted(f.name for f in subfolders) == sorted(FOLDER_1_SUBFOLDERS)


def test_folder_subfolders_none(photoslib):
folder = photoslib.folder(FOLDER_2_NAME, top_level=False)
subfolders = folder.subfolders
assert subfolders == []


def test_folder_folder(photoslib):
folder = photoslib.folder(FOLDER_1_NAME)
subfolder = folder.folder(FOLDER_2_NAME)
assert subfolder.name == FOLDER_2_NAME


def test_folder_folder_none(photoslib):
folder = photoslib.folder(FOLDER_1_NAME)
subfolder = folder.folder("FOOBAR")
assert subfolder is None


def test_folder_create_album(photoslib):
import photoscript

folder = photoslib.folder(FOLDER_1_NAME)
album = folder.create_album("New Album")
assert isinstance(album, photoscript.Album)
assert album.name == "New Album"
assert album.parent.id == folder.id


def test_folder_create_folder(photoslib):
import photoscript

folder = photoslib.folder(FOLDER_1_NAME)
subfolder = folder.create_folder("New Folder")
assert isinstance(subfolder, photoscript.Folder)
assert subfolder.name == "New Folder"
assert subfolder.parent.id == folder.id


def test_len_1(photoslib):
""" test Album.__len__ """
folder = photoslib.folder(FOLDER_1_NAME)
Expand Down

0 comments on commit a4c1b32

Please sign in to comment.