예제 #1
0
def no_parents(
    request: ValueMatcher[Optional[str]],
    scope: ValueMatcher[Optional[MapRegion]] = empty(),
    ambiguity_resolver: ValueMatcher[AmbiguityResolver] = eq(
        AmbiguityResolver.empty())
) -> QueryMatcher:
    return QueryMatcher(name=request,
                        scope=scope,
                        ambiguity_resolver=ambiguity_resolver,
                        country=empty(),
                        state=empty(),
                        county=empty())
def _query(request: Optional[str],
           scope: Optional[MapRegion] = None,
           ambiguity_resolver: AmbiguityResolver = AmbiguityResolver.empty()):
    return RegionQuery(request, scope, ambiguity_resolver)
예제 #3
0
#  Copyright (c) 2020. JetBrains s.r.o.
#  Use of this source code is governed by the MIT license that can be found in the LICENSE file.

from typing import Optional, List

import pytest

from lets_plot.geo_data.gis.request import MapRegion, RegionQuery, MISSING_LEVEL_AND_SCOPE_OR_REQUEST_EXCEPTION_TEXT, \
    MISSING_LEVEL_OR_REQUEST_EXCEPTION_TEXT, GeocodingRequest, \
    AmbiguityResolver
from lets_plot.geo_data.gis.response import LevelKind

REACTION_KIND_ALERT: AmbiguityResolver = AmbiguityResolver.empty()

NAME = 'NY'
LEVEL: LevelKind = LevelKind.city
REGION_STR = 'ignored'
PARENT = MapRegion.with_name(REGION_STR)


@pytest.mark.parametrize('region_queries,level,message', [
    ([], None, MISSING_LEVEL_AND_SCOPE_OR_REQUEST_EXCEPTION_TEXT),
    ([RegionQuery(None, None, REACTION_KIND_ALERT)], None, MISSING_LEVEL_AND_SCOPE_OR_REQUEST_EXCEPTION_TEXT),
    ([RegionQuery(None, PARENT, REACTION_KIND_ALERT)], None, MISSING_LEVEL_OR_REQUEST_EXCEPTION_TEXT),
])
def test_args_that_fail(region_queries: List[RegionQuery],
                        level: Optional[LevelKind],
                        message: str):
    with pytest.raises(ValueError) as exception:
        GeocodingRequest._check_required_parameters(region_queries, level)