async def test_clock_indicator(ovshell: testing.OpenVarioShellStub,
                               monkeypatch) -> None:
    # GIVEN
    datetime_mock = mock.Mock()
    datetime_mock.utcnow.return_value = datetime(2020, 6, 2, 12, 32, 54)
    monkeypatch.setattr("ovshell_core.gpstime.datetime", datetime_mock)
    monkeypatch.setattr("ovshell_core.gpstime.CLOCK_POLL_INTERVAL", 0.01)
    state = gpstime.GPSTimeState()

    # WHEN
    task = asyncio.create_task(gpstime.clock_indicator(ovshell.screen, state))
    await asyncio.sleep(0)

    clockind = ovshell.screen.stub_get_indicator("clock")
    assert clockind is not None
    assert clockind.markup == ("ind error", "12:32 UTC")
    assert clockind.location == protocol.IndicatorLocation.LEFT

    state.acquired = True
    await asyncio.sleep(0.02)
    clockind = ovshell.screen.stub_get_indicator("clock")
    assert clockind is not None
    assert clockind.markup == ("ind normal", "12:32 UTC")
    assert clockind.location == protocol.IndicatorLocation.LEFT

    task.cancel()
async def test_gps_time_sync(ovshell: testing.OpenVarioShellStub,
                             monkeypatch) -> None:
    # GIVEN
    subpr_mock = mock.Mock()
    monkeypatch.setattr("ovshell_core.gpstime.subprocess", subpr_mock)

    gprmc_fields = "225446,A,4916.45,N,12311.12,W,000.5,054.7,191194,020.3"
    ovshell.devices.stub_add_nmea([
        protocol.NMEA("", "", "ZZZ", []),
        protocol.NMEA("", "", "GPRMC", gprmc_fields.split(",")),
        protocol.NMEA("", "", "AAA", []),
    ])
    state = gpstime.GPSTimeState()

    # WHEN
    await gpstime.gps_time_sync(ovshell, state)

    # THEN
    assert state.acquired is True
    datebin = ovshell.os.path("//bin/date")
    subpr_mock.run.assert_called_with(
        [datebin, "+%F %H:%M:%S", "-s", "1994-11-19 22:54:46"],
        check=True,
        capture_output=True,
    )
예제 #3
0
    def start(self) -> None:
        self.shell.processes.start(serial.maintain_serial_devices(self.shell))

        gpsstate = gpstime.GPSTimeState()
        self.shell.processes.start(gpstime.gps_time_sync(self.shell, gpsstate))
        self.shell.processes.start(gpstime.clock_indicator(self.shell.screen, gpsstate))

        simfile = os.environ.get("OVSHELL_CORE_SIMULATE_DEVICE")
        if simfile:
            devsim.run_simulated_device(self.shell, simfile)

        self.shell.processes.start(devindicators.show_device_indicators(self.shell))