Skip to content

Commit

Permalink
fix image_box is None (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhaus authored Feb 13, 2022
1 parent b1b0c92 commit 5d6312b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
5 changes: 4 additions & 1 deletion deebot_client/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ def _calc_value(value: int, min_value: int, max_value: int) -> int:


def _calc_point(
x: int, y: int, image_box: tuple[int, int, int, int]
x: int, y: int, image_box: Optional[tuple[int, int, int, int]]
) -> tuple[int, int]:
if image_box is None:
image_box = (0, 0, x, y)

return (
_calc_value(x, image_box[0], image_box[2]),
_calc_value(y, image_box[1], image_box[3]),
Expand Down
4 changes: 4 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
asyncio_mode = auto
#log_cli=true
#log_level=DEBUG
3 changes: 2 additions & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mypy==0.931
pre-commit==2.17.0
pylint==2.12.2
pytest==7.0.0
pytest==7.0.1
pytest-asyncio==0.18.1
pytest-cov==3.0.0
types-cachetools==4.2.9
22 changes: 22 additions & 0 deletions tests/test_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from typing import Optional

import pytest

from deebot_client.map import _calc_point

_test_calc_point_data = [
(0, 10, None, (0, 10)),
(10, 100, (100, 0, 200, 50), (200, 50)),
(10, 100, (0, 0, 1000, 1000), (400, 402)),
]


@pytest.mark.parametrize("x,y,image_box,expected", _test_calc_point_data)
def test_calc_point(
x: int,
y: int,
image_box: Optional[tuple[int, int, int, int]],
expected: tuple[int, int],
) -> None:
result = _calc_point(x, y, image_box)
assert result == expected

0 comments on commit 5d6312b

Please sign in to comment.