diff --git a/pyobs/modules/test/standalone.py b/pyobs/modules/test/standalone.py index 362fbe67..9283c6dc 100644 --- a/pyobs/modules/test/standalone.py +++ b/pyobs/modules/test/standalone.py @@ -33,11 +33,11 @@ async def _message_func(self): """Thread function for async processing.""" # loop until closing while True: - # log message - log.info(self._message) + await self._loop() - # sleep a little - await asyncio.sleep(self._interval) + async def _loop(self): + log.info(self._message) + await asyncio.sleep(self._interval) __all__ = ["StandAlone"] diff --git a/pyobs/utils/skyflats/flatfielder.py b/pyobs/utils/skyflats/flatfielder.py index 7314b6d4..da8cb349 100644 --- a/pyobs/utils/skyflats/flatfielder.py +++ b/pyobs/utils/skyflats/flatfielder.py @@ -88,7 +88,9 @@ def __init__( self._abort = asyncio.Event() # pointing - self._pointing: Optional[SkyFlatsBasePointing] = self.get_safe_object(pointing, SkyFlatsBasePointing) + self._pointing: Optional[SkyFlatsBasePointing] = None + if pointing is not None: + self._pointing = self.get_safe_object(pointing, SkyFlatsBasePointing) # state machine self._state = FlatFielder.State.INIT diff --git a/pyproject.toml b/pyproject.toml index 290f3f22..c70aa8ab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "pyobs-core" packages = [{ include = "pyobs" }] -version = "1.7.0" +version = "1.7.1" description = "robotic telescope software" authors = ["Tim-Oliver Husser "] license = "MIT" diff --git a/tests/modules/test/__init__.py b/tests/modules/test/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/modules/test/standalone.py b/tests/modules/test/standalone.py new file mode 100644 index 00000000..e4343154 --- /dev/null +++ b/tests/modules/test/standalone.py @@ -0,0 +1,30 @@ +import asyncio +import logging + +import pytest + +from pyobs.modules.test import StandAlone + + +def test_default(): + module = StandAlone() + assert module._message == "Hello world" + assert module._interval == 10 + + +@pytest.mark.asyncio +async def test_loop(mocker, caplog): + mocker.patch("asyncio.sleep", return_value=None) + module = StandAlone("Testmessage", 3) + + with caplog.at_level(logging.INFO): + await module._loop() + + assert caplog.messages[0] == "Testmessage" + asyncio.sleep.assert_called_once_with(3) + + +@pytest.mark.asyncio +async def test_background_task(): + module = StandAlone() + assert module._message_func in module._background_tasks diff --git a/tests/utils/skyflats/test_scheduler.py b/tests/utils/skyflats/test_scheduler.py index 13bf6b7c..a65ddf4a 100644 --- a/tests/utils/skyflats/test_scheduler.py +++ b/tests/utils/skyflats/test_scheduler.py @@ -4,7 +4,7 @@ from pyobs.utils.skyflats import Scheduler from pyobs.utils.skyflats.priorities import ConstSkyflatPriorities from pyobs.utils.time import Time - +import astropy.units as u pytest_plugins = ("pytest_asyncio",) @@ -12,7 +12,8 @@ @pytest.mark.asyncio async def test_scheduler(): # init observer and time - observer = Observer.at_site("SAAO") + saao_observer = Observer(longitude=20.8108 * u.deg, latitude=-32.375823 * u.deg, + elevation=1798.0 * u.m, timezone="UTC") now = Time("2019-11-21T17:10:00Z") # have some test functions @@ -26,7 +27,7 @@ async def test_scheduler(): priorities = ConstSkyflatPriorities({("B", (1, 1)): 1, ("V", (1, 1)): 2, ("R", (1, 1)): 3}) # create scheduler - scheduler = Scheduler(functions, priorities, observer) + scheduler = Scheduler(functions, priorities, saao_observer) await scheduler(now) # test order