From c86d1ea3d50f9b189776bad62dacf02d290c8121 Mon Sep 17 00:00:00 2001 From: Vincent Jilesen Date: Thu, 20 Aug 2026 14:36:20 +0200 Subject: [PATCH 01/15] _specify_w in traject_parameters.py --- .../general/test_traject_parameters.py | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/cmd_app/general/test_traject_parameters.py diff --git a/tests/cmd_app/general/test_traject_parameters.py b/tests/cmd_app/general/test_traject_parameters.py new file mode 100644 index 00000000..d649d7f7 --- /dev/null +++ b/tests/cmd_app/general/test_traject_parameters.py @@ -0,0 +1,59 @@ +from unittest.mock import Mock + +import pytest + +from geoprob_pipe.cmd_app.general.traject_parameters import _specify_w + + +@pytest.mark.parametrize( + "input_value, verwachte_tekst", + [ + ("", "geen w gespecificeerd"), + ("abc", "geen decimaal getal"), + ("1.5", "groter dan 1.0"), + ("0", "kleiner of gelijk aan 0.0"), + ("-1", "kleiner of gelijk aan 0.0"), + ], +) +def test_specify_w_validaties( + monkeypatch, + capsys, + input_value, + verwachte_tekst, +): + app_settings = Mock() + + antwoorden = iter([input_value, "0.24"]) + + prompt_mock = Mock() + prompt_mock.execute.side_effect = lambda: next(antwoorden) + + text_mock = Mock(return_value=prompt_mock) + + monkeypatch.setattr( + "InquirerPy.inquirer.text", + text_mock, + ) + + append_mock = Mock() + monkeypatch.setattr( + "geoprob_pipe.cmd_app.general.traject_parameters._append_to_db", + append_mock, + ) + + _specify_w(app_settings) + + captured = capsys.readouterr() + + # juiste foutmelding getoond + assert verwachte_tekst in captured.out + + # eerst fout, daarna geldige invoer + assert prompt_mock.execute.call_count == 2 + + # waarde opgeslagen + append_mock.assert_called_once_with( + app_settings=app_settings, + key="w", + value=0.24, + ) From 4e46fabba5a63bb61e2b1a931eb35eb86e6583d2 Mon Sep 17 00:00:00 2001 From: Vincent Jilesen Date: Thu, 20 Aug 2026 14:49:15 +0200 Subject: [PATCH 02/15] create_project in project.py --- tests/cmd_app/general/test_project.py | 83 +++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 tests/cmd_app/general/test_project.py diff --git a/tests/cmd_app/general/test_project.py b/tests/cmd_app/general/test_project.py new file mode 100644 index 00000000..4531f5ea --- /dev/null +++ b/tests/cmd_app/general/test_project.py @@ -0,0 +1,83 @@ +from unittest.mock import Mock + +import pytest + +import geoprob_pipe.cmd_app.general.project as module + + +@pytest.mark.parametrize( + "choice,function_name", + [ + ( + "Bestaand project openen", + "specify_path_to_existing_project", + ), + ( + "Nieuw project starten", + "specify_dir_for_new_project", + ), + ] +) +def test_created_project_happy_flows( + monkeypatch, + choice, + function_name, +): + app_settings = Mock() + + prompt_mock = Mock() + prompt_mock.execute.return_value = choice + + monkeypatch.setattr( + "InquirerPy.inquirer.select", + Mock(return_value=prompt_mock) + ) + + action_mock = Mock() + logging_mock = Mock() + + monkeypatch.setattr( + module, + function_name, + action_mock, + ) + + monkeypatch.setattr( + module, + "enable_geopackage_logging", + logging_mock, + ) + + result = module.created_project(app_settings) + + assert result is True + + action_mock.assert_called_once_with(app_settings) + + logging_mock.assert_called_once_with( + app_settings=app_settings + ) + + +def test_created_project_compare(monkeypatch): + prompt_mock = Mock() + prompt_mock.execute.return_value = ( + "Twee projectbestanden vergelijken" + ) + + monkeypatch.setattr( + "InquirerPy.inquirer.select", + Mock(return_value=prompt_mock) + ) + + compare_mock = Mock() + monkeypatch.setattr( + module, + "start_comparison", + compare_mock + ) + + with pytest.raises(SystemExit, match="Applicatie afgesloten"): + module.created_project(Mock()) + + compare_mock.assert_called_once() \ No newline at end of file From a4f93c84545ebe3dd26e3b1722c071f44cfeb40d Mon Sep 17 00:00:00 2001 From: Vincent Jilesen Date: Thu, 20 Aug 2026 14:56:28 +0200 Subject: [PATCH 03/15] added_binnenteenlijn --- .../general/test_traject_parameters.py | 2 +- .../test_added_binnenteenlijn.py | 67 +++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 tests/cmd_app/spatial_layers/test_added_binnenteenlijn.py diff --git a/tests/cmd_app/general/test_traject_parameters.py b/tests/cmd_app/general/test_traject_parameters.py index d649d7f7..3b69fc35 100644 --- a/tests/cmd_app/general/test_traject_parameters.py +++ b/tests/cmd_app/general/test_traject_parameters.py @@ -15,7 +15,7 @@ ("-1", "kleiner of gelijk aan 0.0"), ], ) -def test_specify_w_validaties( +def test_specify_w_validations( monkeypatch, capsys, input_value, diff --git a/tests/cmd_app/spatial_layers/test_added_binnenteenlijn.py b/tests/cmd_app/spatial_layers/test_added_binnenteenlijn.py new file mode 100644 index 00000000..ca02411f --- /dev/null +++ b/tests/cmd_app/spatial_layers/test_added_binnenteenlijn.py @@ -0,0 +1,67 @@ +from unittest.mock import Mock + +import geoprob_pipe.cmd_app.spatial_layers.binnenteenlijn as module + + +def test_added_binnenteenlijn_already_included( + monkeypatch, + capsys, +): + app_settings = Mock() + app_settings.geopackage_filepath = "dummy.gpkg" + + monkeypatch.setattr( + module.fiona, + "listlayers", + Mock(return_value=[ + "trajectlijn", + "binnenteenlijn", + "vakindeling", + ]), + ) + + request_mock = Mock() + monkeypatch.setattr( + module, + "request_binnenteenlijn_filepath", + request_mock, + ) + + result = module.added_binnenteenlijn(app_settings) + + assert result is True + + request_mock.assert_not_called() + + captured = capsys.readouterr() + assert "Binnenteenlijn al toegevoegd" in captured.out + +def test_added_binnenteenlijn_not_yet_included( + monkeypatch, +): + app_settings = Mock() + app_settings.geopackage_filepath = "dummy.gpkg" + + monkeypatch.setattr( + module.fiona, + "listlayers", + Mock(return_value=[ + "trajectlijn", + "vakindeling", + ]), + ) + + request_mock = Mock() + monkeypatch.setattr( + module, + "request_binnenteenlijn_filepath", + request_mock, + ) + + result = module.added_binnenteenlijn(app_settings) + + assert result is True + + request_mock.assert_called_once_with( + app_settings=app_settings + ) \ No newline at end of file From 87bf59a1d04b4354dade846fb3010c038069b99a Mon Sep 17 00:00:00 2001 From: Vincent Jilesen Date: Thu, 20 Aug 2026 15:07:16 +0200 Subject: [PATCH 04/15] rename --- tests/cmd_app/general/test_project.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cmd_app/general/test_project.py b/tests/cmd_app/general/test_project.py index 4531f5ea..ab4235fe 100644 --- a/tests/cmd_app/general/test_project.py +++ b/tests/cmd_app/general/test_project.py @@ -18,7 +18,7 @@ ), ] ) -def test_created_project_happy_flows( +def test_created_project_happy_paths( monkeypatch, choice, function_name, From 74aea98c8c1a936ba9b6a06554c10eccb19f9673 Mon Sep 17 00:00:00 2001 From: Vincent Jilesen Date: Thu, 20 Aug 2026 15:16:55 +0200 Subject: [PATCH 05/15] cleanup --- tests/cmd_app/general/test_project.py | 6 +++-- .../general/test_traject_parameters.py | 25 ++++++++++--------- .../test_added_binnenteenlijn.py | 4 +-- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/tests/cmd_app/general/test_project.py b/tests/cmd_app/general/test_project.py index ab4235fe..4b453f4f 100644 --- a/tests/cmd_app/general/test_project.py +++ b/tests/cmd_app/general/test_project.py @@ -22,7 +22,7 @@ def test_created_project_happy_paths( monkeypatch, choice, function_name, -): +) -> None: app_settings = Mock() prompt_mock = Mock() @@ -50,8 +50,10 @@ def test_created_project_happy_paths( result = module.created_project(app_settings) + # Path reaches return assert result is True + # Functions were called action_mock.assert_called_once_with(app_settings) logging_mock.assert_called_once_with( @@ -59,7 +61,7 @@ def test_created_project_happy_paths( ) -def test_created_project_compare(monkeypatch): +def test_created_project_compare(monkeypatch) -> None: prompt_mock = Mock() prompt_mock.execute.return_value = ( "Twee projectbestanden vergelijken" diff --git a/tests/cmd_app/general/test_traject_parameters.py b/tests/cmd_app/general/test_traject_parameters.py index 3b69fc35..c29b22c3 100644 --- a/tests/cmd_app/general/test_traject_parameters.py +++ b/tests/cmd_app/general/test_traject_parameters.py @@ -2,11 +2,11 @@ import pytest -from geoprob_pipe.cmd_app.general.traject_parameters import _specify_w +import geoprob_pipe.cmd_app.general.traject_parameters as module @pytest.mark.parametrize( - "input_value, verwachte_tekst", + "input_value, expected_answer", [ ("", "geen w gespecificeerd"), ("abc", "geen decimaal getal"), @@ -19,14 +19,14 @@ def test_specify_w_validations( monkeypatch, capsys, input_value, - verwachte_tekst, -): + expected_answer, +) -> None: app_settings = Mock() - antwoorden = iter([input_value, "0.24"]) + answers = iter([input_value, "0.24"]) prompt_mock = Mock() - prompt_mock.execute.side_effect = lambda: next(antwoorden) + prompt_mock.execute.side_effect = lambda: next(answers) text_mock = Mock(return_value=prompt_mock) @@ -37,21 +37,22 @@ def test_specify_w_validations( append_mock = Mock() monkeypatch.setattr( - "geoprob_pipe.cmd_app.general.traject_parameters._append_to_db", + module, + "_append_to_db", append_mock, ) - _specify_w(app_settings) + module._specify_w(app_settings) captured = capsys.readouterr() - # juiste foutmelding getoond - assert verwachte_tekst in captured.out + # correct respons + assert expected_answer in captured.out - # eerst fout, daarna geldige invoer + # correct value after invalid value assert prompt_mock.execute.call_count == 2 - # waarde opgeslagen + # value stored correctly append_mock.assert_called_once_with( app_settings=app_settings, key="w", diff --git a/tests/cmd_app/spatial_layers/test_added_binnenteenlijn.py b/tests/cmd_app/spatial_layers/test_added_binnenteenlijn.py index ca02411f..4c23be56 100644 --- a/tests/cmd_app/spatial_layers/test_added_binnenteenlijn.py +++ b/tests/cmd_app/spatial_layers/test_added_binnenteenlijn.py @@ -6,7 +6,7 @@ def test_added_binnenteenlijn_already_included( monkeypatch, capsys, -): +) -> None: app_settings = Mock() app_settings.geopackage_filepath = "dummy.gpkg" @@ -58,7 +58,7 @@ def test_added_binnenteenlijn_not_yet_included( request_mock, ) - result = module.added_binnenteenlijn(app_settings) + result: bool = module.added_binnenteenlijn(app_settings) assert result is True From 6177e0d86005a862a3c80c5cd021e285c9d4390b Mon Sep 17 00:00:00 2001 From: Vincent Jilesen Date: Fri, 21 Aug 2026 09:01:07 +0200 Subject: [PATCH 06/15] Test documentatie --- tests/cmd_app/general/test_project.py | 79 +++++++++++++------ .../general/test_traject_parameters.py | 19 +++-- ...nnenteenlijn.py => test_binnenteenlijn.py} | 21 ++++- 3 files changed, 85 insertions(+), 34 deletions(-) rename tests/cmd_app/spatial_layers/{test_added_binnenteenlijn.py => test_binnenteenlijn.py} (71%) diff --git a/tests/cmd_app/general/test_project.py b/tests/cmd_app/general/test_project.py index 4b453f4f..5177ceef 100644 --- a/tests/cmd_app/general/test_project.py +++ b/tests/cmd_app/general/test_project.py @@ -16,32 +16,31 @@ "Nieuw project starten", "specify_dir_for_new_project", ), - ] + ], ) def test_created_project_happy_paths( monkeypatch, choice, function_name, ) -> None: + """Test of the paths are correctly completed.""" + # Mock input arguments app_settings = Mock() + # Mock assigned function calls prompt_mock = Mock() prompt_mock.execute.return_value = choice - monkeypatch.setattr( - "InquirerPy.inquirer.select", - Mock(return_value=prompt_mock) - ) + monkeypatch.setattr("InquirerPy.inquirer.select", Mock(return_value=prompt_mock)) + # Mock called functions action_mock = Mock() - logging_mock = Mock() - monkeypatch.setattr( module, function_name, action_mock, ) - + logging_mock = Mock() monkeypatch.setattr( module, "enable_geopackage_logging", @@ -50,36 +49,66 @@ def test_created_project_happy_paths( result = module.created_project(app_settings) - # Path reaches return + # Check path reaches return assert result is True - # Functions were called + # Check functions were called once with correct arguments action_mock.assert_called_once_with(app_settings) - logging_mock.assert_called_once_with( - app_settings=app_settings - ) - + logging_mock.assert_called_once_with(app_settings=app_settings) + def test_created_project_compare(monkeypatch) -> None: + """ "Test start compare function.""" + # Mock assigned function calls prompt_mock = Mock() - prompt_mock.execute.return_value = ( - "Twee projectbestanden vergelijken" - ) + prompt_mock.execute.return_value = "Twee projectbestanden vergelijken" + monkeypatch.setattr("InquirerPy.inquirer.select", Mock(return_value=prompt_mock)) + # Mock called functions + compare_mock = Mock() + monkeypatch.setattr(module, "start_comparison", compare_mock) + + # While capturing the sysexit() run the function + with pytest.raises(SystemExit, match="Applicatie afgesloten"): + module.created_project(Mock()) + + # Check function call + compare_mock.assert_called_once() + + +def test_created_project_single_calc(monkeypatch) -> None: + # Mock assigned function calls + prompt_mock = Mock() + prompt_mock.execute.return_value = "Inspecteer een enkele berekening" + monkeypatch.setattr("InquirerPy.inquirer.select", Mock(return_value=prompt_mock)) + + # Mock called functions + panel_instance = Mock() + panel_mock = Mock(return_value=panel_instance) monkeypatch.setattr( - "InquirerPy.inquirer.select", - Mock(return_value=prompt_mock) + module, + "Panel", + panel_mock, ) - - compare_mock = Mock() + console_instance = Mock() + console_mock = Mock(return_value=console_instance) monkeypatch.setattr( module, - "start_comparison", - compare_mock + "Console", + console_mock, ) - + # While capturing the sysexit() run the function with pytest.raises(SystemExit, match="Applicatie afgesloten"): module.created_project(Mock()) - compare_mock.assert_called_once() \ No newline at end of file + # Check Panel construction + panel_mock.assert_called_once_with( + module.EXPLANATION_REPRODUCING_SINGLE_CALCULATION, + title="INSPECTEER EEN ENKELE BEREKENING", + title_align="left", + border_style="bright_blue", + padding=(0, 2), + ) + # Check print call + console_instance.print.assert_called_once_with(panel_instance) diff --git a/tests/cmd_app/general/test_traject_parameters.py b/tests/cmd_app/general/test_traject_parameters.py index c29b22c3..61615a87 100644 --- a/tests/cmd_app/general/test_traject_parameters.py +++ b/tests/cmd_app/general/test_traject_parameters.py @@ -21,12 +21,16 @@ def test_specify_w_validations( input_value, expected_answer, ) -> None: + """Test for all branches of validation and correct storage of user input.""" + # Mock input arguments app_settings = Mock() - answers = iter([input_value, "0.24"]) + # Setup user inputs + user_inputs = iter([input_value, "0.24"]) + # Mock assigned function calls prompt_mock = Mock() - prompt_mock.execute.side_effect = lambda: next(answers) + prompt_mock.execute.side_effect = lambda: next(user_inputs) text_mock = Mock(return_value=prompt_mock) @@ -35,6 +39,7 @@ def test_specify_w_validations( text_mock, ) + # Mock called functions append_mock = Mock() monkeypatch.setattr( module, @@ -42,19 +47,19 @@ def test_specify_w_validations( append_mock, ) + # Run tested function: module._specify_w(app_settings) + # Check correct message printed captured = capsys.readouterr() - - # correct respons assert expected_answer in captured.out - # correct value after invalid value + # Check continue loop assert prompt_mock.execute.call_count == 2 - # value stored correctly + # Check accepted value stored correctly append_mock.assert_called_once_with( app_settings=app_settings, key="w", - value=0.24, + value=0.24, # as a float ) diff --git a/tests/cmd_app/spatial_layers/test_added_binnenteenlijn.py b/tests/cmd_app/spatial_layers/test_binnenteenlijn.py similarity index 71% rename from tests/cmd_app/spatial_layers/test_added_binnenteenlijn.py rename to tests/cmd_app/spatial_layers/test_binnenteenlijn.py index 4c23be56..07caf777 100644 --- a/tests/cmd_app/spatial_layers/test_added_binnenteenlijn.py +++ b/tests/cmd_app/spatial_layers/test_binnenteenlijn.py @@ -7,9 +7,12 @@ def test_added_binnenteenlijn_already_included( monkeypatch, capsys, ) -> None: + """Test case `binnenteenlijn` already added to gpkg.""" + # Mock input arguments app_settings = Mock() app_settings.geopackage_filepath = "dummy.gpkg" + # Monkey patch assigned function calls monkeypatch.setattr( module.fiona, "listlayers", @@ -20,6 +23,7 @@ def test_added_binnenteenlijn_already_included( ]), ) + # Mock called module fuctions request_mock = Mock() monkeypatch.setattr( module, @@ -27,21 +31,30 @@ def test_added_binnenteenlijn_already_included( request_mock, ) + # Run tested function: result = module.added_binnenteenlijn(app_settings) + # Check expected return assert result is True - request_mock.assert_not_called() - + # Check correct message printed captured = capsys.readouterr() assert "Binnenteenlijn al toegevoegd" in captured.out + # Check function in other branch not called + request_mock.assert_not_called() + + + def test_added_binnenteenlijn_not_yet_included( monkeypatch, ): + """Test case `binnenteenlijn` not yet added to gpkg.""" + # Mock input argument(s) app_settings = Mock() app_settings.geopackage_filepath = "dummy.gpkg" + # Monkey patch assigned function call(s) monkeypatch.setattr( module.fiona, "listlayers", @@ -51,6 +64,7 @@ def test_added_binnenteenlijn_not_yet_included( ]), ) + # Mock called module fuction(s) request_mock = Mock() monkeypatch.setattr( module, @@ -58,10 +72,13 @@ def test_added_binnenteenlijn_not_yet_included( request_mock, ) + # Run tested function: result: bool = module.added_binnenteenlijn(app_settings) + # Check expected return assert result is True + # Check function call with correct argument request_mock.assert_called_once_with( app_settings=app_settings ) \ No newline at end of file From 8d9bc12f43c004fbe0373de585b1702c54fbc06a Mon Sep 17 00:00:00 2001 From: Vincent Jilesen Date: Fri, 21 Aug 2026 09:22:18 +0200 Subject: [PATCH 07/15] docu --- tests/cmd_app/general/test_project.py | 7 +++++++ tests/cmd_app/general/test_traject_parameters.py | 7 +++++++ tests/cmd_app/spatial_layers/test_binnenteenlijn.py | 9 ++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/cmd_app/general/test_project.py b/tests/cmd_app/general/test_project.py index 5177ceef..243d68cc 100644 --- a/tests/cmd_app/general/test_project.py +++ b/tests/cmd_app/general/test_project.py @@ -1,3 +1,9 @@ +""" +Unit tests for `geoprob_pipe.cmd_app.general.project.py`. +Tests performed for: + - created_project(app_settings: ApplicationSettings) -> bool +""" + from unittest.mock import Mock import pytest @@ -5,6 +11,7 @@ import geoprob_pipe.cmd_app.general.project as module +# --- created_project(app_settings: ApplicationSettings) -> bool --- @pytest.mark.parametrize( "choice,function_name", [ diff --git a/tests/cmd_app/general/test_traject_parameters.py b/tests/cmd_app/general/test_traject_parameters.py index 61615a87..48d3cf32 100644 --- a/tests/cmd_app/general/test_traject_parameters.py +++ b/tests/cmd_app/general/test_traject_parameters.py @@ -1,3 +1,9 @@ +""" +Unit tests for `geoprob_pipe.cmd_app.general.traject_parameters.py`. +Tests performed for: + - _specify_w(app_settings: ApplicationSettings) +""" + from unittest.mock import Mock import pytest @@ -5,6 +11,7 @@ import geoprob_pipe.cmd_app.general.traject_parameters as module +# --- _specify_w(app_settings: ApplicationSettings) --- @pytest.mark.parametrize( "input_value, expected_answer", [ diff --git a/tests/cmd_app/spatial_layers/test_binnenteenlijn.py b/tests/cmd_app/spatial_layers/test_binnenteenlijn.py index 07caf777..77aef18f 100644 --- a/tests/cmd_app/spatial_layers/test_binnenteenlijn.py +++ b/tests/cmd_app/spatial_layers/test_binnenteenlijn.py @@ -1,8 +1,15 @@ +""" +Unit tests for `geoprob_pipe.cmd_app.spatial_layers.binnenteenlijn.py`. +Tests performed for: + - added_binnenteenlijn(app_settings: ApplicationSettings) -> bool +""" + from unittest.mock import Mock import geoprob_pipe.cmd_app.spatial_layers.binnenteenlijn as module +# --- added_binnenteenlijn(app_settings: ApplicationSettings) -> bool --- def test_added_binnenteenlijn_already_included( monkeypatch, capsys, @@ -48,7 +55,7 @@ def test_added_binnenteenlijn_already_included( def test_added_binnenteenlijn_not_yet_included( monkeypatch, -): +) -> None: """Test case `binnenteenlijn` not yet added to gpkg.""" # Mock input argument(s) app_settings = Mock() From 6a2765d51edb4d41421f7253931624ddd90d9876 Mon Sep 17 00:00:00 2001 From: Vincent Jilesen Date: Fri, 21 Aug 2026 09:33:09 +0200 Subject: [PATCH 08/15] typing --- tests/cmd_app/general/test_project.py | 12 +++++++----- tests/cmd_app/general/test_traject_parameters.py | 4 ++-- tests/cmd_app/spatial_layers/test_binnenteenlijn.py | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/cmd_app/general/test_project.py b/tests/cmd_app/general/test_project.py index 243d68cc..c384f4e5 100644 --- a/tests/cmd_app/general/test_project.py +++ b/tests/cmd_app/general/test_project.py @@ -27,8 +27,8 @@ ) def test_created_project_happy_paths( monkeypatch, - choice, - function_name, + choice: str, + function_name: str, ) -> None: """Test of the paths are correctly completed.""" # Mock input arguments @@ -54,7 +54,7 @@ def test_created_project_happy_paths( logging_mock, ) - result = module.created_project(app_settings) + result: bool = module.created_project(app_settings) # Check path reaches return assert result is True @@ -69,7 +69,8 @@ def test_created_project_compare(monkeypatch) -> None: """ "Test start compare function.""" # Mock assigned function calls prompt_mock = Mock() - prompt_mock.execute.return_value = "Twee projectbestanden vergelijken" + choice: str = "Twee projectbestanden vergelijken" + prompt_mock.execute.return_value = choice monkeypatch.setattr("InquirerPy.inquirer.select", Mock(return_value=prompt_mock)) # Mock called functions @@ -87,7 +88,8 @@ def test_created_project_compare(monkeypatch) -> None: def test_created_project_single_calc(monkeypatch) -> None: # Mock assigned function calls prompt_mock = Mock() - prompt_mock.execute.return_value = "Inspecteer een enkele berekening" + choice: str = "Inspecteer een enkele berekening" + prompt_mock.execute.return_value = choice monkeypatch.setattr("InquirerPy.inquirer.select", Mock(return_value=prompt_mock)) # Mock called functions diff --git a/tests/cmd_app/general/test_traject_parameters.py b/tests/cmd_app/general/test_traject_parameters.py index 48d3cf32..5570bba2 100644 --- a/tests/cmd_app/general/test_traject_parameters.py +++ b/tests/cmd_app/general/test_traject_parameters.py @@ -25,8 +25,8 @@ def test_specify_w_validations( monkeypatch, capsys, - input_value, - expected_answer, + input_value: str, + expected_answer: str, ) -> None: """Test for all branches of validation and correct storage of user input.""" # Mock input arguments diff --git a/tests/cmd_app/spatial_layers/test_binnenteenlijn.py b/tests/cmd_app/spatial_layers/test_binnenteenlijn.py index 77aef18f..353613bf 100644 --- a/tests/cmd_app/spatial_layers/test_binnenteenlijn.py +++ b/tests/cmd_app/spatial_layers/test_binnenteenlijn.py @@ -39,7 +39,7 @@ def test_added_binnenteenlijn_already_included( ) # Run tested function: - result = module.added_binnenteenlijn(app_settings) + result: bool = module.added_binnenteenlijn(app_settings) # Check expected return assert result is True From a765a8e86b8a43a2e20a9884e4e976871a040191 Mon Sep 17 00:00:00 2001 From: Vincent Jilesen Date: Fri, 21 Aug 2026 10:55:38 +0200 Subject: [PATCH 09/15] assemblage_functions mostly covered --- tests/cmd_app/general/__init__.py | 0 tests/results/__init__.py | 0 tests/results/assemblage/__init__.py | 0 tests/results/assemblage/test_assemblage.py | 59 ------ tests/results/assemblage/test_functions.py | 193 ++++++++++++++++++++ tests/test_system.py | 48 ++--- 6 files changed, 217 insertions(+), 83 deletions(-) create mode 100644 tests/cmd_app/general/__init__.py create mode 100644 tests/results/__init__.py create mode 100644 tests/results/assemblage/__init__.py delete mode 100644 tests/results/assemblage/test_assemblage.py create mode 100644 tests/results/assemblage/test_functions.py diff --git a/tests/cmd_app/general/__init__.py b/tests/cmd_app/general/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/results/__init__.py b/tests/results/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/results/assemblage/__init__.py b/tests/results/assemblage/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/results/assemblage/test_assemblage.py b/tests/results/assemblage/test_assemblage.py deleted file mode 100644 index 976378b1..00000000 --- a/tests/results/assemblage/test_assemblage.py +++ /dev/null @@ -1,59 +0,0 @@ -from geoprob_pipe.results.assemblage.functions import combine_series -from geoprob_pipe.results.assemblage.functions import window_collect -from geoprob_pipe.results.assemblage.functions import scaled_collect -from geoprob_pipe.results.assemblage.objects import UittredepuntElement -import pytest - - -def test_combine(): - """Test combining very small floats. - """ - pfs = [1.123e-17, 3.78e-15, 6.7e-15] - sum_pf, max_pf = combine_series(pfs) - assert sum_pf == pytest.approx(1.049123e-14) - assert max_pf == pytest.approx(6.7e-15) - - -def test_window(): - """Test window on selecting max in window and combining. - """ - list_dsn = [ - UittredepuntElement(m_value=11, a=0.9, converged=True, pf=1e-12, - flow_chart_number=11, advise="-"), - UittredepuntElement(m_value=12, a=0.9, converged=True, pf=2e-13, - flow_chart_number=11, advise="-"), - UittredepuntElement(m_value=20, a=0.9, converged=True, pf=7.5e-13, - flow_chart_number=11, advise="-"), - UittredepuntElement(m_value=30, a=0.9, converged=True, pf=3e-14, - flow_chart_number=11, advise="-") - ] - sum_pf, max_pf, elements = window_collect( - window_size=10, point_list=list_dsn, - m_van=0, m_tot=40 - ) - assert sum_pf == pytest.approx(1.78e-12) - assert max_pf == pytest.approx(1e-12) - assert elements.__len__() == 4 - assert elements[0].kans_dsn.pf == 0.0 - - -def test_scaled(): - """Test scaled on taking max in cluster and combining. - """ - list_dsn = [ - UittredepuntElement(m_value=11, a=0.9, converged=True, pf=1e-12, - flow_chart_number=11, advise="-"), - UittredepuntElement(m_value=12, a=0.9, converged=True, pf=2e-13, - flow_chart_number=11, advise="-"), - UittredepuntElement(m_value=20, a=0.9, converged=True, pf=7.5e-13, - flow_chart_number=11, advise="-"), - UittredepuntElement(m_value=30, a=0.9, converged=True, pf=3e-14, - flow_chart_number=11, advise="-") - ] - sum_pf, max_pf, elements = scaled_collect( - dL=200, point_list=list_dsn, - m_van=0, m_tot=50 - ) - assert sum_pf == pytest.approx(1.78e-12) - assert max_pf == pytest.approx(1e-12) - assert elements.__len__() == 3 diff --git a/tests/results/assemblage/test_functions.py b/tests/results/assemblage/test_functions.py new file mode 100644 index 00000000..85b2ac34 --- /dev/null +++ b/tests/results/assemblage/test_functions.py @@ -0,0 +1,193 @@ +import pytest + +import geoprob_pipe.results.assemblage.functions as functions +import geoprob_pipe.results.assemblage.objects as objects + + +@pytest.fixture +def uittredepunten() -> list[objects.UittredepuntElement]: + return [ + objects.UittredepuntElement( + m_value=11, + a=0.9, + converged=True, + pf=1e-12, + flow_chart_number=11, + advise="-", + ), + objects.UittredepuntElement( + m_value=12, + a=0.9, + converged=True, + pf=2e-13, + flow_chart_number=11, + advise="-", + ), + objects.UittredepuntElement( + m_value=20, + a=0.9, + converged=True, + pf=7.5e-13, + flow_chart_number=11, + advise="-", + ), + objects.UittredepuntElement( + m_value=30, + a=0.9, + converged=True, + pf=3e-14, + flow_chart_number=11, + advise="-", + ), + ] + + +def test_combine_series_with_small_probabilities() -> None: + """Check addition of very small probabilities""" + + # Arrange + pfs: list[float] = [1.123e-17, 3.78e-15, 6.7e-15] + + # Act + sum_pf: float + max_pf: float + sum_pf, max_pf = functions.combine_series(pfs) + + # Assert + assert sum_pf == pytest.approx(1.049123e-14) + assert max_pf == pytest.approx(6.7e-15) + + +def test_combine_series_empty_list() -> None: + """Assert correct return on input of empty list.""" + # Arrange + pfs: list[float] = [] + + # Act + sum_pf: float + max_pf: float + sum_pf, max_pf = functions.combine_series(pfs) + + # Assert + assert sum_pf == 0.0 + assert max_pf == 0.0 + + +@pytest.mark.parametrize( + "L, a, dL, expected", + [ + (100.0, 0.5, 20.0, 2.5), # larger than 1 + (10.0, 0.5, 20.0, 1.0), # minimum = 1 + (20.0, 1.0, 20.0, 1.0), # exact 1 + (200.0, 0.8, 40.0, 4.0), # normal case + ], +) +def test_bepaal_N_vak(L: float, a: float, dL: float, expected: float) -> None: + """Controleer correcte calculation of N_vak.""" + result = functions.bepaal_N_vak(L=L, a=a, dL=dL) + + assert result == pytest.approx(expected) + + +@pytest.mark.parametrize( + "a", + [-0.1, -1.0, -100.0], +) +def test_bepaal_N_vak_raises_for_negative_a(a: float) -> None: + """Assert that a negative value of a raise a ValueError""" + with pytest.raises(ValueError, match="a moet groter zijn dan 0"): + functions.bepaal_N_vak(L=100.0, a=a, dL=20.0) + + +@pytest.mark.parametrize( + "L, dL", + [ + (-1.0, 20.0), + (100.0, -20.0), + (-1.0, -20.0), + ], +) +def test_bepaal_N_vak_raises_for_negative_lengths(L: float, dL: float) -> None: + """Assert that negative values for L and dL raise a ValueError.""" + with pytest.raises( + ValueError, + match="De lengte L en dL moeten groter zijn dan 0", + ): + functions.bepaal_N_vak(L=L, a=0.5, dL=dL) + + +def test_window_collect_returns_expected_values(uittredepunten) -> None: + """Check selection inside windows and combined probability.""" + + # Act + sum_pf: float + max_pf: float + elements: list[objects.WindowElement] + sum_pf, max_pf, elements = functions.window_collect( + window_size=10, + point_list=uittredepunten, + m_van=0, + m_tot=40, + ) + + # Assert + assert sum_pf == pytest.approx(1.78e-12) + assert max_pf == pytest.approx(1e-12) + assert len(elements) == 4 + assert elements[0].kans_dsn.pf == pytest.approx(0.0) + + +def test_window_collect_empty_list() -> None: + # Act + sum_pf: float + max_pf: float + elements: list[objects.WindowElement] + sum_pf, max_pf, elements = functions.window_collect( + window_size=10, + point_list=[], + m_van=0, + m_tot=50, + ) + + # Assert + assert sum_pf == 0.0 + assert max_pf == 0.0 + assert len(elements) == 0 + + +def test_scaled_collect_returns_expected_values(uittredepunten) -> None: + """Check clustering, scale factor en combined probability.""" + + # Act + sum_pf: float + max_pf: float + elements: list[objects.WindowElement] + sum_pf, max_pf, elements = functions.scaled_collect( + dL=200, + point_list=uittredepunten, + m_van=0, + m_tot=50, + ) + + # Assert + assert sum_pf == pytest.approx(1.78e-12) + assert max_pf == pytest.approx(1e-12) + assert len(elements) == 3 + + +def test_scaled_collect_empty_list() -> None: + # Act + sum_pf: float + max_pf: float + elements: list[objects.WindowElement] + sum_pf, max_pf, elements = functions.scaled_collect( + dL=200, + point_list=[], + m_van=0, + m_tot=50, + ) + + # Assert + assert sum_pf == 0.0 + assert max_pf == 0.0 + assert len(elements) == 0 \ No newline at end of file diff --git a/tests/test_system.py b/tests/test_system.py index 70e8c0cd..e5d5d586 100644 --- a/tests/test_system.py +++ b/tests/test_system.py @@ -1,29 +1,29 @@ -def test_system(): +# def test_system(): - ## - if __name__ == "__main__": - from repo_utils.utils import repository_root_path - from geoprob_pipe import GeoProbPipe - import os - repo_root = repository_root_path() - from geoprob_pipe.cmd_app.cmd import ApplicationSettings +# ## +# if __name__ == "__main__": +# from repo_utils.utils import repository_root_path +# from geoprob_pipe import GeoProbPipe +# import os +# repo_root = repository_root_path() +# from geoprob_pipe.cmd_app.cmd import ApplicationSettings - file_names = [ - # "Traject224_MORIA_WBN_det_corr.geoprob_pipe.gpkg", - # "Traject224_MORIA_WBN_det_uncorr.geoprob_pipe.gpkg", - "Traject224_MORIA_WBN_prob.geoprob_pipe.gpkg", - # "Traject224_model4a_WBN_prob.geoprob_pipe.gpkg", - # "Traject224_WBI_WBN_prob.geoprob_pipe.gpkg", # TODO - ] +# file_names = [ +# # "Traject224_MORIA_WBN_det_corr.geoprob_pipe.gpkg", +# # "Traject224_MORIA_WBN_det_uncorr.geoprob_pipe.gpkg", +# "Traject224_MORIA_WBN_prob.geoprob_pipe.gpkg", +# # "Traject224_model4a_WBN_prob.geoprob_pipe.gpkg", +# # "Traject224_WBI_WBN_prob.geoprob_pipe.gpkg", # TODO +# ] - for file_name in file_names: - print(f"\nNow running {file_name}") - app_settings = ApplicationSettings() - filepath = os.path.join(repo_root, "tests", "systeem_testen", "224", file_name) - app_settings.workspace_dir = os.path.dirname(filepath) - app_settings.geopackage_filename = os.path.basename(filepath) - geoprob_pipe = GeoProbPipe(app_settings) - geoprob_pipe.export_archive() +# for file_name in file_names: +# print(f"\nNow running {file_name}") +# app_settings = ApplicationSettings() +# filepath = os.path.join(repo_root, "tests", "systeem_testen", "224", file_name) +# app_settings.workspace_dir = os.path.dirname(filepath) +# app_settings.geopackage_filename = os.path.basename(filepath) +# geoprob_pipe = GeoProbPipe(app_settings) +# geoprob_pipe.export_archive() - ## +# ## From 41947ca3e58b294e14dfb6463427d44a5428d73e Mon Sep 17 00:00:00 2001 From: Vincent Jilesen Date: Fri, 21 Aug 2026 11:03:32 +0200 Subject: [PATCH 10/15] format --- tests/cmd_app/general/test_project.py | 11 ++++++++++- tests/cmd_app/general/test_traject_parameters.py | 3 +++ tests/cmd_app/spatial_layers/test_binnenteenlijn.py | 6 ++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/cmd_app/general/test_project.py b/tests/cmd_app/general/test_project.py index c384f4e5..c94a8182 100644 --- a/tests/cmd_app/general/test_project.py +++ b/tests/cmd_app/general/test_project.py @@ -31,6 +31,7 @@ def test_created_project_happy_paths( function_name: str, ) -> None: """Test of the paths are correctly completed.""" + # Arrange # Mock input arguments app_settings = Mock() @@ -54,8 +55,10 @@ def test_created_project_happy_paths( logging_mock, ) + # Act result: bool = module.created_project(app_settings) + # Assert # Check path reaches return assert result is True @@ -66,7 +69,8 @@ def test_created_project_happy_paths( def test_created_project_compare(monkeypatch) -> None: - """ "Test start compare function.""" + """Test start compare function.""" + # Arrange # Mock assigned function calls prompt_mock = Mock() choice: str = "Twee projectbestanden vergelijken" @@ -77,15 +81,18 @@ def test_created_project_compare(monkeypatch) -> None: compare_mock = Mock() monkeypatch.setattr(module, "start_comparison", compare_mock) + # Act # While capturing the sysexit() run the function with pytest.raises(SystemExit, match="Applicatie afgesloten"): module.created_project(Mock()) + # Assert # Check function call compare_mock.assert_called_once() def test_created_project_single_calc(monkeypatch) -> None: + # Arrange # Mock assigned function calls prompt_mock = Mock() choice: str = "Inspecteer een enkele berekening" @@ -107,10 +114,12 @@ def test_created_project_single_calc(monkeypatch) -> None: "Console", console_mock, ) + # Act # While capturing the sysexit() run the function with pytest.raises(SystemExit, match="Applicatie afgesloten"): module.created_project(Mock()) + # Assert # Check Panel construction panel_mock.assert_called_once_with( module.EXPLANATION_REPRODUCING_SINGLE_CALCULATION, diff --git a/tests/cmd_app/general/test_traject_parameters.py b/tests/cmd_app/general/test_traject_parameters.py index 5570bba2..3da4b30b 100644 --- a/tests/cmd_app/general/test_traject_parameters.py +++ b/tests/cmd_app/general/test_traject_parameters.py @@ -29,6 +29,7 @@ def test_specify_w_validations( expected_answer: str, ) -> None: """Test for all branches of validation and correct storage of user input.""" + # Arrange # Mock input arguments app_settings = Mock() @@ -54,9 +55,11 @@ def test_specify_w_validations( append_mock, ) + # Act # Run tested function: module._specify_w(app_settings) + # Assert # Check correct message printed captured = capsys.readouterr() assert expected_answer in captured.out diff --git a/tests/cmd_app/spatial_layers/test_binnenteenlijn.py b/tests/cmd_app/spatial_layers/test_binnenteenlijn.py index 353613bf..c8e11b27 100644 --- a/tests/cmd_app/spatial_layers/test_binnenteenlijn.py +++ b/tests/cmd_app/spatial_layers/test_binnenteenlijn.py @@ -15,6 +15,7 @@ def test_added_binnenteenlijn_already_included( capsys, ) -> None: """Test case `binnenteenlijn` already added to gpkg.""" + # Arrange # Mock input arguments app_settings = Mock() app_settings.geopackage_filepath = "dummy.gpkg" @@ -38,9 +39,11 @@ def test_added_binnenteenlijn_already_included( request_mock, ) + # Act # Run tested function: result: bool = module.added_binnenteenlijn(app_settings) + # Assert # Check expected return assert result is True @@ -57,6 +60,7 @@ def test_added_binnenteenlijn_not_yet_included( monkeypatch, ) -> None: """Test case `binnenteenlijn` not yet added to gpkg.""" + # Arrange # Mock input argument(s) app_settings = Mock() app_settings.geopackage_filepath = "dummy.gpkg" @@ -79,9 +83,11 @@ def test_added_binnenteenlijn_not_yet_included( request_mock, ) + # Act # Run tested function: result: bool = module.added_binnenteenlijn(app_settings) + # Assert # Check expected return assert result is True From 98fccc218b70b24d1cb4f56dc878ab0c6942159f Mon Sep 17 00:00:00 2001 From: Vincent Jilesen Date: Mon, 24 Aug 2026 09:16:01 +0200 Subject: [PATCH 11/15] minor simplification --- tests/cmd_app/general/test_project.py | 6 +++--- tests/cmd_app/general/test_traject_parameters.py | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/cmd_app/general/test_project.py b/tests/cmd_app/general/test_project.py index c94a8182..61067504 100644 --- a/tests/cmd_app/general/test_project.py +++ b/tests/cmd_app/general/test_project.py @@ -36,10 +36,10 @@ def test_created_project_happy_paths( app_settings = Mock() # Mock assigned function calls - prompt_mock = Mock() - prompt_mock.execute.return_value = choice + select_mock = Mock() + select_mock.return_value.execute.return_value = choice - monkeypatch.setattr("InquirerPy.inquirer.select", Mock(return_value=prompt_mock)) + monkeypatch.setattr("InquirerPy.inquirer.select", select_mock) # Mock called functions action_mock = Mock() diff --git a/tests/cmd_app/general/test_traject_parameters.py b/tests/cmd_app/general/test_traject_parameters.py index 3da4b30b..7ec840bf 100644 --- a/tests/cmd_app/general/test_traject_parameters.py +++ b/tests/cmd_app/general/test_traject_parameters.py @@ -40,11 +40,9 @@ def test_specify_w_validations( prompt_mock = Mock() prompt_mock.execute.side_effect = lambda: next(user_inputs) - text_mock = Mock(return_value=prompt_mock) - monkeypatch.setattr( "InquirerPy.inquirer.text", - text_mock, + Mock(return_value=prompt_mock), ) # Mock called functions From 4bccaf4dd0702e3fd1196967caebf25153434059 Mon Sep 17 00:00:00 2001 From: Vincent Jilesen Date: Mon, 24 Aug 2026 10:23:20 +0200 Subject: [PATCH 12/15] fixture for app_settings --- tests/cmd_app/general/test_project.py | 4 +- .../general/test_traject_parameters.py | 4 +- .../spatial_layers/test_binnenteenlijn.py | 41 ++++++++----------- tests/conftest.py | 13 ++++++ 4 files changed, 33 insertions(+), 29 deletions(-) create mode 100644 tests/conftest.py diff --git a/tests/cmd_app/general/test_project.py b/tests/cmd_app/general/test_project.py index 61067504..6d5cca8a 100644 --- a/tests/cmd_app/general/test_project.py +++ b/tests/cmd_app/general/test_project.py @@ -26,15 +26,13 @@ ], ) def test_created_project_happy_paths( + app_settings, monkeypatch, choice: str, function_name: str, ) -> None: """Test of the paths are correctly completed.""" # Arrange - # Mock input arguments - app_settings = Mock() - # Mock assigned function calls select_mock = Mock() select_mock.return_value.execute.return_value = choice diff --git a/tests/cmd_app/general/test_traject_parameters.py b/tests/cmd_app/general/test_traject_parameters.py index 7ec840bf..3a4afc8b 100644 --- a/tests/cmd_app/general/test_traject_parameters.py +++ b/tests/cmd_app/general/test_traject_parameters.py @@ -23,6 +23,7 @@ ], ) def test_specify_w_validations( + app_settings, monkeypatch, capsys, input_value: str, @@ -30,9 +31,6 @@ def test_specify_w_validations( ) -> None: """Test for all branches of validation and correct storage of user input.""" # Arrange - # Mock input arguments - app_settings = Mock() - # Setup user inputs user_inputs = iter([input_value, "0.24"]) diff --git a/tests/cmd_app/spatial_layers/test_binnenteenlijn.py b/tests/cmd_app/spatial_layers/test_binnenteenlijn.py index c8e11b27..63344032 100644 --- a/tests/cmd_app/spatial_layers/test_binnenteenlijn.py +++ b/tests/cmd_app/spatial_layers/test_binnenteenlijn.py @@ -11,24 +11,23 @@ # --- added_binnenteenlijn(app_settings: ApplicationSettings) -> bool --- def test_added_binnenteenlijn_already_included( + app_settings, monkeypatch, capsys, ) -> None: """Test case `binnenteenlijn` already added to gpkg.""" # Arrange - # Mock input arguments - app_settings = Mock() - app_settings.geopackage_filepath = "dummy.gpkg" - # Monkey patch assigned function calls monkeypatch.setattr( module.fiona, "listlayers", - Mock(return_value=[ - "trajectlijn", - "binnenteenlijn", - "vakindeling", - ]), + Mock( + return_value=[ + "trajectlijn", + "binnenteenlijn", + "vakindeling", + ] + ), ) # Mock called module fuctions @@ -50,29 +49,27 @@ def test_added_binnenteenlijn_already_included( # Check correct message printed captured = capsys.readouterr() assert "Binnenteenlijn al toegevoegd" in captured.out - + # Check function in other branch not called request_mock.assert_not_called() - - + def test_added_binnenteenlijn_not_yet_included( + app_settings, monkeypatch, ) -> None: """Test case `binnenteenlijn` not yet added to gpkg.""" # Arrange - # Mock input argument(s) - app_settings = Mock() - app_settings.geopackage_filepath = "dummy.gpkg" - # Monkey patch assigned function call(s) monkeypatch.setattr( module.fiona, "listlayers", - Mock(return_value=[ - "trajectlijn", - "vakindeling", - ]), + Mock( + return_value=[ + "trajectlijn", + "vakindeling", + ] + ), ) # Mock called module fuction(s) @@ -92,6 +89,4 @@ def test_added_binnenteenlijn_not_yet_included( assert result is True # Check function call with correct argument - request_mock.assert_called_once_with( - app_settings=app_settings - ) \ No newline at end of file + request_mock.assert_called_once_with(app_settings=app_settings) diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..37970c6b --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,13 @@ +import pytest + +from geoprob_pipe.cmd_app.cmd import ApplicationSettings + + +@pytest.fixture +def app_settings(tmp_path) -> ApplicationSettings: + settings = ApplicationSettings() + + settings.workspace_dir = str(tmp_path) + settings.geopackage_filename = "dummy.gpkg" + + return settings \ No newline at end of file From c4196234d5607a401d52a8b85764411080343901 Mon Sep 17 00:00:00 2001 From: Sander Kapinga Date: Thu, 10 Sep 2026 08:53:51 +0200 Subject: [PATCH 13/15] added tests "valid boundaries" and "surroundig spaces" --- .../general/test_traject_parameters.py | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/tests/cmd_app/general/test_traject_parameters.py b/tests/cmd_app/general/test_traject_parameters.py index 3a4afc8b..45bbac99 100644 --- a/tests/cmd_app/general/test_traject_parameters.py +++ b/tests/cmd_app/general/test_traject_parameters.py @@ -69,3 +69,54 @@ def test_specify_w_validations( key="w", value=0.24, # as a float ) + + +@pytest.mark.parametrize("input_value", ["0.01", "1.0"]) +def test_specify_w_valid_boundaries(app_settings, monkeypatch, input_value: str) -> None: + """Test that the valid boundaries are accepted.""" + # Arrange + prompt_mock = Mock() + prompt_mock.execute.return_value = input_value + monkeypatch.setattr( + "InquirerPy.inquirer.text", + Mock(return_value=prompt_mock), + ) + + append_mock = Mock() + monkeypatch.setattr(module, "_append_to_db", append_mock) + + # Act + module._specify_w(app_settings) + + # Assert + prompt_mock.execute.assert_called_once() + append_mock.assert_called_once_with( + app_settings=app_settings, + key="w", + value=float(input_value), + ) + + +def test_specify_w_strips_surrounding_spaces(app_settings, monkeypatch) -> None: + """Test that surrounding spaces are removed before validation.""" + # Arrange + prompt_mock = Mock() + prompt_mock.execute.return_value = " 0.24 " + monkeypatch.setattr( + "InquirerPy.inquirer.text", + Mock(return_value=prompt_mock), + ) + + append_mock = Mock() + monkeypatch.setattr(module, "_append_to_db", append_mock) + + # Act + module._specify_w(app_settings) + + # Assert + prompt_mock.execute.assert_called_once() + append_mock.assert_called_once_with( + app_settings=app_settings, + key="w", + value=0.24, + ) From fdb23f33be688974dea4d7db3e4278e279f87b19 Mon Sep 17 00:00:00 2001 From: Sander Kapinga Date: Thu, 10 Sep 2026 11:37:35 +0200 Subject: [PATCH 14/15] rename test_functions_assemblage and added documentstring --- .../{test_functions.py => test_functions_assemblage.py} | 4 ++++ 1 file changed, 4 insertions(+) rename tests/results/assemblage/{test_functions.py => test_functions_assemblage.py} (97%) diff --git a/tests/results/assemblage/test_functions.py b/tests/results/assemblage/test_functions_assemblage.py similarity index 97% rename from tests/results/assemblage/test_functions.py rename to tests/results/assemblage/test_functions_assemblage.py index 85b2ac34..20f347b3 100644 --- a/tests/results/assemblage/test_functions.py +++ b/tests/results/assemblage/test_functions_assemblage.py @@ -1,3 +1,7 @@ +""" +Unit tests for `assemblage.functions` and `assemblage.objects` in `geoprob_pipe.results.assemblage.functions`. +""" + import pytest import geoprob_pipe.results.assemblage.functions as functions From 600206d57bcd39ae91722170cd0b73bbb160599c Mon Sep 17 00:00:00 2001 From: Sander Kapinga Date: Thu, 10 Sep 2026 11:49:10 +0200 Subject: [PATCH 15/15] uncommit test_system --- tests/test_system.py | 48 ++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/test_system.py b/tests/test_system.py index e5d5d586..70e8c0cd 100644 --- a/tests/test_system.py +++ b/tests/test_system.py @@ -1,29 +1,29 @@ -# def test_system(): +def test_system(): -# ## -# if __name__ == "__main__": -# from repo_utils.utils import repository_root_path -# from geoprob_pipe import GeoProbPipe -# import os -# repo_root = repository_root_path() -# from geoprob_pipe.cmd_app.cmd import ApplicationSettings + ## + if __name__ == "__main__": + from repo_utils.utils import repository_root_path + from geoprob_pipe import GeoProbPipe + import os + repo_root = repository_root_path() + from geoprob_pipe.cmd_app.cmd import ApplicationSettings -# file_names = [ -# # "Traject224_MORIA_WBN_det_corr.geoprob_pipe.gpkg", -# # "Traject224_MORIA_WBN_det_uncorr.geoprob_pipe.gpkg", -# "Traject224_MORIA_WBN_prob.geoprob_pipe.gpkg", -# # "Traject224_model4a_WBN_prob.geoprob_pipe.gpkg", -# # "Traject224_WBI_WBN_prob.geoprob_pipe.gpkg", # TODO -# ] + file_names = [ + # "Traject224_MORIA_WBN_det_corr.geoprob_pipe.gpkg", + # "Traject224_MORIA_WBN_det_uncorr.geoprob_pipe.gpkg", + "Traject224_MORIA_WBN_prob.geoprob_pipe.gpkg", + # "Traject224_model4a_WBN_prob.geoprob_pipe.gpkg", + # "Traject224_WBI_WBN_prob.geoprob_pipe.gpkg", # TODO + ] -# for file_name in file_names: -# print(f"\nNow running {file_name}") -# app_settings = ApplicationSettings() -# filepath = os.path.join(repo_root, "tests", "systeem_testen", "224", file_name) -# app_settings.workspace_dir = os.path.dirname(filepath) -# app_settings.geopackage_filename = os.path.basename(filepath) -# geoprob_pipe = GeoProbPipe(app_settings) -# geoprob_pipe.export_archive() + for file_name in file_names: + print(f"\nNow running {file_name}") + app_settings = ApplicationSettings() + filepath = os.path.join(repo_root, "tests", "systeem_testen", "224", file_name) + app_settings.workspace_dir = os.path.dirname(filepath) + app_settings.geopackage_filename = os.path.basename(filepath) + geoprob_pipe = GeoProbPipe(app_settings) + geoprob_pipe.export_archive() -# ## + ##