-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/servir-mekong/hydra-floods
- Loading branch information
Showing
4 changed files
with
148 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
"""Unit tests for geeutils.py.""" | ||
import pytest | ||
import unittest.mock as mock | ||
|
||
import ee | ||
import hydrafloods as hf | ||
|
||
|
||
def test_export_image_toAsset(): | ||
"""Test that the toAsset export gets called by default.""" | ||
# mock ee export functionality | ||
ee.batch.Export.image.toAsset = mock.MagicMock() | ||
ee.Image = mock.MagicMock() | ||
ee.Geometry = mock.MagicMock() | ||
# call export function | ||
hf.geeutils.export_image(ee.Image, ee.Geometry, 'assid', 'desc') | ||
# assert that the ee.export call within the function was called | ||
assert ee.batch.Export.image.toAsset.call_count == 1 | ||
|
||
|
||
def test_export_image_toDrive(): | ||
"""Test that the toDrive export gets called when specified.""" | ||
# mock ee export functionality | ||
ee.batch.Export.image.toDrive = mock.MagicMock() | ||
ee.Image = mock.MagicMock() | ||
ee.Geometry = mock.MagicMock() | ||
# call export function | ||
hf.geeutils.export_image(ee.Image, ee.Geometry, 'assid', 'desc', | ||
export_type='toDrive') | ||
# assert that the ee.export call within the function was called | ||
assert ee.batch.Export.image.toDrive.call_count == 1 | ||
|
||
|
||
def test_export_image_export_type_invalid_string(): | ||
"""Test ValueError for export_type.""" | ||
# mock ee export functionality | ||
ee.batch.Export.image.toAsset = mock.MagicMock() | ||
ee.Image = mock.MagicMock() | ||
ee.Geometry = mock.MagicMock() | ||
# call export function | ||
with pytest.raises(ValueError): | ||
hf.geeutils.export_image(ee.Image, ee.Geometry, 'assid', 'desc', | ||
export_type='invalid string') | ||
|
||
|
||
def test_export_image_export_type_invalid_type(): | ||
"""Test TypeError for export_type.""" | ||
# mock ee export functionality | ||
ee.batch.Export.image.toAsset = mock.MagicMock() | ||
ee.Image = mock.MagicMock() | ||
ee.Geometry = mock.MagicMock() | ||
# call export function | ||
with pytest.raises(TypeError): | ||
hf.geeutils.export_image(ee.Image, ee.Geometry, 'assid', 'desc', | ||
export_type=123) | ||
|
||
|
||
def test_export_image_folder_invalid_type(): | ||
"""Test TypeError for folder.""" | ||
# mock ee export functionality | ||
ee.batch.Export.image.toAsset = mock.MagicMock() | ||
ee.Image = mock.MagicMock() | ||
ee.Geometry = mock.MagicMock() | ||
# call export function | ||
with pytest.raises(TypeError): | ||
hf.geeutils.export_image(ee.Image, ee.Geometry, 'assid', 'desc', | ||
folder=123) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters