From 585bb2b9450713c7cb752fdcf49fc4db9303f06b Mon Sep 17 00:00:00 2001 From: Filip Rutkowski Date: Wed, 28 Feb 2024 09:16:05 +0000 Subject: [PATCH] Merge svg import in test_map --- tests/test_map.py | 86 ++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 50 deletions(-) diff --git a/tests/test_map.py b/tests/test_map.py index af820c835..1f44cf05a 100644 --- a/tests/test_map.py +++ b/tests/test_map.py @@ -5,21 +5,7 @@ from unittest.mock import ANY, AsyncMock, Mock, call import pytest -from svg import ( - ArcRel, - ClosePath, - CubicBezier, - HorizontalLineToRel, - LineToRel, - MoveTo, - MoveToRel, - PathData, - Polygon, - SmoothCubicBezierRel, - Use, - VerticalLineToRel, - ViewBoxSpec, -) +import svg from deebot_client.events.map import ( MajorMapEvent, @@ -72,10 +58,10 @@ def test_calc_point( _test_calc_point_in_viewbox_data = [ - (100, 100, ViewBoxSpec(-100, -100, 200, 150), Point(2.0, -2.0)), - (-64000, -64000, ViewBoxSpec(0, 0, 1000, 1000), Point(0.0, 1000.0)), - (64000, 64000, ViewBoxSpec(0, 0, 1000, 1000), Point(1000.0, 0.0)), - (None, 1000, ViewBoxSpec(-500, -500, 1000, 1000), Point(0.0, -20.0)), + (100, 100, svg.ViewBoxSpec(-100, -100, 200, 150), Point(2.0, -2.0)), + (-64000, -64000, svg.ViewBoxSpec(0, 0, 1000, 1000), Point(0.0, 1000.0)), + (64000, 64000, svg.ViewBoxSpec(0, 0, 1000, 1000), Point(1000.0, 0.0)), + (None, 1000, svg.ViewBoxSpec(-500, -500, 1000, 1000), Point(0.0, -20.0)), ] @@ -85,7 +71,7 @@ def test_calc_point( def test_calc_point_in_viewbox( x: int, y: int, - viewbox: ViewBoxSpec, + viewbox: svg.ViewBoxSpec, expected: Point, ) -> None: result = _calc_point_in_viewbox(x, y, viewbox) @@ -160,13 +146,13 @@ def test_compact_path() -> None: path = Path( fill="#ffe605", d=[ - MoveTo(4, -6.4), - CubicBezier(4, -4.2, 0, 0, 0, 0), - SmoothCubicBezierRel(-4, -4.2, -4, -6.4), - LineToRel(0, -3.2), - LineToRel(4, 0), - ArcRel(1, 2, 3, large_arc=True, sweep=False, dx=4, dy=5), - ClosePath(), + svg.MoveTo(4, -6.4), + svg.CubicBezier(4, -4.2, 0, 0, 0, 0), + svg.SmoothCubicBezierRel(-4, -4.2, -4, -6.4), + svg.LineToRel(0, -3.2), + svg.LineToRel(4, 0), + svg.ArcRel(1, 2, 3, large_arc=True, sweep=False, dx=4, dy=5), + svg.ClosePath(), ], ) @@ -181,7 +167,7 @@ def test_compact_path() -> None: [ ( [Point(x=45.58, y=176.12), Point(x=18.78, y=175.94)], - [MoveTo(45.58, 176.12), LineToRel(-26.8, -0.18)], + [svg.MoveTo(45.58, 176.12), svg.LineToRel(-26.8, -0.18)], ), ( [ @@ -196,19 +182,19 @@ def test_compact_path() -> None: TracePoint(x=-260, y=-80, connected=True), ], [ - MoveTo(x=-215, y=-70), - LineToRel(dx=3, dy=-3), - HorizontalLineToRel(dx=-1), - LineToRel(dx=-14, dy=1), - VerticalLineToRel(dy=2), - MoveToRel(dx=-29, dy=1), - LineToRel(dx=-4, dy=-11), + svg.MoveTo(x=-215, y=-70), + svg.LineToRel(dx=3, dy=-3), + svg.HorizontalLineToRel(dx=-1), + svg.LineToRel(dx=-14, dy=1), + svg.VerticalLineToRel(dy=2), + svg.MoveToRel(dx=-29, dy=1), + svg.LineToRel(dx=-4, dy=-11), ], ), ], ) def test_points_to_svg_path( - points: Sequence[Point | TracePoint], expected: list[PathData] + points: Sequence[Point | TracePoint], expected: list[svg.PathData] ) -> None: assert _points_to_svg_path(points) == expected @@ -225,7 +211,7 @@ def test_points_to_svg_path( stroke_width=1.5, stroke_dasharray=[4], vector_effect="non-scaling-stroke", - d=[MoveTo(x=-78.0, y=-13.36), HorizontalLineToRel(dx=35.34)], + d=[svg.MoveTo(x=-78.0, y=-13.36), svg.HorizontalLineToRel(dx=35.34)], ), ), ( @@ -234,7 +220,7 @@ def test_points_to_svg_path( type=MapSetType.NO_MOP_ZONES, coordinates="[-442,2910,-442,982,1214,982,1214,2910]", ), - Polygon( + svg.Polygon( fill="#ffa50030", stroke="#ffa500", stroke_width=1.5, @@ -245,36 +231,36 @@ def test_points_to_svg_path( ), ], ) -def test_get_svg_subset(subset: MapSubsetEvent, expected: Path | Polygon) -> None: +def test_get_svg_subset(subset: MapSubsetEvent, expected: Path | svg.Polygon) -> None: assert _get_svg_subset(subset) == expected _test_get_svg_positions_data = [ ( [Position(PositionType.CHARGER, 5000, -55000)], - ViewBoxSpec(-500, -500, 1000, 1000), - [Use(href="#c", x=100, y=500)], + svg.ViewBoxSpec(-500, -500, 1000, 1000), + [svg.Use(href="#c", x=100, y=500)], ), ( [Position(PositionType.DEEBOT, 15000, 15000)], - ViewBoxSpec(-500, -500, 1000, 1000), - [Use(href="#d", x=300, y=-300)], + svg.ViewBoxSpec(-500, -500, 1000, 1000), + [svg.Use(href="#d", x=300, y=-300)], ), ( [ Position(PositionType.CHARGER, 25000, 55000), Position(PositionType.DEEBOT, -5000, -50000), ], - ViewBoxSpec(-500, -500, 1000, 1000), - [Use(href="#d", x=-100, y=500), Use(href="#c", x=500, y=-500)], + svg.ViewBoxSpec(-500, -500, 1000, 1000), + [svg.Use(href="#d", x=-100, y=500), svg.Use(href="#c", x=500, y=-500)], ), ( [ Position(PositionType.DEEBOT, -10000, 10000), Position(PositionType.CHARGER, 50000, 5000), ], - ViewBoxSpec(-500, -500, 1000, 1000), - [Use(href="#d", x=-200, y=-200), Use(href="#c", x=500, y=-100)], + svg.ViewBoxSpec(-500, -500, 1000, 1000), + [svg.Use(href="#d", x=-200, y=-200), svg.Use(href="#c", x=500, y=-100)], ), ] @@ -284,13 +270,13 @@ def test_get_svg_subset(subset: MapSubsetEvent, expected: Path | Polygon) -> Non ) def test_get_svg_positions( positions: list[Position], - viewbox: ViewBoxSpec, - expected: list[Use], + viewbox: svg.ViewBoxSpec, + expected: list[svg.Use], ) -> None: result = _get_svg_positions(positions, viewbox) assert len(result) == len(expected) for result_item, expected_item in zip(result, expected, strict=True): - assert type(result_item) == Use + assert type(result_item) == svg.Use assert result_item.href == expected_item.href assert result_item.x == expected_item.x assert result_item.y == expected_item.y