Updated a couple of tests to use pytest-mock
This commit is contained in:
@@ -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/`
|
||||||
|
|||||||
@@ -106,17 +106,17 @@ 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()
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user