-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Roof Test and Refactor
- Loading branch information
Showing
7 changed files
with
244 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from typing import Any, Tuple, Optional | ||
|
||
import pytest | ||
|
||
from pyobs.modules.roof import BaseDome | ||
|
||
|
||
class TestBaseDome(BaseDome): | ||
|
||
async def init(self, **kwargs: Any) -> None: | ||
pass | ||
|
||
async def park(self, **kwargs: Any) -> None: | ||
pass | ||
|
||
async def stop_motion(self, device: Optional[str] = None, **kwargs: Any) -> None: | ||
pass | ||
|
||
async def move_altaz(self, alt: float, az: float, **kwargs: Any) -> None: | ||
pass | ||
|
||
async def get_altaz(self, **kwargs: Any) -> Tuple[float, float]: | ||
return 60.0, 0.0 | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_get_fits_header_before(mocker): | ||
dome = TestBaseDome() | ||
|
||
mocker.patch("pyobs.modules.roof.BaseRoof.get_fits_header_before", return_value={"ROOF-OPN": (True, "")}) | ||
|
||
header = await dome.get_fits_header_before() | ||
|
||
assert "ROOF-OPN" in header | ||
assert header["ROOF-AZ"] == (0.0, "Azimuth of roof slit, deg E of N") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from typing import Optional, Any | ||
from unittest.mock import AsyncMock | ||
|
||
import pytest | ||
|
||
import pyobs | ||
from pyobs.modules.roof import BaseRoof | ||
from pyobs.utils.enums import MotionStatus | ||
|
||
|
||
class TestBaseRoof(BaseRoof): | ||
async def init(self, **kwargs: Any) -> None: | ||
pass | ||
|
||
async def park(self, **kwargs: Any) -> None: | ||
pass | ||
|
||
async def stop_motion(self, device: Optional[str] = None, **kwargs: Any) -> None: | ||
pass | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_open(mocker): | ||
mocker.patch("pyobs.mixins.WeatherAwareMixin.open") | ||
mocker.patch("pyobs.mixins.MotionStatusMixin.open") | ||
mocker.patch("pyobs.modules.Module.open") | ||
|
||
telescope = TestBaseRoof() | ||
await telescope.open() | ||
|
||
pyobs.mixins.WeatherAwareMixin.open.assert_called_once_with(telescope) | ||
pyobs.mixins.MotionStatusMixin.open.assert_called_once_with(telescope) | ||
pyobs.modules.Module.open.assert_called_once_with(telescope) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_get_fits_header_before_open(): | ||
telescope = TestBaseRoof() | ||
|
||
telescope.get_motion_status = AsyncMock(return_value=MotionStatus.POSITIONED) | ||
header = await telescope.get_fits_header_before() | ||
|
||
assert header["ROOF-OPN"] == (True, "True for open, false for closed roof") | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_get_fits_header_before_closed(): | ||
telescope = TestBaseRoof() | ||
|
||
telescope.get_motion_status = AsyncMock(return_value=MotionStatus.PARKED) | ||
header = await telescope.get_fits_header_before() | ||
|
||
assert header["ROOF-OPN"] == (False, "True for open, false for closed roof") | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_ready(): | ||
telescope = TestBaseRoof() | ||
|
||
telescope.get_motion_status = AsyncMock(return_value=MotionStatus.TRACKING) | ||
assert await telescope.is_ready() is True | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_not_ready(): | ||
telescope = TestBaseRoof() | ||
|
||
telescope.get_motion_status = AsyncMock(return_value=MotionStatus.PARKING) | ||
assert await telescope.is_ready() is False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
from unittest.mock import AsyncMock, Mock | ||
|
||
import pytest | ||
|
||
import pyobs | ||
from pyobs.events import RoofOpenedEvent, RoofClosingEvent | ||
from pyobs.modules.roof import DummyRoof | ||
from pyobs.utils.enums import MotionStatus | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_open(mocker) -> None: | ||
mocker.patch("pyobs.modules.roof.BaseRoof.open") | ||
roof = DummyRoof() | ||
roof.comm.register_event = AsyncMock() | ||
|
||
await roof.open() | ||
|
||
pyobs.modules.roof.BaseRoof.open.assert_called_once() | ||
|
||
assert roof.comm.register_event.call_args_list[0][0][0] == RoofOpenedEvent | ||
assert roof.comm.register_event.call_args_list[1][0][0] == RoofClosingEvent | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_init(mocker) -> None: | ||
mocker.patch("asyncio.sleep") | ||
|
||
roof = DummyRoof() | ||
roof._change_motion_status = AsyncMock() | ||
roof.comm.send_event = Mock() | ||
|
||
await roof.init() | ||
|
||
roof._change_motion_status.assert_awaited_with(MotionStatus.IDLE) | ||
roof.comm.send_event(RoofOpenedEvent()) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_park(mocker) -> None: | ||
mocker.patch("asyncio.sleep") | ||
|
||
roof = DummyRoof() | ||
roof._open_percentage = 100 | ||
|
||
roof._change_motion_status = AsyncMock() | ||
roof.comm.send_event = Mock() | ||
|
||
await roof.park() | ||
|
||
roof._change_motion_status.assert_awaited_with(MotionStatus.PARKED) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_move_roof_open(mocker) -> None: | ||
mocker.patch("asyncio.sleep") | ||
|
||
roof = DummyRoof() | ||
|
||
await roof._move_roof(roof._ROOF_OPEN_PERCENTAGE) | ||
|
||
assert roof._open_percentage == 100 | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_move_roof_closed(mocker) -> None: | ||
mocker.patch("asyncio.sleep") | ||
|
||
roof = DummyRoof() | ||
|
||
await roof._move_roof(roof._ROOF_CLOSED_PERCENTAGE) | ||
|
||
assert roof._open_percentage == 0 | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_move_roof_abort(mocker) -> None: | ||
mocker.patch("asyncio.sleep") | ||
|
||
roof = DummyRoof() | ||
|
||
roof._abort_motion.set() | ||
await roof._move_roof(roof._ROOF_OPEN_PERCENTAGE) | ||
|
||
assert roof._open_percentage == 0 | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_move_roof_open(mocker) -> None: | ||
mocker.patch("asyncio.sleep") | ||
|
||
roof = DummyRoof() | ||
|
||
await roof._move_roof(roof._ROOF_OPEN_PERCENTAGE) | ||
|
||
assert roof._open_percentage == 100 | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_stop_motion() -> None: | ||
roof = DummyRoof() | ||
roof._change_motion_status = AsyncMock() | ||
await roof.stop_motion() | ||
|
||
roof._change_motion_status.assert_awaited_with(MotionStatus.IDLE) |