From d95acdf9f8764a1720bcba71a6dad29bf668eaf9 Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Sat, 21 Dec 2019 10:08:49 -0800 Subject: [PATCH] Moved PhotosDB attributes to properties instead of methods --- README.md | 222 ++++++++++++++------------------- examples/examples.py | 16 +-- osxphotos/__main__.py | 14 +-- osxphotos/photosdb.py | 17 ++- tests/test_10_12_6.py | 22 ++-- tests/test_catalina_10_15_1.py | 26 ++-- tests/test_highsierra.py | 22 ++-- tests/test_mojave_10_14_5.py | 22 ++-- tests/test_mojave_10_14_6.py | 26 ++-- 9 files changed, 183 insertions(+), 204 deletions(-) diff --git a/README.md b/README.md index dc76cf2c..6c7c094c 100644 --- a/README.md +++ b/README.md @@ -3,59 +3,7 @@ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/python/black) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) -- [OSXPhotos](#osxphotos) - * [What is osxphotos?](#what-is-osxphotos) - * [Supported operating systems](#supported-operating-systems) - * [Installation instructions](#installation-instructions) - * [Command Line Usage](#command-line-usage) - * [Example uses of the module](#example-uses-of-the-module) - * [Module Interface](#module-interface) - + [PhotosDB](#photosdb) - - [Open the default Photos library](#open-the-default-photos-library) - - [Open System Photos library](#open-system-photos-library) - - [Open a specific Photos library](#open-a-specific-photos-library) - - [```keywords()```](#keywords) - - [```albums()```](#albums) - - [```persons()```](#persons) - - [```keywords_as_dict()```](#keywords_as_dict) - - [```persons_as_dict()```](#persons_as_dict) - - [```albums_as_dict()```](#albums_as_dict) - - [```get_library_path()```](#get_library_path) - - [```get_db_path()```](#get_db_path) - - [```get_db_version()```](#get_db_version) - - [`photos(keywords=[], uuid=[], persons=[], albums=[])`](#photoskeywords-uuid-persons-albums) - + [PhotoInfo](#photoinfo) - - [`uuid()`](#uuid) - - [`filename()`](#filename) - - [`original_filename()`](#original_filename) - - [`date()`](#date) - - [`description()`](#description) - - [`title()`](#title) - - [`keywords()`](#keywords) - - [`albums()`](#albums) - - [`persons()`](#persons) - - [`path()`](#path) - - [`path_edited()`](#path_edited) - - [`ismissing()`](#ismissing) - - [`hasadjustments()`](#hasadjustments) - - [`external_edit()`](#external_edit) - - [`favorite()`](#favorite) - - [`hidden()`](#hidden) - - [`location()`](#location) - - [`json()`](#json) - - [`export(dest, *filename, edited=False, overwrite=False, increment=True)`](#exportdest-filename-editedfalse-overwritefalse-incrementtrue) - + [Utility Functions](#utility-functions) - - [```get_system_library_path()```](#get_system_library_path) - - [```get_last_library_path()```](#get_last_library_path) - - [```list_photo_libraries()```](#list_photo_libraries) - - [```dd_to_dms_str(lat, lon)```](#dd_to_dms_strlat-lon) - + [Examples](#examples) - * [History](#history) - * [Contributing](#contributing) - * [Implementation Notes](#implementation-notes) - * [Dependencies](#dependencies) - * [Acknowledgements](#acknowledgements) - + ## What is osxphotos? OSXPhotos provides the ability to interact with and query Apple's Photos.app library database on MacOS. Using this module you can query the Photos database for information about the photos stored in a Photos library on your Mac--for example, file name, file path, and metadata such as keywords/tags, persons/faces, albums, etc. You can also easily export both the original and edited photos. @@ -150,13 +98,13 @@ import osxphotos def main(): photosdb = osxphotos.PhotosDB() - print(photosdb.keywords()) - print(photosdb.persons()) - print(photosdb.albums()) + print(photosdb.keywords) + print(photosdb.persons) + print(photosdb.albums) - print(photosdb.keywords_as_dict()) - print(photosdb.persons_as_dict()) - print(photosdb.albums_as_dict()) + print(photosdb.keywords_as_dict) + print(photosdb.persons_as_dict) + print(photosdb.albums_as_dict) # find all photos with Keyword = Foo and containing John Smith photos = photosdb.photos(keywords=["Foo"],persons=["John Smith"]) @@ -278,78 +226,78 @@ Pass the fully qualified path to the Photos library or the actual database file Returns a PhotosDB object. -#### ```keywords()``` +#### ```keywords``` ```python # assumes photosdb is a PhotosDB object (see above) -keywords = photosdb.keywords() +keywords = photosdb.keywords ``` Returns a list of the keywords found in the Photos library -#### ```albums()``` +#### ```albums``` ```python # assumes photosdb is a PhotosDB object (see above) -albums = photosdb.albums() +albums = photosdb.albums ``` Returns a list of the albums found in the Photos library. **Note**: In Photos 5.0 (MacOS 10.15/Catalina), It is possible to have more than one album with the same name in Photos. Albums with duplicate names are treated as a single album and the photos in each are combined. For example, if you have two albums named "Wedding" and each has 2 photos, osxphotos will treat this as a single album named "Wedding" with 4 photos in it. -#### ```persons()``` +#### ```persons``` ```python # assumes photosdb is a PhotosDB object (see above) -persons = photosdb.persons() +persons = photosdb.persons ``` Returns a list of the persons (faces) found in the Photos library -#### ```keywords_as_dict()``` +#### ```keywords_as_dict``` ```python # assumes photosdb is a PhotosDB object (see above) -keyword_dict = photosdb.keywords_as_dict() +keyword_dict = photosdb.keywords_as_dict ``` Returns a dictionary of keywords found in the Photos library where key is the keyword and value is the count of how many times that keyword appears in the library (ie. how many photos are tagged with the keyword). Resulting dictionary is in reverse sorted order (e.g. keyword with the highest count is first). -#### ```persons_as_dict()``` +#### ```persons_as_dict``` ```python # assumes photosdb is a PhotosDB object (see above) -persons_dict = photosdb.persons_as_dict() +persons_dict = photosdb.persons_as_dict ``` Returns a dictionary of persons (faces) found in the Photos library where key is the person name and value is the count of how many times that person appears in the library (ie. how many photos are tagged with the person). Resulting dictionary is in reverse sorted order (e.g. person who appears in the most photos is listed first). -#### ```albums_as_dict()``` +#### ```albums_as_dict``` ```python # assumes photosdb is a PhotosDB object (see above) -albums_dict = photosdb.albums_as_dict() +albums_dict = photosdb.albums_as_dict ``` Returns a dictionary of albums found in the Photos library where key is the album name and value is the count of how many photos are in the album. Resulting dictionary is in reverse sorted order (e.g. album with the most photos is listed first). **Note**: In Photos 5.0 (MacOS 10.15/Catalina), It is possible to have more than one album with the same name in Photos. Albums with duplicate names are treated as a single album and the photos in each are combined. For example, if you have two albums named "Wedding" and each has 2 photos, osxphotos will treat this as a single album named "Wedding" with 4 photos in it. -#### ```get_library_path()``` +#### ```library_path``` ```python # assumes photosdb is a PhotosDB object (see above) -photosdb.get_photos_library_path() +photosdb.library_path ``` Returns the path to the Photos library as a string -#### ```get_db_path()``` +#### ```db_path``` ```python # assumes photosdb is a PhotosDB object (see above) -photosdb.get_db_path() +photosdb.db_path ``` Returns the path to the Photos database PhotosDB was initialized with -#### ```get_db_version()``` +#### ```db_version``` ```python # assumes photosdb is a PhotosDB object (see above) -photosdb.get_db_version() +photosdb.db_version ``` Returns the version number for Photos library database. You likely won't need this but it's provided in case needed for debugging. PhotosDB will print a warning to `sys.stderr` if you open a database version that has not been tested. @@ -425,55 +373,55 @@ photos3 = [p for p in photos2 if p not in photos1] ### PhotoInfo PhotosDB.photos() returns a list of PhotoInfo objects. Each PhotoInfo object represents a single photo in the Photos library. -#### `uuid()` +#### `uuid` Returns the universally unique identifier (uuid) of the photo. This is how Photos keeps track of individual photos within the database. -#### `filename()` -Returns the current filename of the photo on disk. See also `original_filename()` +#### `filename` +Returns the current filename of the photo on disk. See also `original_filename` -#### `original_filename()` -Returns the original filename of the photo when it was imported to Photos. **Note**: Photos 5.0+ renames the photo when it adds the file to the library using UUID. See also `filename()` +#### `original_filename` +Returns the original filename of the photo when it was imported to Photos. **Note**: Photos 5.0+ renames the photo when it adds the file to the library using UUID. See also `filename` -#### `date()` +#### `date` Returns the date of the photo as a datetime.datetime object -#### `description()` +#### `description` Returns the description of the photo -#### `title()` +#### `title` Returns the title of the photo -#### `keywords()` +#### `keywords` Returns a list of keywords (e.g. tags) applied to the photo -#### `albums()` +#### `albums` Returns a list of albums the photo is contained in -#### `persons()` +#### `persons` Returns a list of the names of the persons in the photo -#### `path()` -Returns the absolute path to the photo on disk as a string. **Note**: this returns the path to the *original* unedited file (see `hasadjustments()`). If the file is missing on disk, path=`None` (see `ismissing()`) +#### `path` +Returns the absolute path to the photo on disk as a string. **Note**: this returns the path to the *original* unedited file (see `hasadjustments`). If the file is missing on disk, path=`None` (see `ismissing`) -#### `path_edited()` -Returns the absolute path to the edited photo on disk as a string. If the photo has not been edited, returns `None`. See also `path()` and `hasadjustments()`. +#### `path_edited` +Returns the absolute path to the edited photo on disk as a string. If the photo has not been edited, returns `None`. See also `path` and `hasadjustments`. -#### `ismissing()` -Returns `True` if the original image file is missing on disk, otherwise `False`. This can occur if the file has been uploaded to iCloud but not yet downloaded to the local library or if the file was deleted or imported from a disk that has been unmounted. **Note**: this status is set by Photos and osxphotos does not verify that the file path returned by `path()` actually exists. It merely reports what Photos has stored in the library database. +#### `ismissing` +Returns `True` if the original image file is missing on disk, otherwise `False`. This can occur if the file has been uploaded to iCloud but not yet downloaded to the local library or if the file was deleted or imported from a disk that has been unmounted. **Note**: this status is set by Photos and osxphotos does not verify that the file path returned by `path` actually exists. It merely reports what Photos has stored in the library database. -#### `hasadjustments()` +#### `hasadjustments` Returns `True` if the picture has been edited, otherwise `False` -#### `external_edit()` +#### `external_edit` Returns `True` if the picture was edited in an external editor (outside Photos.app), otherwise `False` -#### `favorite()` +#### `favorite` Returns `True` if the picture has been marked as a favorite, otherwise `False` -#### `hidden()` +#### `hidden` Returns `True` if the picture has been marked as hidden, otherwise `False` -#### `location()` +#### `location` Returns latitude and longitude as a tuple of floats (latitude, longitude). If location is not set, latitude and longitude are returned as `None` #### `json()` @@ -522,43 +470,69 @@ This is the same format used by exiftool's json format. ```python import osxphotos -photosdb = osxphotos.PhotosDB() -photos=photosdb.photos() +def main(): + photosdb = osxphotos.PhotosDB() + print(f"db file = {photosdb.db_path}") + print(f"db version = {photosdb.db_version}") -for p in photos: - print( - p.uuid(), - p.filename(), - p.original_filename(), - p.date(), - p.description(), - p.name(), - p.keywords(), - p.albums(), - p.persons(), - p.path(), - p.ismissing(), - p.hasadjustments(), - ) + print(photosdb.keywords) + print(photosdb.persons) + print(photosdb.albums) + + print(photosdb.keywords_as_dict) + print(photosdb.persons_as_dict) + print(photosdb.albums_as_dict) + + # find all photos with Keyword = Kids and containing person Katie + photos = photosdb.photos(keywords=["Kids"], persons=["Katie"]) + print(f"found {len(photos)} photos") + + # find all photos that include Katie but do not contain the keyword wedding + photos = [ + p + for p in photosdb.photos(persons=["Katie"]) + if p not in photosdb.photos(keywords=["wedding"]) + ] + + # get all photos in the database + photos = photosdb.photos() + for p in photos: + print( + p.uuid, + p.filename, + p.date, + p.description, + p.title, + p.keywords, + p.albums, + p.persons, + p.path, + p.ismissing, + p.hasadjustments, + ) + + +if __name__ == "__main__": + main() ``` -## History +## Related Projects -This project started as a command line utility, `photosmeta`, available at [photosmeta](https://github.com/RhetTbull/photosmeta) This module converts the photosmeta Photos library query functionality into a module. +[photosmeta](https://github.com/rhettbull/photosmeta): uses osxphotos and [exiftool](https://exiftool.org/) to apply metadata from Photos as exif data in the photo files. ## Contributing -Contributing is easy! If you find bugs or want to suggest additional features/changes, please open an [issue](https://github.com/RhetTbull/osxphotos/issues/). +Contributing is easy! if you find bugs or want to suggest additional features/changes, please open an [issue](https://github.com/rhettbull/osxphotos/issues/). I'll gladly consider pull requests for bug fixes or feature implementations. -If you have an interesting example that shows usage of this module, submit an issue or pull request and I'll include it or link to it. +If you have an interesting example that shows usage of this module, submit an issue or pull request and i'll include it or link to it. ## Implementation Notes -This module works by creating a copy of the sqlite3 database that Photos uses to store data about the Photos library. The class PhotosDB then queries this database to extract information about the photos such as persons (faces identified in the photos), albums, keywords, etc. +This module works by creating a copy of the sqlite3 database that photos uses to store data about the photos library. the class photosdb then queries this database to extract information about the photos such as persons (faces identified in the photos), albums, keywords, etc. -If Apple changes the database format this will likely break. +If apple changes the database format this will likely break. Apple does provide a framework ([PhotoKit](https://developer.apple.com/documentation/photokit?language=objc)) for querying the user's Photos library and I attempted to create the funcationality in this module using this framework but unfortunately PhotoKit does not provide access to much of the needed metadata (such as Faces/Persons). While copying the sqlite file is a bit kludgy, it allows osxphotos to provide access to all available metadata. @@ -570,7 +544,3 @@ Apple does provide a framework ([PhotoKit](https://developer.apple.com/documenta ## Acknowledgements This project was originally inspired by photo-export by Patrick Fältström see: (https://github.com/patrikhson/photo-export) Copyright (c) 2015 Patrik Fältström paf@frobbit.se -To interact with the Photos app, I use [py-applescript]( https://github.com/rdhyee/py-applescript) by "Raymond Yee / rdhyee". Rather than import this module, I included the entire module -(which is published as public domain code) in a private module to prevent ambiguity with -other applescript modules on PyPi. py-applescript uses a native bridge via PyObjC and -is very fast compared to the other osascript based modules. diff --git a/examples/examples.py b/examples/examples.py index 9be16d4c..377ea420 100644 --- a/examples/examples.py +++ b/examples/examples.py @@ -3,16 +3,16 @@ import osxphotos def main(): photosdb = osxphotos.PhotosDB() - print(f"db file = {photosdb.get_db_path()}") - print(f"db version = {photosdb.get_db_version()}") + print(f"db file = {photosdb.db_path}") + print(f"db version = {photosdb.db_version}") - print(photosdb.keywords()) - print(photosdb.persons()) - print(photosdb.albums()) + print(photosdb.keywords) + print(photosdb.persons) + print(photosdb.albums) - print(photosdb.keywords_as_dict()) - print(photosdb.persons_as_dict()) - print(photosdb.albums_as_dict()) + print(photosdb.keywords_as_dict) + print(photosdb.persons_as_dict) + print(photosdb.albums_as_dict) # find all photos with Keyword = Kids and containing person Katie photos = photosdb.photos(keywords=["Kids"], persons=["Katie"]) diff --git a/osxphotos/__main__.py b/osxphotos/__main__.py index 7807a61e..07590782 100644 --- a/osxphotos/__main__.py +++ b/osxphotos/__main__.py @@ -50,7 +50,7 @@ def cli(ctx, db, json, debug): def keywords(cli_obj): """ Print out keywords found in the Photos library. """ photosdb = osxphotos.PhotosDB(dbfile=cli_obj.db) - keywords = {"keywords": photosdb.keywords_as_dict()} + keywords = {"keywords": photosdb.keywords_as_dict} if cli_obj.json: click.echo(json.dumps(keywords)) else: @@ -62,7 +62,7 @@ def keywords(cli_obj): def albums(cli_obj): """ Print out albums found in the Photos library. """ photosdb = osxphotos.PhotosDB(dbfile=cli_obj.db) - albums = {"albums": photosdb.albums_as_dict()} + albums = {"albums": photosdb.albums_as_dict} if cli_obj.json: click.echo(json.dumps(albums)) else: @@ -74,7 +74,7 @@ def albums(cli_obj): def persons(cli_obj): """ Print out persons (faces) found in the Photos library. """ photosdb = osxphotos.PhotosDB(dbfile=cli_obj.db) - persons = {"persons": photosdb.persons_as_dict()} + persons = {"persons": photosdb.persons_as_dict} if cli_obj.json: click.echo(json.dumps(persons)) else: @@ -88,20 +88,20 @@ def info(cli_obj): pdb = osxphotos.PhotosDB(dbfile=cli_obj.db) info = {} info["database_path"] = pdb.get_db_path() - info["database_version"] = pdb.get_db_version() + info["database_version"] = pdb.db_version photos = pdb.photos() info["photo_count"] = len(photos) - keywords = pdb.keywords_as_dict() + keywords = pdb.keywords_as_dict info["keywords_count"] = len(keywords) info["keywords"] = keywords - albums = pdb.albums_as_dict() + albums = pdb.albums_as_dict info["albums_count"] = len(albums) info["albums"] = albums - persons = pdb.persons_as_dict() + persons = pdb.persons_as_dict # handle empty person names (added by Photos 5.0+ when face detected but not identified) # TODO: remove this diff --git a/osxphotos/photosdb.py b/osxphotos/photosdb.py index c2a2979b..825e62bc 100644 --- a/osxphotos/photosdb.py +++ b/osxphotos/photosdb.py @@ -179,6 +179,7 @@ class PhotosDB: def __del__(self): self._cleanup_tmp_files() + @property def keywords_as_dict(self): """ return keywords as dict of keyword, count in reverse sorted order (descending) """ keywords = {} @@ -187,6 +188,7 @@ class PhotosDB: keywords = dict(sorted(keywords.items(), key=lambda kv: kv[1], reverse=True)) return keywords + @property def persons_as_dict(self): """ return persons as dict of person, count in reverse sorted order (descending) """ persons = {} @@ -195,6 +197,7 @@ class PhotosDB: persons = dict(sorted(persons.items(), key=lambda kv: kv[1], reverse=True)) return persons + @property def albums_as_dict(self): """ return albums as dict of albums, count in reverse sorted order (descending) """ albums = {} @@ -207,16 +210,19 @@ class PhotosDB: albums = dict(sorted(albums.items(), key=lambda kv: kv[1], reverse=True)) return albums + @property def keywords(self): """ return list of keywords found in photos database """ keywords = self._dbkeywords_keyword.keys() return list(keywords) + @property def persons(self): """ return list of persons found in photos database """ persons = self._dbfaces_person.keys() return list(persons) + @property def albums(self): """ return list of albums found in photos database """ # Could be more than one album with same name @@ -266,15 +272,18 @@ class PhotosDB: # """ # ) - def get_db_version(self): + @property + def db_version(self): """ return the database version as stored in LiGlobals table """ return self._db_version - def get_db_path(self): + @property + def db_path(self): """ returns path to the Photos library database PhotosDB was initialized with """ return os.path.abspath(self._dbfile) - def get_library_path(self): + @property + def library_path(self): """ returns path to the Photos library PhotosDB was initialized with """ return self._library_path @@ -1070,4 +1079,4 @@ class PhotosDB: def __repr__(self): # TODO: update to use __class__ and __name__ - return f"osxphotos.PhotosDB(dbfile='{self.get_db_path()}')" + return f"osxphotos.PhotosDB(dbfile='{self.db_path}')" diff --git a/tests/test_10_12_6.py b/tests/test_10_12_6.py index a85ff4f7..91dad97a 100644 --- a/tests/test_10_12_6.py +++ b/tests/test_10_12_6.py @@ -43,8 +43,8 @@ def test_db_version(): import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - # assert photosdb.get_db_version() in osxphotos._TESTED_DB_VERSIONS - assert photosdb.get_db_version() == "2622" + # assert photosdb.db_version in osxphotos._TESTED_DB_VERSIONS + assert photosdb.db_version == "2622" def test_os_version(): @@ -59,8 +59,8 @@ def test_persons(): import collections photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - assert "Katie" in photosdb.persons() - assert collections.Counter(PERSONS) == collections.Counter(photosdb.persons()) + assert "Katie" in photosdb.persons + assert collections.Counter(PERSONS) == collections.Counter(photosdb.persons) def test_keywords(): @@ -68,8 +68,8 @@ def test_keywords(): import collections photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - assert "wedding" in photosdb.keywords() - assert collections.Counter(KEYWORDS) == collections.Counter(photosdb.keywords()) + assert "wedding" in photosdb.keywords + assert collections.Counter(KEYWORDS) == collections.Counter(photosdb.keywords) def test_albums(): @@ -77,15 +77,15 @@ def test_albums(): import collections photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - assert "Pumpkin Farm" in photosdb.albums() - assert collections.Counter(ALBUMS) == collections.Counter(photosdb.albums()) + assert "Pumpkin Farm" in photosdb.albums + assert collections.Counter(ALBUMS) == collections.Counter(photosdb.albums) def test_keywords_dict(): import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - keywords = photosdb.keywords_as_dict() + keywords = photosdb.keywords_as_dict assert keywords["wedding"] == 2 assert keywords == KEYWORDS_DICT @@ -94,7 +94,7 @@ def test_persons_as_dict(): import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - persons = photosdb.persons_as_dict() + persons = photosdb.persons_as_dict assert persons["Maria"] == 1 assert persons == PERSONS_DICT @@ -103,7 +103,7 @@ def test_albums_as_dict(): import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - albums = photosdb.albums_as_dict() + albums = photosdb.albums_as_dict assert albums["Pumpkin Farm"] == 3 assert albums == ALBUM_DICT diff --git a/tests/test_catalina_10_15_1.py b/tests/test_catalina_10_15_1.py index 02404df3..c41b1b6f 100644 --- a/tests/test_catalina_10_15_1.py +++ b/tests/test_catalina_10_15_1.py @@ -120,8 +120,8 @@ def test_db_version(): import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - # assert photosdb.get_db_version() in osxphotos._TESTED_DB_VERSIONS - assert photosdb.get_db_version() == "6000" + # assert photosdb.db_version in osxphotos._TESTED_DB_VERSIONS + assert photosdb.db_version == "6000" def test_os_version(): @@ -136,8 +136,8 @@ def test_persons(): import collections photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - assert "Katie" in photosdb.persons() - assert collections.Counter(PERSONS) == collections.Counter(photosdb.persons()) + assert "Katie" in photosdb.persons + assert collections.Counter(PERSONS) == collections.Counter(photosdb.persons) def test_keywords(): @@ -145,8 +145,8 @@ def test_keywords(): import collections photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - assert "wedding" in photosdb.keywords() - assert collections.Counter(KEYWORDS) == collections.Counter(photosdb.keywords()) + assert "wedding" in photosdb.keywords + assert collections.Counter(KEYWORDS) == collections.Counter(photosdb.keywords) def test_albums(): @@ -154,15 +154,15 @@ def test_albums(): import collections photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - assert "Pumpkin Farm" in photosdb.albums() - assert collections.Counter(ALBUMS) == collections.Counter(photosdb.albums()) + assert "Pumpkin Farm" in photosdb.albums + assert collections.Counter(ALBUMS) == collections.Counter(photosdb.albums) def test_keywords_dict(): import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - keywords = photosdb.keywords_as_dict() + keywords = photosdb.keywords_as_dict assert keywords["wedding"] == 2 assert keywords == KEYWORDS_DICT @@ -171,7 +171,7 @@ def test_persons_as_dict(): import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - persons = photosdb.persons_as_dict() + persons = photosdb.persons_as_dict assert persons["Maria"] == 1 assert persons == PERSONS_DICT @@ -180,7 +180,7 @@ def test_albums_as_dict(): import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - albums = photosdb.albums_as_dict() + albums = photosdb.albums_as_dict assert albums["Pumpkin Farm"] == 3 assert albums == ALBUM_DICT @@ -391,7 +391,7 @@ def test_get_db_path(): import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - db_path = photosdb.get_db_path() + db_path = photosdb.db_path assert db_path.endswith(PHOTOS_DB_PATH) @@ -399,7 +399,7 @@ def test_get_library_path(): import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - lib_path = photosdb.get_library_path() + lib_path = photosdb.library_path assert lib_path.endswith(PHOTOS_LIBRARY_PATH) diff --git a/tests/test_highsierra.py b/tests/test_highsierra.py index d7aa255c..c4f8a28f 100644 --- a/tests/test_highsierra.py +++ b/tests/test_highsierra.py @@ -42,8 +42,8 @@ def test_db_version(): import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - assert photosdb.get_db_version() == "3301" - # assert photosdb.get_db_version() in osxphotos._TESTED_DB_VERSIONS + assert photosdb.db_version == "3301" + # assert photosdb.db_version in osxphotos._TESTED_DB_VERSIONS def test_os_version(): @@ -58,8 +58,8 @@ def test_persons(): import collections photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - assert "Katie" in photosdb.persons() - assert collections.Counter(PERSONS) == collections.Counter(photosdb.persons()) + assert "Katie" in photosdb.persons + assert collections.Counter(PERSONS) == collections.Counter(photosdb.persons) def test_keywords(): @@ -67,8 +67,8 @@ def test_keywords(): import collections photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - assert "wedding" in photosdb.keywords() - assert collections.Counter(KEYWORDS) == collections.Counter(photosdb.keywords()) + assert "wedding" in photosdb.keywords + assert collections.Counter(KEYWORDS) == collections.Counter(photosdb.keywords) def test_albums(): @@ -76,15 +76,15 @@ def test_albums(): import collections photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - assert "Pumpkin Farm" in photosdb.albums() - assert collections.Counter(ALBUMS) == collections.Counter(photosdb.albums()) + assert "Pumpkin Farm" in photosdb.albums + assert collections.Counter(ALBUMS) == collections.Counter(photosdb.albums) def test_keywords_dict(): import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - keywords = photosdb.keywords_as_dict() + keywords = photosdb.keywords_as_dict assert keywords["wedding"] == 2 assert keywords == KEYWORDS_DICT @@ -93,7 +93,7 @@ def test_persons_as_dict(): import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - persons = photosdb.persons_as_dict() + persons = photosdb.persons_as_dict assert persons["Maria"] == 1 assert persons == PERSONS_DICT @@ -102,7 +102,7 @@ def test_albums_as_dict(): import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - albums = photosdb.albums_as_dict() + albums = photosdb.albums_as_dict assert albums["Pumpkin Farm"] == 3 assert albums == ALBUM_DICT diff --git a/tests/test_mojave_10_14_5.py b/tests/test_mojave_10_14_5.py index e0ba20cc..2cc090a2 100644 --- a/tests/test_mojave_10_14_5.py +++ b/tests/test_mojave_10_14_5.py @@ -42,8 +42,8 @@ def test_db_version(): import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - # assert photosdb.get_db_version() in osxphotos._TESTED_DB_VERSIONS - assert photosdb.get_db_version() == "4016" + # assert photosdb.db_version in osxphotos._TESTED_DB_VERSIONS + assert photosdb.db_version == "4016" def test_os_version(): @@ -58,8 +58,8 @@ def test_persons(): import collections photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - assert "Katie" in photosdb.persons() - assert collections.Counter(PERSONS) == collections.Counter(photosdb.persons()) + assert "Katie" in photosdb.persons + assert collections.Counter(PERSONS) == collections.Counter(photosdb.persons) def test_keywords(): @@ -67,8 +67,8 @@ def test_keywords(): import collections photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - assert "wedding" in photosdb.keywords() - assert collections.Counter(KEYWORDS) == collections.Counter(photosdb.keywords()) + assert "wedding" in photosdb.keywords + assert collections.Counter(KEYWORDS) == collections.Counter(photosdb.keywords) def test_albums(): @@ -76,15 +76,15 @@ def test_albums(): import collections photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - assert "Pumpkin Farm" in photosdb.albums() - assert collections.Counter(ALBUMS) == collections.Counter(photosdb.albums()) + assert "Pumpkin Farm" in photosdb.albums + assert collections.Counter(ALBUMS) == collections.Counter(photosdb.albums) def test_keywords_dict(): import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - keywords = photosdb.keywords_as_dict() + keywords = photosdb.keywords_as_dict assert keywords["wedding"] == 2 assert keywords == KEYWORDS_DICT @@ -93,7 +93,7 @@ def test_persons_as_dict(): import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - persons = photosdb.persons_as_dict() + persons = photosdb.persons_as_dict assert persons["Maria"] == 1 assert persons == PERSONS_DICT @@ -102,7 +102,7 @@ def test_albums_as_dict(): import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - albums = photosdb.albums_as_dict() + albums = photosdb.albums_as_dict assert albums["Pumpkin Farm"] == 3 assert albums == ALBUM_DICT diff --git a/tests/test_mojave_10_14_6.py b/tests/test_mojave_10_14_6.py index 3ceb0e88..c1a04d56 100644 --- a/tests/test_mojave_10_14_6.py +++ b/tests/test_mojave_10_14_6.py @@ -45,8 +45,8 @@ def test_db_version(): import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - assert photosdb.get_db_version() in osxphotos._constants._TESTED_DB_VERSIONS - assert photosdb.get_db_version() == "4025" + assert photosdb.db_version in osxphotos._constants._TESTED_DB_VERSIONS + assert photosdb.db_version == "4025" def test_os_version(): @@ -61,8 +61,8 @@ def test_persons(): import collections photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - assert "Katie" in photosdb.persons() - assert collections.Counter(PERSONS) == collections.Counter(photosdb.persons()) + assert "Katie" in photosdb.persons + assert collections.Counter(PERSONS) == collections.Counter(photosdb.persons) def test_keywords(): @@ -70,8 +70,8 @@ def test_keywords(): import collections photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - assert "wedding" in photosdb.keywords() - assert collections.Counter(KEYWORDS) == collections.Counter(photosdb.keywords()) + assert "wedding" in photosdb.keywords + assert collections.Counter(KEYWORDS) == collections.Counter(photosdb.keywords) def test_albums(): @@ -79,15 +79,15 @@ def test_albums(): import collections photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - assert "Pumpkin Farm" in photosdb.albums() - assert collections.Counter(ALBUMS) == collections.Counter(photosdb.albums()) + assert "Pumpkin Farm" in photosdb.albums + assert collections.Counter(ALBUMS) == collections.Counter(photosdb.albums) def test_keywords_dict(): import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - keywords = photosdb.keywords_as_dict() + keywords = photosdb.keywords_as_dict assert keywords["wedding"] == 2 assert keywords == KEYWORDS_DICT @@ -96,7 +96,7 @@ def test_persons_as_dict(): import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - persons = photosdb.persons_as_dict() + persons = photosdb.persons_as_dict assert persons["Maria"] == 1 assert persons == PERSONS_DICT @@ -105,7 +105,7 @@ def test_albums_as_dict(): import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - albums = photosdb.albums_as_dict() + albums = photosdb.albums_as_dict assert albums["Pumpkin Farm"] == 3 assert albums == ALBUM_DICT @@ -314,7 +314,7 @@ def test_get_db_path(): import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - db_path = photosdb.get_db_path() + db_path = photosdb.db_path assert db_path.endswith(PHOTOS_DB_PATH) @@ -322,5 +322,5 @@ def test_get_library_path(): import osxphotos photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) - lib_path = photosdb.get_library_path() + lib_path = photosdb.library_path assert lib_path.endswith(PHOTOS_LIBRARY_PATH)