diff --git a/photoscript/__init__.py b/photoscript/__init__.py index 1c87ec1..7c60d99 100644 --- a/photoscript/__init__.py +++ b/photoscript/__init__.py @@ -308,7 +308,7 @@ def albums(self, top_level=False): album_ids = run_script("photosLibraryAlbumIDs", top_level) return [Album(uuid) for uuid in album_ids] - def create_album(self, name, folder=None): + def create_album(self, name, folder: "Folder" = None) -> "Album": """creates an album Args: @@ -325,14 +325,16 @@ def create_album(self, name, folder=None): if folder is None: album_id = run_script("photosLibraryCreateAlbum", name) else: - album_id = run_script("photosLibraryCreateAlbumAtFolder", name, folder.id) + album_id = run_script( + "photosLibraryCreateAlbumAtFolder", name, folder.idstring + ) - if album_id != 0: + if album_id != kMissingValue: return Album(album_id) else: raise AppleScriptError(f"Could not create album {name}") - def delete_album(self, album): + def delete_album(self, album: "Album"): """deletes album (but does not delete photos in the album) Args: @@ -340,34 +342,56 @@ def delete_album(self, album): """ return run_script("photosLibraryDeleteAlbum", album.id) - def folder(self, *name, uuid=None, top_level=True): + def folder( + self, name: str = None, path: list[str] = None, uuid: str = None, top_level=True + ): """Folder instance by name or uuid Args: - name: name of folder - uuid: id of folder + name: name of folder, e.g. "My Folder" + path: path of folder as list of strings, e.g. ["My Folder", "Subfolder"] + uuid: id of folder, e.g. "F1234567-1234-1234-1234-1234567890AB" top_level: if True, only searches top level folders by name; default is True Returns: Folder object or None if folder could not be found Raises: - ValueError if both name and id passed or neither passed. + ValueError not one of name, path, or uuid is passed - Must pass only name or id but not both. - If more than one folder with same name, returns first one found. + Notes: + Must pass one of path, name, or uuid but not more than one + If more than one folder with same name, returns first one found. """ - if (not name and uuid is None) or (name and uuid is not None): - raise ValueError("Must pass only name or uuid but not both") + if sum(bool(x) for x in [name, path, uuid]) != 1: + raise ValueError( + "Must pass one of name, path, or uuid but not more than one" + ) + + if path: + idstring = run_script("folderGetIDStringFromPath", path) + if idstring != kMissingValue: + return Folder(idstring=idstring) + else: + return None if name: - uuid = run_script("folderIDByName", name[0], top_level) - if uuid != 0: - return Folder(uuid) + idstring = run_script( + "photosLibraryGetFolderIDStringForName", name, top_level + ) + if idstring != kMissingValue: + return Folder(idstring=idstring) + else: + return None + + if uuid: + idstring = run_script( + "photosLibraryGetFolderIDStringForID", uuid, top_level + ) + if idstring != kMissingValue: + return Folder(idstring=idstring) else: return None - else: - return Folder(uuid) def folder_by_path(self, folder_path): """Return folder in the library by path @@ -389,7 +413,7 @@ def folders(self, top_level=True): folder_ids = run_script("photosLibraryFolderIDs", top_level) return [Folder(uuid) for uuid in folder_ids] - def create_folder(self, name, folder=None): + def create_folder(self, name, folder: "Folder" = None) -> "Folder": """creates a folder Args: @@ -406,9 +430,11 @@ def create_folder(self, name, folder=None): if folder is None: folder_id = run_script("photosLibraryCreateFolder", name) else: - folder_id = run_script("photosLibraryCreateFolderAtFolder", name, folder.id) + folder_id = run_script( + "photosLibraryCreateFolderAtFolder", name, folder.idstring + ) - if folder_id != 0: + if folder_id != kMissingValue: return Folder(folder_id) else: raise AppleScriptError(f"Could not create folder {name}") @@ -474,17 +500,18 @@ def make_album_folders(self, album_name, folder_path): album = folder.create_album(album_name) return album - def delete_folder(self, folder): + def delete_folder(self, folder: "Folder"): """Deletes folder Args: folder: a Folder object for folder to delete """ - return run_script("photosLibraryDeleteFolder", folder.id) + return run_script("photosLibraryDeleteFolder", folder.idstring) def __len__(self): return run_script("photosLibraryCount") + # TODO: add a temp_album() method that creates a temporary album def _temp_album_name(self): """get a temporary album name that doesn't clash with album in the library""" temp_name = self._temp_name() @@ -783,12 +810,16 @@ def __len__(self): class Folder: def __init__( self, - path: list[str] | None = None, uuid: str | None = None, + path: list[str] | None = None, idstring: str | None = None, ): """Create a Folder object; only one of path, uuid, or idstring should be specified + The preferred method is to use the path argument or idstring to specify the folder + as this is much faster than using uuid. The uuid argument is listed first for + backwards compatibility. + Args: path: list of folder names in descending order from parent to child: ["Folder", "SubFolder"] uuid: uuid of folder: "E0CD4B6C-CB43-46A6-B8A3-67D1FB4D0F3D/L0/020" or "E0CD4B6C-CB43-46A6-B8A3-67D1FB4D0F3D" @@ -811,9 +842,17 @@ def __init__( # if initialized with path or uuid, need to initialize idstring if self._path is not None: self._idstring = run_script("folderGetIDStringFromPath", self._path) + if self._idstring == kMissingValue: + raise ValueError(f"Folder at path {self._path} does not exist") elif self._id is not None: # if uuid was passed, _id will have been initialized above - self._idstring = run_script("photosLibraryGetFolderIDStringForID", self._id) + # second argument is False so search is not limited to top-level folders + self._idstring = run_script("photosLibraryGetFolderIDStringForID", self._id, False) + if self._idstring == kMissingValue: + raise ValueError(f"Folder id {self._id} does not exist") + + if not run_script("folderExists", self._idstring): + raise ValueError(f"Folder {self._idstring} does not exist") @property def idstring(self) -> str: @@ -866,18 +905,19 @@ def title(self, title): @property def parent_id(self): """parent container id""" - return run_script("folderParent", self._idstring) + parent_id = run_script("folderParent", self._idstring) + return parent_id if parent_id != kMissingValue else None # TODO: if no parent should return a "My Albums" object that contains all top-level folders/albums? @property def parent(self): """Return parent Folder object""" - # ZZZ - parent_id = self.parent_id - if parent_id != 0: - return Folder(parent_id) - else: - return None + parent_idstring = self.parent_id + return ( + Folder(idstring=parent_idstring) + if parent_idstring != kMissingValue + else None + ) def path_str(self, delim="/"): """Return internal library path to folder as string. @@ -892,7 +932,7 @@ def path_str(self, delim="/"): if len(delim) > 1: raise ValueError("delim must be single character") - return run_script("folderGetPath", self.id, delim) + return run_script("folderGetPath", self._idstring, delim) def path(self): """Return list of Folder objects this folder is contained in. @@ -900,29 +940,26 @@ def path(self): path()[-1] is the immediate parent of this folder. Returns empty list if folder is not contained in another folders. """ - folder_path = run_script("folderPathIDs", self.id) - return [Folder(folder) for folder in folder_path] + folder_path = run_script("folderGetPathFolderIDScript", self._idstring) + return [Folder(idstring=folder) for folder in folder_path] @property def albums(self): """list of Album objects for albums contained in folder""" - album_ids = run_script("folderAlbums", self.id) + album_ids = run_script("folderAlbums", self._idstring) return [Album(uuid) for uuid in album_ids] def album(self, name): """Return Album object contained in this folder for album named name or None if no matching album """ - for album in self.albums: - if album.name == name: - return album - return None + return next((album for album in self.albums if album.name == name), None) @property def subfolders(self): """list of Folder objects for immediate sub-folders contained in folder""" - folder_ids = run_script("folderFolders", self.id) - return [Folder(uuid) for uuid in folder_ids] + folder_idstrings = run_script("folderFolders", self._idstring) + return [Folder(idstring=ids) for ids in folder_idstrings] def folder(self, name): """Folder object for first subfolder folder named name. @@ -933,10 +970,7 @@ def folder(self, name): Returns: Folder object for first subfolder who's name matches name or None if not found """ - for folder in self.subfolders: - if folder.name == name: - return folder - return None + return next((folder for folder in self.subfolders if folder.name == name), None) def create_album(self, name): """Creates an album in this folder diff --git a/photoscript/photoscript.applescript b/photoscript/photoscript.applescript index 76aaec2..ee3a920 100644 --- a/photoscript/photoscript.applescript +++ b/photoscript/photoscript.applescript @@ -265,43 +265,59 @@ on _walkFoldersLookingForID(theFolderID, theFolder, folderString) folderString: the script snippet for the folder Returns: - folderString: the matching script snippet or the current snippet if not found - + record of {folderString: string, foundID: bool} + folderString: the matching script snippet + foundID: true if matching folder found, othwerwise false + Note: This is intended to be called only from photosLibraryGetFolderIDScriptForID The initial folderString should be set to "" *) - set originalFolderScript to folderString + set originalFolderString to folderString tell application "Photos" set subFolders to theFolder's folders repeat with aFolder in subFolders set folderString to "folder id(\"" & (id of aFolder as text) & "\") of " & folderString if id of aFolder is equal to theFolderID then - return folderString + return {folderString:folderString, foundID:true} end if return my _walkFoldersLookingForID(theFolderID, aFolder, folderString) end repeat end tell - return originalFolderScript + return {folderString:originalFolderString, foundID:false} end _walkFoldersLookingForID -on photosLibraryGetFolderIDStringForID(theFolderID) - (* return AppleScript snippet for folder with ID folderID *) - # see https://discussions.apple.com/docs/DOC-250002459 +on photosLibraryGetFolderIDStringForID(theFolderID, topLevel) + (* Return AppleScript snippet for folder with ID folderID + + Args: + folderID: the folder ID to look for + topLevel: boolean, if True, only search top level folders + + Returns: + string containing AppleScript snippet for folder with ID folderID + missing value if not found + *) tell application "Photos" set theFolders to folders repeat with aFolder in theFolders + -- on Catalina+ only top-level folders are returned by Photos set folderString to "folder id(\"" & (id of aFolder as text) & "\")" if id of aFolder is equal to theFolderID then return folderString end if - -- my is required due to scope as this is inside a tell block - -- if my is not used, Photos will look for the function _walkFolders which does not exist in its namespace - set returnValue to my _walkFoldersLookingForID(theFolderID, aFolder, folderString) - if returnValue is not equal to "" then - return returnValue + + if topLevel is false then + -- my is required due to scope as this is inside a tell block + -- if my is not used, Photos will look for the function _walkFolders which does not exist in its namespace + set returnValue to my _walkFoldersLookingForID(theFolderID, aFolder, folderString) + if foundID of returnValue is true then + return folderString of returnValue + end if end if end repeat + -- went through all folders with no match + return missing value end tell end photosLibraryGetFolderIDStringForID @@ -315,7 +331,9 @@ on _walkFoldersLookingForName(theFolderName, theFolder, folderString) folderString: the script snippet for the folder Returns: - folderString: the matching script snippet or the current snippet if not found + record of {folderString: string, foundID: bool} + folderString: the matching script snippet + foundID: true if matching folder found, othwerwise false Note: This is intended to be called only from photosLibraryGetFolderIDStringForName @@ -328,17 +346,27 @@ on _walkFoldersLookingForName(theFolderName, theFolder, folderString) repeat with aFolder in subFolders set folderString to "folder id(\"" & (id of aFolder as text) & "\") of " & folderString if aFolder's name is equal to theFolderName then - return folderString + return {folderString:folderString, foundID:true} end if return my _walkFoldersLookingForName(theFolderName, aFolder, folderString) end repeat end tell - return originalFolderScript + return {folderString:originalFolderScript, foundID:false} end _walkFoldersLookingForName -on photosLibraryGetFolderIDStringForName(theFolderName) - (* return AppleScript snippet for folder with name folderName *) - # see https://discussions.apple.com/docs/DOC-250002459 +on photosLibraryGetFolderIDStringForName(theFolderName, topLevel) + (* Return AppleScript snippet for folder with name folderName + + Args: + folderName: the folder name to look for + topLevel: true if only top level folders should be searched, otherwise false + + Returns: + string: the AppleScript snippet for the folder + missing value: if no folder with the given name is found + *) + -- TODO: topLevel logic isn't correct for Mojave which will return *all* folders + -- on Catalina+, only top level folders are returned by Photos tell application "Photos" set theFolders to folders repeat with aFolder in theFolders @@ -348,11 +376,16 @@ on photosLibraryGetFolderIDStringForName(theFolderName) end if -- my is required due to scope as this is inside a tell block -- if my is not used, Photos will look for the function _walkFolders which does not exist in its namespace - set returnValue to my _walkFoldersLookingForName(theFolderName, aFolder, folderString) - if returnValue is not equal to "" then - return returnValue + if topLevel is false then + --recursively walk the folder tree + set returnValue to my _walkFoldersLookingForName(theFolderName, aFolder, folderString) + if foundID of returnValue is true then + return folderString of returnValue + end if end if end repeat + -- went through all folders with no match + return missing value end tell end photosLibraryGetFolderIDStringForName @@ -535,7 +568,7 @@ on photosLibraryCreateAlbumAtFolder(albumName, folderIDString) folderIDString: string; id of folder to create album in Returns: - UUID of newly created album or 0 if error + UUID of newly created album or missing value if error *) set theScript to " set count_ to 0 @@ -548,7 +581,7 @@ on photosLibraryCreateAlbumAtFolder(albumName, folderIDString) set count_ to count_ + 1 end try end repeat - return 0 + return missing value " photosLibraryWaitForPhotos(WAIT_FOR_PHOTOS) return folderRunScript(folderIDString, theScript) @@ -589,10 +622,14 @@ on photosLibraryDeleteAlbum(id_) end photosLibraryDeleteAlbum on photosLibraryCreateFolder(folderName) - (* creates folder named folderName - does not check for duplicate folder - Returns: - UUID of newly created folder or 0 if error + (* Creates top-level folder named folderName; does not check for duplicate folder + + Args: + folderName: string; name of folder to create + + Returns: + folder id string for new folder or missing value if error + *) photosLibraryWaitForPhotos(WAIT_FOR_PHOTOS) tell application "Photos" @@ -600,45 +637,57 @@ on photosLibraryCreateFolder(folderName) repeat while count_ < MAX_RETRY try set theFolder to make new folder named folderName - set theID to ((id of theFolder) as text) - return theID + set theID to (id of theFolder) as text + return "folder id(\"" & theID & "\")" on error set count_ to count_ + 1 end try end repeat - return 0 + return missing value end tell end photosLibraryCreateFolder -on photosLibraryCreateFolderAtFolder(folderName, folder_id_) - (* creates folder named folderName inside folder folder_id_ - does not check for duplicate folder - Returns: - UUID of newly created folder +on photosLibraryCreateFolderAtFolder(folderIDString, folderName) + (* Creates folder named folderName inside folder folderIDString + does not check for duplicate folder + + Args: + folderIDString: string; id of folder to create folder in + folderName: string; name of folder to create + + Returns: + folder id string of newly created folder or missing value if error *) - photosLibraryWaitForPhotos(WAIT_FOR_PHOTOS) - set folder_ to folderGetFolderForID(folder_id_) - tell application "Photos" + set theScript to " set count_ to 0 - repeat while count_ < MAX_RETRY + repeat while count_ < " & MAX_RETRY & " try - set theFolder to make new folder named folderName at folder_ - set theID to ((id of theFolder) as text) - return theID + tell theFolder + set newFolder to make new folder named \"" & folderName & "\" at theFolder + set theID to (id of newFolder) as text + return \"folder id(\\\"\" & theID & \"\\\")\" + end tell on error set count_ to count_ + 1 end try end repeat - return 0 - end tell + return missing value + " + photosLibraryWaitForPhotos(WAIT_FOR_PHOTOS) + set newFolderID to folderRunScript(folderIDString, theScript) + if newFolderID is equal to missing value then + return missing value + end if + return newFolderID & " of " & folderIDString end photosLibraryCreateFolderAtFolder -on photosLibraryDeleteFolder(id_) - (* delete folder with id_ *) - set folder_ to folderGetFolderForID(id_) - tell application "Photos" - delete folder_ - end tell +on photosLibraryDeleteFolder(folderIDString) + (* Delete folder with id string folderIDString + + NOTE: Since Catalina/10.15, does not work for sub folders + *) + photosLibraryWaitForPhotos(WAIT_FOR_PHOTOS) + return folderRunScript(folderIDString, "delete theFolder") end photosLibraryDeleteFolder (* @@ -907,7 +956,6 @@ on albumSpotlight(id_) end tell end albumSpotlight - ---------- Folder ---------- on folderGetIDStringFromPath(folderPath) @@ -1085,7 +1133,7 @@ on folderSetName(folderIDString, theName) end folderSetName on folderParent(folderIDString) - (* return folder script for parent path of folder at folderID + (* return folder script for parent path of folder at folderIDString Args: folderIDString: script snippet as returned by folderGetIDStringFromPath @@ -1124,8 +1172,8 @@ on folderFolders(folderIDString) (* return list of folder IDs in folder *) set theScript to " set theIDs to {} - repeat with theFolder in folders of theFolder - set end of theIDs to id of theFolder + repeat with aSubFolder in folders of theFolder + set end of theIDs to id of aSubFolder end repeat return theIDs " diff --git a/photoscript/utils.py b/photoscript/utils.py index 647a16d..43de3f1 100644 --- a/photoscript/utils.py +++ b/photoscript/utils.py @@ -61,4 +61,4 @@ def get_os_version() -> tuple[int, int, int]: f"Could not parse version string: {platform.mac_ver()} {version}" ) ) - return tuple(map(int, (ver, major, minor))) + return tuple(int(x) for x in (ver, major, minor)) diff --git a/tests/mock_photoscript.applescript b/tests/mock_photoscript.applescript index 61ff26a..ad5a069 100644 --- a/tests/mock_photoscript.applescript +++ b/tests/mock_photoscript.applescript @@ -1,17 +1,17 @@ (* mock photoscript applescript functions for testing AppleScriptError *) on photosLibraryCreateFolder(folderName) - return 0 + return missing value end photosLibraryCreateFolder on photosLibraryCreateFolderAtFolder(folderName, folder_id_) - return 0 + return missing value end photosLibraryCreateFolderAtFolder on photosLibraryCreateAlbum(albumName) - return 0 + return missing value end photosLibraryCreateAlbum on photosLibraryCreateAlbumAtFolder(albumName, folder_id_) - return 0 + return missing value end photosLibraryCreateAlbumAtFolder \ No newline at end of file diff --git a/tests/test_3_folder.py b/tests/test_3_folder.py index 44b4707..d96af67 100644 --- a/tests/test_3_folder.py +++ b/tests/test_3_folder.py @@ -1,30 +1,29 @@ """ 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 +import photoscript +from tests.conftest import get_os_version, photoslib, suspend_capture +from tests.photoscript_config_catalina import ALBUM_1_NAME, FOLDER_1_SUBFOLDERS OS_VER = get_os_version()[1] if OS_VER == "15": from tests.photoscript_config_catalina import ( - FOLDER_NAMES_ALL, - FOLDER_NAMES_TOP, FOLDER_1_LEN, FOLDER_1_NAME, + FOLDER_1_SUBFOLDERS, FOLDER_1_UUID, FOLDER_1_UUID_OSXPHOTOS, - FOLDER_1_SUBFOLDERS, FOLDER_2_LEN, FOLDER_2_NAME, - FOLDER_2_UUID, FOLDER_2_PATH, FOLDER_2_PATH_STR, FOLDER_2_PATH_STR_COLON, + FOLDER_2_UUID, + FOLDER_3_ALBUMS, FOLDER_3_LEN, FOLDER_3_NAME, - FOLDER_3_ALBUMS, FOLDER_3_UUID, FOLDER_NAME, FOLDER_NAMES_ALL, @@ -53,17 +52,14 @@ ########## Non-interactive tests ########## -def test_folder_init(): - import photoscript - +def test_folder_init_uuid(): + """Test init with UUID""" folder = photoscript.Folder(FOLDER_1_UUID) assert isinstance(folder, photoscript.Folder) def test_folder_init_osxphotos_uuid(): - """ test Folder() with osxphotos style UUID """ - import photoscript - + """test Folder() with osxphotos style UUID""" folder = photoscript.Folder(FOLDER_1_UUID_OSXPHOTOS) assert isinstance(folder, photoscript.Folder) assert folder.id == FOLDER_1_UUID @@ -71,33 +67,44 @@ def test_folder_init_osxphotos_uuid(): def test_folder_init_bad_uuid(): - import photoscript - + """Test init with bad UUID""" with pytest.raises(ValueError): assert photoscript.Folder("BAD_UUID") -def test_folder_id(): - import photoscript +def test_folder_init_bad_path(): + """Test init with bad path""" + with pytest.raises(ValueError): + assert photoscript.Folder(path="BAD_PATH") + +def test_folder_init_bad_idstring(): + """Test init with bad idstring""" + with pytest.raises(ValueError): + assert photoscript.Folder(idstring="BAD_IDSTRING") + + +def test_folder_id(): + """Test folder id""" folder = photoscript.Folder(FOLDER_1_UUID) assert folder.id == FOLDER_1_UUID def test_folder_uuid(): - import photoscript - + """Test folder uuid""" folder = photoscript.Folder(FOLDER_1_UUID) assert folder.uuid == FOLDER_1_UUID_OSXPHOTOS def test_folder_name_title(photoslib): + """Test folder name/title""" folder = photoslib.folder(FOLDER_1_NAME) assert folder.name == FOLDER_1_NAME assert folder.title == FOLDER_1_NAME def test_folder_name_setter(photoslib): + """ "Test setter for name""" folder = photoslib.folder(FOLDER_1_NAME) new_name = "My New Folder Name" folder.name = new_name @@ -106,6 +113,7 @@ def test_folder_name_setter(photoslib): def test_folder_title_setter(photoslib): + """Test setter for title""" folder = photoslib.folder(FOLDER_1_NAME) new_name = "My New Folder Name" folder.title = new_name @@ -114,18 +122,19 @@ def test_folder_title_setter(photoslib): def test_folder_parent_id(photoslib): + """ "Test parent_id top_level folder""" folder = photoslib.folder(FOLDER_1_NAME) assert folder.parent_id is None -def test_folder_parent_id(photoslib): +def test_folder_parent_id_not_toplevel(photoslib): + """Test parent id with non-top-level folder""" folder = photoslib.folder(FOLDER_2_NAME, top_level=False) assert folder.parent_id == FOLDER_1_UUID def test_folder_parent(photoslib): - import photoscript - + """Test folder parent""" folder = photoslib.folder(FOLDER_2_NAME, top_level=False) parent = folder.parent assert isinstance(parent, photoscript.Folder) @@ -133,11 +142,13 @@ def test_folder_parent(photoslib): def test_folder_parent_top_level(photoslib): + """Test folder parent with top-level folder""" folder = photoslib.folder(FOLDER_NAMES_TOP[0]) assert folder.parent is None def test_folder_path_str(photoslib): + """Test folder path_str""" folder = photoslib.folder(FOLDER_2_NAME, top_level=False) assert folder.path_str() == FOLDER_2_PATH_STR assert folder.path_str(":") == FOLDER_2_PATH_STR_COLON @@ -146,8 +157,7 @@ def test_folder_path_str(photoslib): def test_folder_path(photoslib): - import photoscript - + """Test folder path""" folder = photoslib.folder(FOLDER_2_NAME, top_level=False) path = folder.path() assert len(path) == len(FOLDER_2_PATH) @@ -157,50 +167,56 @@ def test_folder_path(photoslib): def test_folder_albums(photoslib): + """Test folder albums""" 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): + """Test folder album""" 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): + """Test folder album with bad name""" folder = photoslib.folder(FOLDER_3_NAME) album = folder.album("FOOBAR") assert album is None def test_folder_subfolders(photoslib): + """Test folder subfolders""" 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): + """Test folder subfolders with no subfolders""" folder = photoslib.folder(FOLDER_2_NAME, top_level=False) subfolders = folder.subfolders assert subfolders == [] def test_folder_folder(photoslib): + """Test folder folder""" folder = photoslib.folder(FOLDER_1_NAME) subfolder = folder.folder(FOLDER_2_NAME) assert subfolder.name == FOLDER_2_NAME def test_folder_folder_none(photoslib): + """Test folder folder with no subfolder""" folder = photoslib.folder(FOLDER_1_NAME) subfolder = folder.folder("FOOBAR") assert subfolder is None def test_folder_create_album(photoslib): - import photoscript - + """Test folder create_album""" folder = photoslib.folder(FOLDER_1_NAME) album = folder.create_album("New Album") assert isinstance(album, photoscript.Album) @@ -209,8 +225,7 @@ def test_folder_create_album(photoslib): def test_folder_create_folder(photoslib): - import photoscript - + """Test folder create_folder""" folder = photoslib.folder(FOLDER_1_NAME) subfolder = folder.create_folder("New Folder") assert isinstance(subfolder, photoscript.Folder) @@ -219,18 +234,18 @@ def test_folder_create_folder(photoslib): def test_len_1(photoslib): - """ test Album.__len__ """ + """test Folder.__len__""" folder = photoslib.folder(FOLDER_1_NAME) assert len(folder) == FOLDER_1_LEN def test_len_2(photoslib): - """ test Album.__len__ """ + """test Folder.__len__""" folder = photoslib.folder(FOLDER_2_NAME, top_level=False) assert len(folder) == FOLDER_2_LEN def test_len_3(photoslib): - """ test Album.__len__ """ + """test Folder.__len__""" folder = photoslib.folder(FOLDER_3_NAME) assert len(folder) == FOLDER_3_LEN