Skip to content

Commit

Permalink
Add test for deebot_client.Map._get_svg_traces_path
Browse files Browse the repository at this point in the history
  • Loading branch information
Filip Rutkowski authored and Filip Rutkowski committed May 8, 2024
1 parent cabf37a commit 7d3231b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
7 changes: 4 additions & 3 deletions deebot_client/map.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Map module."""

from __future__ import annotations

import ast
Expand All @@ -16,6 +17,7 @@
from PIL import Image, ImageColor, ImageOps, ImagePalette
import svg

from deebot_client import util
from deebot_client.events.map import CachedMapInfoEvent, MapChangedEvent

from .commands.json import GetMinorMap
Expand All @@ -37,7 +39,6 @@
from .util import (
OnChangedDict,
OnChangedList,
decompress_7z_base64_data,
)

if TYPE_CHECKING:
Expand Down Expand Up @@ -383,7 +384,7 @@ async def on_map_subset(event: MapSubsetEvent) -> None:

def _update_trace_points(self, data: str) -> None:
_LOGGER.debug("[_update_trace_points] Begin")
trace_points = decompress_7z_base64_data(data)
trace_points = util.decompress_7z_base64_data(data)

for i in range(0, len(trace_points), 5):
position_x, position_y = struct.unpack("<hh", trace_points[i : i + 4])
Expand Down Expand Up @@ -610,7 +611,7 @@ def image(self) -> Image.Image:

def update_points(self, base64_data: str) -> None:
"""Add map piece points."""
decoded = decompress_7z_base64_data(base64_data)
decoded = util.decompress_7z_base64_data(base64_data)

Check warning on line 614 in deebot_client/map.py

View check run for this annotation

Codecov / codecov/patch

deebot_client/map.py#L614

Added line #L614 was not covered by tests
old_crc32 = self._crc32
self._crc32 = zlib.crc32(decoded)

Expand Down
30 changes: 29 additions & 1 deletion tests/test_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import asyncio
from typing import TYPE_CHECKING
from unittest.mock import ANY, AsyncMock, Mock, call
from unittest.mock import ANY, AsyncMock, Mock, call, patch

import pytest
import svg
Expand Down Expand Up @@ -141,6 +141,34 @@ async def on_change() -> None:
assert not map._unsubscribers


@patch(
"deebot_client.util.decompress_7z_base64_data",
Mock(return_value=b"\x10\x00\x00\x01\x00"),
)
async def test_Map_svg_traces_path(
execute_mock: AsyncMock, event_bus_mock: Mock
) -> None:
map = Map(execute_mock, event_bus_mock)

path = map._get_svg_traces_path()
assert path is None

map._update_trace_points("")
path = map._get_svg_traces_path()

assert path == Path(
fill="none",
stroke="#fff",
stroke_width=1.5,
stroke_linejoin="round",
vector_effect="non-scaling-stroke",
transform=[
svg.Scale(0.2, -0.2),
],
d=[svg.MoveTo(x=16, y=256)],
)


def test_compact_path() -> None:
"""Test that the path is compacted correctly."""
path = Path(
Expand Down

0 comments on commit 7d3231b

Please sign in to comment.