Tests for osxphotos
Running Tests
To set up a dev environment to work on osxphotos code or run tests follow these steps. This assumes you have python 3.7 or later installed. If you need to install python, you can do so with the XCode command lines tools (xcode-select --install) or from python.org.
git clone git@github.com:RhetTbull/osxphotos.gitcd osxphotospython3 -m venv venvsource venv/bin/activatepython3 -m pip install -r dev_requirements.txtpython3 -m pip install -e .
To run the tests, do the following from the main source folder:
python3 -m pytest tests/
- To run a specific test specify its name with the -k flag:
python3 -m pytest -k "test_export_cleanup"
Skipped Tests
A few tests will look for certain environment variables to determine if they should run.
Some of the export tests rely on photos in my local library and will look for OSXPHOTOS_TEST_EXPORT=1 to determine if they should run.
One test for locale does not run on GitHub's automated workflow and will look for OSXPHOTOS_TEST_LOCALE=1 to determine if it should be run. If you want to run this test, set the environment variable.
A couple of tests require interaction with Photos and configuring a specific test library. Currently these run only on Catalina. The tests must be specified by using a pytest flag. Only one of these interactive tests can be run at a time. The current flags are:
--addalbum: test --add-to-album options (pytest -vv tests/test_photosalbum_unicode.py tests/test_cli_add_to_album.py --addalbum)
--timewarp: test osxphotos timewarp
--test-import: test osxphotos import
--test-sync: test osxphotos sync
--test-add-locations: test osxphotos add-locations
--test-batch-edit: test osxphotos batch-edit
Test Photo Libraries
Important: The test code uses several test photo libraries created on various version of MacOS. If you need to inspect one of these or modify one for a test, make a copy of the library (for example, copy it to your ~/Pictures folder) then open the copy in Photos. Once done, copy the revised library back to the tests/ folder. If you do not do this, the Photos background process photoanalysisd will forever try to process the library resulting in updates to the database which will cause git to see changes to the file you didn't intend. I'm not aware of any way to disassociate photoanalysisd from the library once you've opened it in Photos.
Some of the "search_info" tests require data from my personal library on Catalina 10.15.7. The data is generated by running python3 tests/generate_search_info_test_data.py >tests/search_info_test_data_10_15_7.json
Attribution
These tests utilize a test Photos library. The test library is populated with photos from flickr and from my own photo library. All images used are licensed under Creative Commons 2.0 Attribution license.
Flickr images used from: