Added shallow json() option, #1038 (#1040)

This commit is contained in:
Rhet Turnbull
2023-04-08 11:10:29 -07:00
committed by GitHub
parent f4a743468d
commit d2b7783125
4 changed files with 91 additions and 30 deletions

View File

@@ -1,5 +1,6 @@
"""Test macOS 13.0 Photos library"""
import json
from collections import namedtuple
import pytest
@@ -660,7 +661,6 @@ def test_keyword_2(photosdb):
def test_keyword_not_in_album(photosdb):
# find all photos with keyword "Kids" not in the album "Pumpkin Farm"
photos1 = photosdb.photos(albums=["Pumpkin Farm"])
photos2 = photosdb.photos(keywords=["Kids"])
@@ -1273,3 +1273,26 @@ def test_person_feature_less(photosdb):
photo = photosdb.get_photo(UUID_PERSON_NOT_FEATURE_LESS)
assert not photo.person_info[0].feature_less
def test_json(photosdb: osxphotos.PhotosDB):
"""Test PhotoInfo.json()"""
photo = photosdb.get_photo(UUID_DICT["favorite"])
photo_dict = json.loads(photo.json())
assert photo_dict["favorite"]
def test_json_indent(photosdb: osxphotos.PhotosDB):
"""Test PhotoInfo.json() with indent"""
photo = photosdb.get_photo(UUID_DICT["favorite"])
photo_dict = json.loads(photo.json(indent=4))
assert photo_dict["favorite"]
assert "album_info" in photo_dict
def test_json_shallow(photosdb: osxphotos.PhotosDB):
"""Test PhotoInfo.json() with shallow=True"""
photo = photosdb.get_photo(UUID_DICT["favorite"])
photo_dict = json.loads(photo.json(shallow=True))
assert photo_dict["favorite"]
assert "album_info" not in photo_dict