def test_SunCalc(monkeypatch, setup_test): # dawn: datetime.time(4, 28, 38, 892410) # sunrise:datetime.time(4, 55, 38, 480930) # noon: datetime.time(11, 50, 59) # sunset datetime.time(18, 46, 18, 926896) # dusk datetime.time(19, 13, 17, 159158) with freeze_time(parse("2000-01-01 00:00:00")) as fdt: global FDT FDT = fdt monkeypatch.setattr(time, 'sleep', sleepless) c = Camera(sw_cam=True) c.save_images = False c.configs(""" [camera] city = 'Brisbane' interval = 600 on = 'dawn' off = 'sunset' # (2000, 1, 1, 18, 46, 18, 926896, tzinfo=tzlocal()) camera_inactive_action = 'WAIT' """) c._camera = FakePiCamera() assert c.active_timer.active() is False run_until(c, fdt, today_at(4, 30)) assert c.active_timer.active() is True run_until(c, fdt, today_at(12, 30)) assert c.active_timer.active() is True run_until(c, fdt, today_at(18, 30)) assert c.active_timer.active() is True run_until(c, fdt, today_at(18, 40)) run_until(c, fdt, today_at(18, 50)) assert c.active_timer.active() is False run_until(c, fdt, tomorrow_at(8)) assert c.active_timer.active() is True
def test_camera_inactive_action(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.mode_button.value = AUTO c.save_images = False c.configs(""" [camera] interval = 900 # 15 minutes on = 09:00:00 off = 13:00:00 camera_inactive_action = 'EXCEPTION' """) c._camera = FakePiCamera() c.mode_button.value = AUTO with pytest.raises(PowerOff): run_until(c, fdt, today_at(18)) c.configs(""" [camera] on = 09:00:00 off = 13:00:00 camera_inactive_action = 'WAIT' """) run_until(c, fdt, tomorrow_at(18)) # no raise
def test_config(monkeypatch, setup_test): with freeze_time(parse("2000-01-01 00:00:00")) as fdt: global FDT FDT = fdt c = Camera(sw_cam=True) c.tmv_root = "./test_config/" cf = """ [location] city = "Brisbane" [camera] off = 07:00:00 on = 18:00:00 [camera.picam.LIGHT] id = "Custom day config at 800" iso = 800 exposure_mode = "auto" resolution = "800x600" [camera.picam.DIM] id = "CUSTOM-DIM" framerate = 1 iso = 0 exposure_mode = "night" resolution = "800x600" [camera.picam.DARK] id = "CUSTOM-NIGHTY" framerate = 1 iso = 1600 shutter_speed = 1000000 exposure_mode = "verylong" resolution = "800x600" """ c.configs(cf) # default assert c.picam[LightLevel.LIGHT.name]['exposure_mode'] == 'auto' assert c.picam[LightLevel.LIGHT.name]['resolution'] == '800x600' # new one assert c.picam[LightLevel.LIGHT.name]['iso'] == 800 c._camera = FakePiCamera() # fake sleeping monkeypatch.setattr(time, 'sleep', sleepless) c.run(3) # should have clicked over to DARK. Configured a special iso for DARK in toml. assert c.picam[c.light_sensor.level.name]['iso'] == 1600 c.run(1)