From da8e679410087562dbf855ef43d5d9d2defd54f3 Mon Sep 17 00:00:00 2001 From: Mads Bisgaard Date: Fri, 29 Sep 2023 15:00:27 +0200 Subject: [PATCH] fix test --- .../computational_sidecar/models.py | 2 +- .../tests/unit/test_docker_utils.py | 58 +++++++++++-------- 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/services/dask-sidecar/src/simcore_service_dask_sidecar/computational_sidecar/models.py b/services/dask-sidecar/src/simcore_service_dask_sidecar/computational_sidecar/models.py index a3a79d6a461..ecf419b55fa 100644 --- a/services/dask-sidecar/src/simcore_service_dask_sidecar/computational_sidecar/models.py +++ b/services/dask-sidecar/src/simcore_service_dask_sidecar/computational_sidecar/models.py @@ -5,7 +5,7 @@ LEGACY_INTEGRATION_VERSION = version.Version("0") PROGRESS_REGEXP: re.Pattern[str] = re.compile( - r"^(?:\[?progress\]?:?)?\s*" + r"^(?:\[?PROGRESS\]?:?)?\s*" r"(?P[0-1]?\.\d+|" r"\d+\s*(?:(?P%)|" r"\d+\s*" diff --git a/services/dask-sidecar/tests/unit/test_docker_utils.py b/services/dask-sidecar/tests/unit/test_docker_utils.py index bb353452170..f747b194890 100644 --- a/services/dask-sidecar/tests/unit/test_docker_utils.py +++ b/services/dask-sidecar/tests/unit/test_docker_utils.py @@ -4,6 +4,7 @@ # pylint: disable=no-member import asyncio +import re from typing import Any from unittest.mock import call @@ -24,6 +25,7 @@ create_container_config, managed_container, ) +from simcore_service_dask_sidecar.computational_sidecar.models import ImageLabels @pytest.fixture() @@ -120,36 +122,45 @@ async def test_create_container_config( @pytest.mark.parametrize("with_timestamp", [True, False], ids=str) @pytest.mark.parametrize( - "log_line, expected_progress_value", + "log_line, expected_progress_value, image_labels", [ - ("hello from the logs", None), - ("[progress] this is some whatever progress without number", None), - ("[Progress] 34%", 0.34), - ("[PROGRESS] .34", 0.34), - ("[progress] 0.44", 0.44), - ("[progress] 44 percent done", 0.44), - ("[progress] 44/150", 44.0 / 150.0), - ("Progress: this is some progress", None), - ("progress: 34%", 0.34), - ("PROGRESS: .34", 0.34), - ("progress: 0.44", 0.44), - ("progress: 44 percent done", 0.44), - ("44 percent done", 0.44), - ("progress: 44/150", 44.0 / 150.0), - ("progress: 44/150...", 44.0 / 150.0), - ("any kind of message even with progress inside", None), - ("[PROGRESS]1.000000\n", 1.00), - ("[PROGRESS] 1\n", 1.00), - ("[PROGRESS] 0\n", 0.00), + ("hello from the logs", None, ImageLabels()), + ( + "[PROGRESS] this is some whatever progress without number", + None, + ImageLabels(), + ), + ("[PROGRESS] .34", 0.34, ImageLabels()), + ("Progress: this is some progress", None, ImageLabels()), + ("PROGRESS: .34", 0.34, ImageLabels()), + ("PROGRESS: 44 percent done", 0.44, ImageLabels()), + ("44 percent done", 0.44, ImageLabels()), + ("PROGRESS: 44/150", 44.0 / 150.0, ImageLabels()), + ("PROGRESS: 44/150...", 44.0 / 150.0, ImageLabels()), + ("any kind of message even with progress inside", None, ImageLabels()), + ("[PROGRESS]1.000000\n", 1.00, ImageLabels()), + ("[PROGRESS] 1\n", 1.00, ImageLabels()), + ("[PROGRESS] 0\n", 0.00, ImageLabels()), ( "[PROGRESS]: 1% [ 10 / 624 ] Time Update, estimated remaining time 1 seconds @ 26.43 MCells/s", 0.01, + ImageLabels(), ), - ("[warn]: this is some warning", None), - ("err: this is some error", None), + ("[warn]: this is some warning", None, ImageLabels()), + ("err: this is some error", None, ImageLabels()), ( "progress: 10/0 asd this is a 15% 10/asdf progress without progress it will not break the system", None, + ImageLabels(), + ), + ( + "[PROGRESS]: 21% [ 1219946 / 5545233 ] Assembling matrix", + 0.21, + ImageLabels( + progress_regexp=re.compile( + "^(?:\\[?PROGRESS\\]?:?)?\\s*(?P[0-1]?\\.\\d+|\\d+\\s*(?:(?P%)|\\d+\\s*(?Ppercent)))" + ) + ), ), ], ) @@ -157,12 +168,13 @@ async def test__try_parse_progress( with_timestamp: bool, log_line: str, expected_progress_value: float, + image_labels: ImageLabels, ): expected_time_stamp = arrow.utcnow().datetime if with_timestamp: log_line = f"{expected_time_stamp.isoformat()} {log_line}" - received_progress = await _try_parse_progress(log_line) + received_progress = await _try_parse_progress(log_line, image_labels=image_labels) assert received_progress == expected_progress_value