Skip to content

Commit

Permalink
Added Folder.subfolders
Browse files Browse the repository at this point in the history
  • Loading branch information
RhetTbull committed Sep 11, 2020
1 parent 203c15a commit c992451
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 10 deletions.
4 changes: 4 additions & 0 deletions docs/source/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ photoscript module
:members:
:undoc-members:

.. autoclass:: photoscript.Folder
:members:
:undoc-members:

.. autoclass:: photoscript.Photo
:members:
:undoc-members:
Binary file modified photoscript.pdf
Binary file not shown.
23 changes: 15 additions & 8 deletions photoscript/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ def import_photos(self, photo_paths, album=None, skip_duplicate_check=False):
skip_duplicate_check,
)
else:
photo_ids = run_script("_photoslibrary_import", photo_paths, skip_duplicate_check)
photo_ids = run_script(
"_photoslibrary_import", photo_paths, skip_duplicate_check
)

return [Photo(photo) for photo in photo_ids]

Expand Down Expand Up @@ -581,7 +583,7 @@ def parent_id(self):
""" parent container id """
return run_script("_folder_parent", self.id)

# TODO: if no parent should return a "My Albums" object that contains all top-level folders/albums
# 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 """
Expand Down Expand Up @@ -631,22 +633,27 @@ def album(self, name):
return None

@property
def folders(self):
""" list of Folder objects for folders contained in folder """
def subfolders(self):
""" list of Folder objects for immediate sub-folders contained in folder """
folder_ids = run_script("_folder_folders", self.id)
return [Folder(uuid) for uuid in folder_ids]

def folder(self, name):
"""Return Folder object for subfolder folder named name
or None if no matching subfolder
"""Folder object for first subfolder folder named name.
Args:
name: name of folder to to return
Returns:
Folder object for first subfolder who's name matches name or None if not found
"""
for folder in self.folders:
for folder in self.subfolders:
if folder.name == name:
return folder
return None

def create_album(self, name):
"""creates an album in this folder
"""Creates an album in this folder
Args:
name: name of new album
Expand Down
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.12"
__version__ = "0.0.13"
42 changes: 41 additions & 1 deletion tests/test_photoscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def test_photoslibrary_folder(photoslib):

folder = photoslib.folder("Folder1")
assert isinstance(folder, photoscript.Folder)
subfolders = folder.folders
subfolders = folder.subfolders
assert len(subfolders) == 1
assert subfolders[0].name == "SubFolder1"

Expand Down Expand Up @@ -428,6 +428,46 @@ def test_photoslibrary_create_folder_at_folder(photoslib):
assert folder.parent.name == "Travel"


def test_photoslibrary_make_folders_exist(photoslib):
""" test make_folders with path that exists """
import photoscript

subfolder = photoslib.folder("SubFolder1", top_level=False)
folder = photoslib.make_folders(["Folder1", "SubFolder1"])
assert isinstance(folder, photoscript.Folder)
assert len(photoslib.folders(top_level=False)) == len(FOLDER_NAMES_ALL)
assert subfolder.id == folder.id


def test_photoslibrary_make_folders_new(photoslib):
""" test make_folders with entirely new path """
import photoscript

folder = photoslib.make_folders(["Folder2", "SubFolder2"])
assert isinstance(folder, photoscript.Folder)
assert len(photoslib.folders(top_level=False)) == len(FOLDER_NAMES_ALL) + 2


def test_photoslibrary_make_folders_new_exist(photoslib):
""" test make_folders with new path inside existing path"""
import photoscript

subfolder = photoslib.folder("SubFolder1", top_level=False)
folder = photoslib.make_folders(["Folder1", "SubFolder1", "New Sub Folder"])
assert isinstance(folder, photoscript.Folder)
assert len(photoslib.folders(top_level=False)) == len(FOLDER_NAMES_ALL) + 1
assert folder.parent_id == subfolder.id

def test_photoslibrary_make_folders_bad_type(photoslib):
""" test make_folders with non-list value for folders """
with pytest.raises(TypeError):
photoslib.make_folders("Folder1")

def test_photoslibrary_make_folders_bad_value(photoslib):
""" test make_folders with empty value for folders """
with pytest.raises(ValueError):
photoslib.make_folders([])

def test_photoslibrary_selection(photoslib, suspend_capture):
""" Test selection. NOTE: this test requires user interaction """
import os
Expand Down

0 comments on commit c992451

Please sign in to comment.