def test_fake(monkeypatch, setup_test): with freeze_time(parse("2000-01-01 12:00:00")) as fdt: global FDT FDT = fdt monkeypatch.setattr(time, 'sleep', sleepless) c = Camera(sw_cam=True) c.file_by_date = False c._interval = timedelta(minutes=10) run_until(c, fdt, today_at(13)) assert len(c.recent_images) == 6 + 1 # fencepost images = sorted(glob(os.path.join(c.tmv_root, "2000-01-01T*"))) assert len(images) == 6 + 1 # fencepost # run 13:00 - 14:00 with switch AUTO c.mode_button.value = AUTO run_until(c, fdt, today_at(14)) assert c.active_timer.active() # active images = sorted(glob(os.path.join(c.tmv_root, "2000-01-01T*"))) assert len(images) == 6 + 1 + 6 # one hour more of 6 photos per hour # run 14:00 - 15:00 with switch ON c.active_timer = Timed(datetime.time(6, 0, 0), datetime.time(7, 0, 0)) c.mode_button.value = ON run_until(c, fdt, today_at(15)) assert not c.active_timer.active() # not active - but overridden by switch images = sorted(glob(os.path.join(c.tmv_root, "2000-01-01T*"))) # one hour more of 6 photos per hour assert len(images) == 6 + 1 + 6 + 6 assert Path("./latest-image.jpg").is_file()
def test_Sensor_lookups(): c = Camera(sw_cam=True) c.active_timer = tmv.camera.ActiveTimes.factory( on='dim', off='dark', camera=c) c.light_sensor._current_level = LightLevel.LIGHT assert c.active_timer.camera_active() c = Camera(sw_cam=True) ss = tmv.camera.ActiveTimes.factory(on='dim', off='dark', camera=c) c.light_sensor._current_level = LightLevel.DARK # Active, as sensor will operate assert ss.active() is True # But could power off if camera not required (it's DARK) assert timedelta(minutes=59) <= ( ss.waketime() - dt.now()) <= timedelta(minutes=61) c.light_sensor._current_level = LightLevel.DIM # Still active assert ss.active() # But can't power off for long (camera is active) assert ss.waketime() <= dt.now() c.light_sensor._current_level = LightLevel.LIGHT assert ss.waketime() <= dt.now() c.light_sensor._current_level = LightLevel.DIM assert ss.waketime() <= dt.now() c.light_sensor._current_level = LightLevel.DARK # active, but only the sensor assert ss.active() assert timedelta(minutes=59) <= ( ss.waketime() - dt.now()) <= timedelta(minutes=61) # c.light_sensor._current_level = LightLevel.LIGHT # ON when DIM, OFF when DARK, should be ON when light assert ss.active()
def check_test_fake2(monkeypatch, setup_test): s = 3 c = Camera(sw_cam=True) c.tmv_root = "./test_fake2/" c.file_by_date = False c.interval = timedelta(seconds=1) c.active_timer = ActiveTimes.factory(dt.now().astimezone().time( ), (dt.now() + timedelta(seconds=s)).astimezone().time(), c) c.camera_inactive_action = CameraInactiveAction.EXCEPTION with pytest.raises(PowerOff): c.run() assert len(c.recent_images) == s + 1 # fencepost images = glob(os.path.join(c.tmv_root, "*.jpg")) assert len(images) == s + 1 # fencepost
def test_Timed_capture(monkeypatch, setup_test): with freeze_time(parse("2000-01-01 06:00:00")) as fdt: global FDT FDT = fdt monkeypatch.setattr(time, 'sleep', sleepless) c = Camera(sw_cam=True) c.mode_button.value = AUTO c.mode_button.button_path = Path("./camera-switch") c.file_by_date = False #c._camera = FakePiCamera() c._interval = timedelta(minutes=60) c.active_timer = Timed(datetime.time(12), datetime.time(18)) run_until(c, fdt, today_at(23)) images = glob(os.path.join(c.tmv_root, "2000-01-01T*")) assert len(images) == 18 - 12 + 1 # +1 for a fencepost