Updated a couple of tests to use pytest-mock

This commit is contained in:
Rhet Turnbull
2020-05-10 09:00:56 -07:00
parent 605d63aa4f
commit 397db0d72f
3 changed files with 15 additions and 12 deletions

View File

@@ -1,8 +1,9 @@
# Tests for osxphotos # # Tests for osxphotos #
## Running Tests ## ## Running Tests ##
Tests require pytest: Tests require pytest and pytest-mock:
`pip install pytest` `pip install pytest`
`pip install pytest-mock`
To run the tests, do the following from the main source folder: To run the tests, do the following from the main source folder:
`python -m pytest tests/` `python -m pytest tests/`

View File

@@ -106,16 +106,16 @@ def test_init4():
except: except:
pass pass
def test_init5(mocker):
def test_init5():
# test failed get_last_library_path # test failed get_last_library_path
import osxphotos import osxphotos
def bad_library(): def bad_library():
return None return None
# force get_last_library to return a bad path for testing # get_last_library actually in utils but need to patch it in photosdb because it's imported into photosdb
osxphotos.photosdb.get_last_library_path = bad_library # as: from .utils import get_last_library
mocker.patch("osxphotos.photosdb.get_last_library_path", new=bad_library)
with pytest.raises(Exception): with pytest.raises(Exception):
assert osxphotos.PhotosDB() assert osxphotos.PhotosDB()

View File

@@ -107,19 +107,21 @@ def test_init4():
pass pass
def test_init5(): def test_init5(mocker):
# test failed get_last_library_path # test failed get_last_library_path
import osxphotos import osxphotos
def bad_library(): def bad_library():
return None return None
# force get_last_library to return a bad path for testing # get_last_library actually in utils but need to patch it in photosdb because it's imported into photosdb
osxphotos.photosdb.get_last_library_path = bad_library # as: from .utils import get_last_library
mocker.patch("osxphotos.photosdb.get_last_library_path", new=bad_library)
with pytest.raises(Exception): with pytest.raises(Exception):
assert osxphotos.PhotosDB() assert osxphotos.PhotosDB()
def test_db_len(): def test_db_len():
import osxphotos import osxphotos