Skip to content

Commit

Permalink
Merge branch '121-add-test-from-coverage' into 'release'
Browse files Browse the repository at this point in the history
test: add check_conf tests with different disparity range and interpolation...

See merge request 3d/PandoraBox/pandora2d!105
  • Loading branch information
lecontm committed May 31, 2024
2 parents 0f7f77c + c244bc4 commit 635005b
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 6 deletions.
59 changes: 59 additions & 0 deletions tests/unit_tests/test_check_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ class TestCheckInputSection:
Test check input section.
"""

@pytest.fixture()
def basic_estimation_cfg(self):
return {"estimation_method": "phase_cross_correlation"}

def test_check_nominal_case(self, correct_input_cfg) -> None:
assert check_configuration.check_input_section(correct_input_cfg)

Expand Down Expand Up @@ -150,6 +154,25 @@ def test_default_nodata(self, correct_input_cfg):
assert result["input"]["left"]["nodata"] == -9999
assert result["input"]["right"]["nodata"] == -9999

@pytest.mark.parametrize(
"estimation_config",
[
pytest.param(None, id="without esimation config"),
pytest.param("basic_estimation_cfg", id="with basic config"),
],
)
def test_check_nominal_case_with_estimation_config(self, correct_input_cfg, estimation_config, request):
"""Default estimation_config value : None or basic config."""
if estimation_config is not None:
estimation_config = request.getfixturevalue(estimation_config)
assert check_configuration.check_input_section(correct_input_cfg, estimation_config)

def test_estimation_config_without_disparity(self, correct_input_cfg, basic_estimation_cfg):
"""Default basic estimation config without disparity in user configuration."""
del correct_input_cfg["input"]["col_disparity"]
del correct_input_cfg["input"]["row_disparity"]
assert check_configuration.check_input_section(correct_input_cfg, basic_estimation_cfg)


class TestCheckPipelineSection:
"""Test check_pipeline_section."""
Expand Down Expand Up @@ -217,6 +240,42 @@ def test_multiband_pipeline(self, pandora2d_machine, left_rgb_path, right_rgb_pa
check_configuration.check_conf(cfg, pandora2d_machine)


class TestCheckConf:
"""Test check_conf method."""

def test_passes_with_good_disparity_range_and_interpolation_step(
self, correct_input_cfg, correct_pipeline, pandora2d_machine
):
"""
Test col_disparity & row_disparity range (=5) with interpolation step in user configuration
"""
user_cfg = {**correct_input_cfg, **correct_pipeline}
check_configuration.check_conf(user_cfg, pandora2d_machine)

@pytest.mark.parametrize(
["col_disparity", "row_disparity"],
[
pytest.param([0, 2], [-2, 2], id="col_disparity range too small"),
pytest.param([-2, 2], [1, 4], id="row_disparity range too small"),
pytest.param([0, 2], [1, 4], id="col_disparity & row_disparity range too small"),
],
)
def test_fails_with_wrong_disparity_range_and_interpolation_step(
self, correct_input_cfg, correct_pipeline, pandora2d_machine, col_disparity, row_disparity
):
"""
Test wrong col_disparity & row_disparity range with interpolation step in user configuration
"""
correct_input_cfg["input"]["col_disparity"] = col_disparity
correct_input_cfg["input"]["row_disparity"] = row_disparity
user_cfg = {**correct_input_cfg, **correct_pipeline}
with pytest.raises(ValueError) as err:
check_configuration.check_conf(user_cfg, pandora2d_machine)
assert (
"disparity range with a size < 5 are not allowed with interpolation refinement method" in err.value.args[0]
)


class TestCheckRoiSection:
"""Test check_roi_section."""

Expand Down
4 changes: 4 additions & 0 deletions tests/unit_tests/test_disparity.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def test_default_invalid_disparity(self):
result = disparity.Disparity({"disparity_method": "wta"})
assert result.cfg["invalid_disparity"] == -9999

def test_nan_invalid_disparity(self):
result = disparity.Disparity({"disparity_method": "wta", "invalid_disparity": "NaN"})
assert np.isnan(result.cfg["invalid_disparity"])


def test_margins():
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import importlib.util
import json_checker
import pytest
from pandora.matching_cost import AbstractMatchingCost
from pandora.margins import Margins

from pandora2d import matching_cost
Expand All @@ -48,14 +49,17 @@ def test_invalid_method():
class TestWindowSize:
"""Test window_size parameter values."""

def test_default_window_size(self):
result = matching_cost.MatchingCost({"matching_cost_method": "zncc", "step": [1, 1]})
@pytest.mark.parametrize("method", ["zncc", "sad", "ssd"])
def test_default_window_size(self, method):
result = matching_cost.MatchingCost({"matching_cost_method": method, "step": [1, 1]})

assert result.cfg["window_size"] == 5
assert result.cfg["window_size"] == AbstractMatchingCost._WINDOW_SIZE # pylint: disable=W0212 protected-access

def test_fails_with_invalid_window_size(self):
with pytest.raises(json_checker.core.exceptions.DictCheckerError):
matching_cost.MatchingCost({"matching_cost_method": "zncc", "window_size": -1})
@pytest.mark.parametrize("method", ["zncc", "sad", "ssd"])
def test_fails_with_invalid_window_size(self, method):
with pytest.raises(json_checker.core.exceptions.DictCheckerError) as err:
matching_cost.MatchingCost({"matching_cost_method": method, "window_size": -1})
assert "window_size" in err.value.args[0]


@pytest.mark.usefixtures("import_plugins")
Expand Down

0 comments on commit 635005b

Please sign in to comment.