From 3797df8232a4032d8784db6db4f19ccddc1e89a8 Mon Sep 17 00:00:00 2001
From: dcarron <daniel.carron@idiap.ch>
Date: Mon, 1 Jul 2024 11:47:01 +0200
Subject: [PATCH] [tests.segmentation] Add tests for view script

---
 tests/segmentation/test_cli.py | 37 ++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/tests/segmentation/test_cli.py b/tests/segmentation/test_cli.py
index a2e35d2e..75838d12 100644
--- a/tests/segmentation/test_cli.py
+++ b/tests/segmentation/test_cli.py
@@ -345,6 +345,43 @@ def test_evaluate_lwnet_drive(session_tmp_path):
             )
 
 
+@pytest.mark.slow
+@pytest.mark.skip_if_rc_var_not_set("datadir.drive")
+def test_view_lwnet_drive(session_tmp_path):
+    from mednet.libs.segmentation.scripts.view import view
+
+    runner = CliRunner()
+
+    with stdout_logging() as buf:
+        output_folder = session_tmp_path / "segmentation-standalone"
+        result = runner.invoke(
+            view,
+            [
+                "-vv",
+                f"--predictions={str(output_folder / 'predictions.json')}",
+                f"--output-folder={str(output_folder)}",
+            ],
+        )
+        _assert_exit_0(result)
+
+        assert len(list((output_folder / "training" / "images").glob("*.png"))) == 20
+        assert len(list((output_folder / "test" / "images").glob("*.png"))) == 20
+
+        keywords = {
+            r"^Creating 20 visualisations for split.*$": 2,
+            r"^Set --threshold.*$": 1,
+        }
+        buf.seek(0)
+        logging_output = buf.read()
+
+        for k, v in keywords.items():
+            assert _str_counter(k, logging_output) == v, (
+                f"Count for string '{k}' appeared "
+                f"({_str_counter(k, logging_output)}) "
+                f"instead of the expected {v}:\nOutput:\n{logging_output}"
+            )
+
+
 @pytest.mark.slow
 @pytest.mark.skip_if_rc_var_not_set("datadir.drive")
 def test_train_lwnet_drive_from_checkpoint(tmp_path):
-- 
GitLab