Skip to content

Commit

Permalink
version 0.1.4 (fixed bug in cam runner: does not fail if missing loca…
Browse files Browse the repository at this point in the history
…l info keys)

* cam runners now ProcessRunners

* version 0.1.3

* updated lock file

* fixed bug in cam runner: does not fail if missing local info keys

* version 0.1.4

---------

Co-authored-by: Vincent Berenz <vincent.berenz@tuebingen.mpg.de>
  • Loading branch information
vincentberenz and Vincent Berenz authored Oct 26, 2024
1 parent e398c94 commit ab4b5fc
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 9 deletions.
11 changes: 7 additions & 4 deletions nightskycam/cams/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,10 @@ def get_local_info(
tnow = time.time()
if tnow - ts > deprecation:
return None, None, None
return tuple(
memory[key] # type: ignore
for key in ("night", "weather", "cloud_cover")
)
try:
return tuple(
memory[key] # type: ignore
for key in ("night", "weather", "cloud_cover")
)
except KeyError:
return None, None, None
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nightskycam"
version = "0.1.3"
version = "0.1.4"
description = "taking pictures at night"
authors = ["Vincent Berenz <vberenz@tuebingen.mpg.de>"]
packages = [{ include = "nightskycam" }]
Expand Down
45 changes: 41 additions & 4 deletions tests/test_cam_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
import datetime
import tempfile
import time
from contextlib import suppress
from pathlib import Path
from typing import Generator, List

import pytest
from nightskyrunner.config import Config
from nightskyrunner.shared_memory import SharedMemory
from nightskyrunner.status import State, wait_for_status

from nightskycam.cams import utils
from nightskycam.cams.runner import CamRunner
from nightskycam.dummycams.runner import DummyCamRunner
Expand All @@ -21,6 +18,9 @@
exception_on_error_state,
get_manager, runner_started,
wait_for)
from nightskyrunner.config import Config
from nightskyrunner.shared_memory import SharedMemory
from nightskyrunner.status import State, wait_for_status


@pytest.fixture
Expand Down Expand Up @@ -211,6 +211,17 @@ def _set_local_info(
memory["cloud_cover"] = cloud_cover
memory["time_stamp"] = time_stamp


def _set_failed_local_info(
time_stamp: float
) -> None:
memory = SharedMemory.get(LocationInfoRunner.sm_key)
with suppress(KeyError):
del memory["night"]
del memory["weather"]
del memory["cloud_cover"]
memory["time_stamp"] = time_stamp


def test_get_local_info(reset_memory) -> None:
"""
Expand Down Expand Up @@ -363,3 +374,29 @@ def test_wait_duration() -> None:

assert sleep1 == pytest.approx(1.0 - 5000 * 1e-6)
assert sleep2 == pytest.approx(1.0 - 601 * 1e-6)


def test_no_local_info(tmp_dir)->None:

time_stamp = time.time()
_set_failed_local_info(time_stamp)

config: Config = {
"frequency": 5.0,
"destination_folder": str(tmp_dir),
"start_time": "19:30",
"end_time": "08:00",
"use_sun_alt": True,
"use_weather": True,
"cloud_cover_threshold": 70,
"nightskycam": "test_system",
"pause": False,
}

with get_manager((DummyCamRunner, config)):
wait_for(runner_started, True, args=(DummyCamRunner.__name__,))
wait_for_status(DummyCamRunner.__name__, State.running, timeout=2.0)
exception_on_error_state(DummyCamRunner.__name__)



0 comments on commit ab4b5fc

Please sign in to comment.