Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
def test_Sensor(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.save_images = True
        c.light_sensor.freq = timedelta(minutes=20)
        c.light_sensor.max_age = timedelta(hours=1)
        c.configs("""
        [location]
        city = "Brisbane"
        [camera]
        interval = 300
        # test ON at first light, then off when dark (i.e. all day)
        on = 'light'
        off =  'dim'
        camera_inactive_action = 'WAIT'
    
       
    
        """)
        c.mode_button.value = AUTO
        reset_camera = deepcopy(c)  # a copy of the camera after it starts
        run_until(c, fdt, tomorrow_at(12), reset_camera)
        run_until(c, fdt, today_at(18, 00), reset_camera)
        run_until(c, fdt, today_at(23, 59), reset_camera)
        run_until(c, fdt, tomorrow_at(9, 00), reset_camera)
        reset_camera.run(1)
        assert reset_camera.active_timer.light_sensor.level == LightLevel.LIGHT
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
def test_latest_image(setup_test):
    cf = """
    [camera]
    tmv_root = "."
    """
    c = Camera(sw_cam=True)
    c.configs(cf)
    cwd = Path(os.getcwd())
    assert (cwd / "latest-image.jpg").absolute() == c.latest_image.absolute()
Ejemplo n.º 5
0
def test_speeds(setup_test):
    """ Test interval change with speed button"""
    c = Camera(sw_cam=True)
    assert c._interval == timedelta(seconds=60)
    cf = """
    [camera]
    interval = 100
    """

    c.configs(cf)
    assert c.interval == timedelta(seconds=100)
    c.speed_button.value = SLOW
    assert c.interval == timedelta(seconds=100 * SPEED_MULTIPLIER)
    c.speed_button.value = FAST
    assert c.interval == timedelta(seconds=100 / SPEED_MULTIPLIER)
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
def test_overlays(monkeypatch, setup_test):
    cf = """
       [camera]
            overlays = [ "spinny", "image_name","simple_settings", "bottom_band"]

        """

    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._camera.width = 1200
        #c._camera.height = 900
        c.configs(cf)
        c.file_by_date = False

        run_until(c, fdt, today_at(13))
Ejemplo n.º 8
0
def test_camera_inactive_action_2(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.save_images = False
        c.configs("""
        [camera]
        interval = 900 # 15 minutes
        on = 'dim'
        off = 'dark'
        camera_inactive_action = 'EXCEPTION'       
        """)
        # with pytest.raises(PowerOff):
        run_until(c, fdt, today_at(14))
        assert c.light_sensor.level == LightLevel.LIGHT
        assert c.active_timer.active()
        assert c.active_timer.camera_active()
Ejemplo n.º 9
0
def test_location():
    cf = """
    [camera]
    on = 'dawn'
    off = 'dusk'
    """
    # no location: fail
    c = Camera(sw_cam=True)

    with pytest.raises(tmv.camera.ConfigError):
        c.configs(cf)

    cf = """
    
    
    [camera]
    city = 'Brisbane'
    on = 'dawn'
    off = 'dusk'
    """
    #  location: ok
    c.configs(cf)

    cf = """
    
    [camera]
    city = 'auto'
    on = 'dawn'
    off = 'dusk'
    """
    # no location: fail

    with pytest.raises(NotImplementedError):
        c.configs(cf)