Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
Knoten
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
aflab
astrogeology
Knoten
Commits
2a54c3fb
Commit
2a54c3fb
authored
Feb 29, 2024
by
Laura, Jason R
Browse files
Options
Downloads
Patches
Plain Diff
Proper mock_obj passing
parent
f3539f0f
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_csm.py
+16
-18
16 additions, 18 deletions
tests/test_csm.py
with
16 additions
and
18 deletions
tests/test_csm.py
+
16
−
18
View file @
2a54c3fb
...
@@ -6,6 +6,14 @@ from plio.io.io_gdal import GeoDataset
...
@@ -6,6 +6,14 @@ from plio.io.io_gdal import GeoDataset
import
csmapi
import
csmapi
from
knoten
import
csm
from
knoten
import
csm
@pytest.fixture
def
mock_dem
():
mock_dem
=
mock
.
MagicMock
(
spec_set
=
GeoDataset
)
mock_dem
.
no_data_value
=
10
mock_dem
.
read_array
.
return_value
=
[[
100
]]
mock_dem
.
latlon_to_pixel
.
return_value
=
(
0.5
,
0.5
)
return
mock_dem
@pytest.fixture
@pytest.fixture
def
mock_sensor
():
def
mock_sensor
():
mock_sensor
=
mock
.
MagicMock
(
spec
=
csmapi
.
RasterGM
)
mock_sensor
=
mock
.
MagicMock
(
spec
=
csmapi
.
RasterGM
)
...
@@ -28,16 +36,12 @@ def test_generate_ground_point_with_imagecoord(mock_sensor, pt):
...
@@ -28,16 +36,12 @@ def test_generate_ground_point_with_imagecoord(mock_sensor, pt):
mock_sensor
.
imageToGround
.
assert_called_once_with
(
pt
,
height
)
mock_sensor
.
imageToGround
.
assert_called_once_with
(
pt
,
height
)
@mock.patch.object
(
csm
,
'
get_radii
'
,
return_value
=
(
10
,
10
))
@mock.patch.object
(
csm
,
'
get_radii
'
,
return_value
=
(
10
,
10
))
@mock.patch
(
'
pyproj.transformer.Transformer.transform
'
,
return_value
=
(
0
,
0
,
0
))
@mock.patch.object
(
csm
,
'
_compute_intersection_distance
'
,
return_value
=
0
)
@mock.patch.object
(
csm
,
'
_compute_intersection_distance
'
,
return_value
=
0
)
def
test_generate_ground_point_with_dtm
(
mock_sensor
,
pt
,
_
):
@mock.patch
(
'
pyproj.transformer.Transformer.transform
'
,
return_value
=
(
0
,
0
,
0
))
# Passing the mock_dem fixture fails for some reason. The
def
test_generate_ground_point_with_dtm
(
mock_get_radii
,
# isinstance(obj, GeoDataset) check fails, causing the singldispath
mock_compute_intsesection
,
# to never dispatch to the func under test.
mock_pyproj_transformer
,
mock_dem
=
mock
.
MagicMock
(
spec_set
=
GeoDataset
)
mock_sensor
,
pt
,
mock_dem
):
mock_dem
.
no_data_value
=
10
mock_dem
.
read_array
.
return_value
=
[[
100
]]
mock_dem
.
latlon_to_pixel
.
return_value
=
(
0.5
,
0.5
)
csm
.
generate_ground_point
(
mock_dem
,
pt
,
mock_sensor
)
csm
.
generate_ground_point
(
mock_dem
,
pt
,
mock_sensor
)
# This call is mocked so that the intitial intersection and
# This call is mocked so that the intitial intersection and
# one iteration should occur. Therefore, the call count
# one iteration should occur. Therefore, the call count
...
@@ -48,16 +52,10 @@ from collections import namedtuple
...
@@ -48,16 +52,10 @@ from collections import namedtuple
@mock.patch.object
(
csm
,
'
get_radii
'
,
return_value
=
(
10
,
10
))
@mock.patch.object
(
csm
,
'
get_radii
'
,
return_value
=
(
10
,
10
))
@mock.patch
(
'
pyproj.transformer.Transformer.transform
'
,
return_value
=
(
0
,
0
,
0
))
@mock.patch
(
'
pyproj.transformer.Transformer.transform
'
,
return_value
=
(
0
,
0
,
0
))
def
test_generate_ground_point_with_dtm_ndv
(
mock_sensor
,
pt
):
def
test_generate_ground_point_with_dtm_ndv
(
mock_get_radii
,
# Passing the mock_dem fixture fails for some reason. The
mock_pyproj_transformer
,
# isinstance(obj, GeoDataset) check fails, causing the singldispath
mock_sensor
,
pt
,
mock_dem
):
# to never dispatch to the func under test.
mock_dem
=
mock
.
MagicMock
(
spec_set
=
GeoDataset
)
# If the no data value equals the height, this should raise a value error
mock_dem
.
no_data_value
=
100
mock_dem
.
no_data_value
=
100
mock_dem
.
read_array
.
return_value
=
[[
100
]]
mock_dem
.
latlon_to_pixel
.
return_value
=
(
0.5
,
0.5
)
with
pytest
.
raises
(
ValueError
):
with
pytest
.
raises
(
ValueError
):
csm
.
generate_ground_point
(
mock_dem
,
pt
,
mock_sensor
)
csm
.
generate_ground_point
(
mock_dem
,
pt
,
mock_sensor
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment