def test_one_outside_range(self):
        start_time = GPSTime.from_datetime(datetime(2020, 4, 28))
        end_time = GPSTime.from_datetime(datetime(2020, 5, 2))
        time = GPSTime.from_datetime(datetime(2021, 5, 1))

        holder = TimeRangeHolder()
        holder.add(start_time, end_time)

        self.assertFalse(time in holder)
    def test_extend_range_right(self):
        merge_range = (GPSTime.from_datetime(datetime(2020, 5, 7)),
                       GPSTime.from_datetime(datetime(2020, 5, 9)))
        range_ = (GPSTime.from_datetime(datetime(2020, 5, 3)),
                  GPSTime.from_datetime(datetime(2020, 5, 7)))
        time = GPSTime.from_datetime(datetime(2020, 5, 8))

        holder = TimeRangeHolder()
        holder.add(*range_)

        self.assertFalse(time in holder)

        holder.add(*merge_range)

        self.assertTrue(time in holder)
Exemple #3
0
    def test_cache(self):
        laikad = Laikad(auto_update=True, save_ephemeris=True)

        def wait_for_cache():
            max_time = 2
            while Params().get(EPHEMERIS_CACHE) is None:
                time.sleep(0.1)
                max_time -= 0.1
                if max_time == 0:
                    self.fail("Cache has not been written after 2 seconds")

        # Test cache with no ephemeris
        laikad.cache_ephemeris(t=GPSTime(0, 0))
        wait_for_cache()
        Params().delete(EPHEMERIS_CACHE)

        laikad.astro_dog.get_navs(self.first_gps_time)
        laikad.fetch_orbits(self.first_gps_time, block=True)

        # Wait for cache to save
        wait_for_cache()

        # Check both nav and orbits separate
        laikad = Laikad(auto_update=False, valid_ephem_types=EphemerisType.NAV)
        # Verify orbits and nav are loaded from cache
        self.dict_has_values(laikad.astro_dog.orbits)
        self.dict_has_values(laikad.astro_dog.nav)
        # Verify cache is working for only nav by running a segment
        msg = verify_messages(self.logs, laikad, return_one_success=True)
        self.assertIsNotNone(msg)

        with patch('selfdrive.locationd.laikad.get_orbit_data',
                   return_value=None) as mock_method:
            # Verify no orbit downloads even if orbit fetch times is reset since the cache has recently been saved and we don't want to download high frequently
            laikad.astro_dog.orbit_fetched_times = TimeRangeHolder()
            laikad.fetch_orbits(self.first_gps_time, block=False)
            mock_method.assert_not_called()

            # Verify cache is working for only orbits by running a segment
            laikad = Laikad(auto_update=False,
                            valid_ephem_types=EphemerisType.ULTRA_RAPID_ORBIT)
            msg = verify_messages(self.logs, laikad, return_one_success=True)
            self.assertIsNotNone(msg)
            # Verify orbit data is not downloaded
            mock_method.assert_not_called()
    def test_merge_ranges(self):
        first_range = (GPSTime.from_datetime(datetime(2020, 5, 1)),
                       GPSTime.from_datetime(datetime(2020, 5, 3)))
        second_range = (GPSTime.from_datetime(datetime(2020, 5, 7)),
                        GPSTime.from_datetime(datetime(2020, 5, 9)))
        merge_range = (GPSTime.from_datetime(datetime(2020, 5, 2)),
                       GPSTime.from_datetime(datetime(2020, 5, 8)))
        time = GPSTime.from_datetime(datetime(2020, 5, 5))

        holder = TimeRangeHolder()
        holder.add(*first_range)
        holder.add(*second_range)

        self.assertFalse(time in holder)

        holder.add(*merge_range)

        self.assertTrue(time in holder)
 def test_empty(self):
     time = GPSTime.from_datetime(datetime(2020, 5, 1, 0, 0, 0))
     holder = TimeRangeHolder()
     self.assertFalse(time in holder)