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_low_light_sense(monkeypatch, setup_test): 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.file_by_date = False c._interval = timedelta(hours=1) c.light_sensor.light = 0.6 c.light_sensor.dark = 0.1 c.light_sensor.freq = timedelta(minutes=10) c.light_sensor.max_age = timedelta(minutes=60) assert c.light_sensor.level == LightLevel.LIGHT # starts LIGHT by default run_until(c, fdt, today_at(3)) assert c.light_sensor.level == LightLevel.DARK run_until(c, fdt, today_at(10)) assert c.light_sensor.level == LightLevel.DIM run_until(c, fdt, today_at(12)) assert c.light_sensor.level == LightLevel.LIGHT run_until(c, fdt, today_at(16, 30)) assert c.light_sensor.level == LightLevel.DIM run_until(c, fdt, today_at(23)) assert c.light_sensor.level == LightLevel.DARK images = glob(os.path.join(c.tmv_root, "2000-01-01T*")) assert len(images) == 24
def test_video(monkeypatch, setup_test): c = Camera(sw_cam=True) c.file_by_date = False with freeze_time(parse("2000-01-01 12:00:00")) as fdt: global FDT FDT = fdt real_sleep = time.sleep monkeypatch.setattr(time, 'sleep', sleepless) # start normally c.mode_button.value = ON c._interval = timedelta(seconds=60) while dt.now() < today_at(13): c.run(1) fdt.tick(timedelta(seconds=1)) # switch to video mode c.mode_button.value = VIDEO vtd = threading.Thread(target=video_server, args=(c, fdt), daemon=True) vtd.start() real_sleep(3) c.mode_button.value = OFF vtd.join() real_sleep(1) # switch to video mode agina : ok c.mode_button.value = VIDEO vtd = threading.Thread(target=video_server, args=(c, fdt), daemon=True) vtd.start() real_sleep(3) c.mode_button.value = OFF vtd.join()
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