Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
bisgaard-itis committed Sep 29, 2023
1 parent 71fac55 commit da8e679
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<value>[0-1]?\.\d+|"
r"\d+\s*(?:(?P<percent_sign>%)|"
r"\d+\s*"
Expand Down
58 changes: 35 additions & 23 deletions services/dask-sidecar/tests/unit/test_docker_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# pylint: disable=no-member

import asyncio
import re
from typing import Any
from unittest.mock import call

Expand All @@ -24,6 +25,7 @@
create_container_config,
managed_container,
)
from simcore_service_dask_sidecar.computational_sidecar.models import ImageLabels


@pytest.fixture()
Expand Down Expand Up @@ -120,49 +122,59 @@ 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<value>[0-1]?\\.\\d+|\\d+\\s*(?:(?P<percent_sign>%)|\\d+\\s*(?P<percent_explicit>percent)))"
)
),
),
],
)
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


Expand Down

0 comments on commit da8e679

Please sign in to comment.