shared config for tests,add fallback location test
This commit is contained in:
parent
ec1ea9710e
commit
c707116d31
7 changed files with 206 additions and 58 deletions
|
@ -32,6 +32,7 @@ def _gpslogger_locations() -> Iterator[Location]:
|
|||
yield from gpslogger.locations()
|
||||
|
||||
|
||||
# TODO: remove, user should use fallback.estimate_location or fallback.fallback_locations instead
|
||||
@import_source(module_name="my.location.via_ip")
|
||||
def _ip_locations() -> Iterator[Location]:
|
||||
from . import via_ip
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# TODO: add config here which passes kwargs to estimate_from (under_accuracy)
|
||||
# overwritable by passing the kwarg name here to the top-level estimate_location
|
||||
|
||||
from typing import Iterator
|
||||
from typing import Iterator, Optional
|
||||
|
||||
from my.core.source import import_source
|
||||
from my.location.fallback.common import (
|
||||
|
@ -12,8 +12,8 @@ from my.location.fallback.common import (
|
|||
)
|
||||
|
||||
|
||||
# can comment/uncomment sources here to enable/disable them
|
||||
def fallback_locations() -> Iterator[FallbackLocation]:
|
||||
# can comment/uncomment sources here to enable/disable them
|
||||
yield from _ip_fallback_locations()
|
||||
|
||||
|
||||
|
@ -24,8 +24,8 @@ def fallback_estimators() -> Iterator[LocationEstimator]:
|
|||
yield _home_estimate
|
||||
|
||||
|
||||
def estimate_location(dt: DateExact) -> FallbackLocation:
|
||||
loc = estimate_from(dt, estimators=list(fallback_estimators()))
|
||||
def estimate_location(dt: DateExact, first_match: bool=False, under_accuracy: Optional[int] = None) -> FallbackLocation:
|
||||
loc = estimate_from(dt, estimators=list(fallback_estimators()), first_match=first_match, under_accuracy=under_accuracy)
|
||||
# should never happen if the user has home configured
|
||||
if loc is None:
|
||||
raise ValueError("Could not estimate location")
|
||||
|
|
|
@ -86,8 +86,9 @@ def estimate_location(dt: DateExact) -> Iterator[FallbackLocation]:
|
|||
if start_time <= dt_ts <= end_time:
|
||||
# logger.debug(f"Found location for {dt}: {loc}")
|
||||
yield loc
|
||||
if end_time > dt_ts:
|
||||
# logger.debug(f"Passed end time: {end_time} > {dt_ts} ({datetime.fromtimestamp(end_time)} > {datetime.fromtimestamp(dt_ts)})")
|
||||
# no more locations could possibly contain dt
|
||||
if start_time > dt_ts:
|
||||
# logger.debug(f"Passed start time: {end_time} > {dt_ts} ({datetime.fromtimestamp(end_time)} > {datetime.fromtimestamp(dt_ts)})")
|
||||
break
|
||||
idx += 1
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue