Skip to content

Commit

Permalink
update black
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-dupre committed Feb 26, 2021
1 parent 9f1c5f5 commit 1504697
Show file tree
Hide file tree
Showing 25 changed files with 148 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Pipfile
Expand Up @@ -19,7 +19,7 @@ lovely-pytest-docker = "*"
freezegun = "*"
ipython = "*"
responses = "*"
black = "==19.10b0"
black = "==20.8b1"
respx = "*"
pylint = "*"

Expand Down
19 changes: 17 additions & 2 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion idunn/api/instant_answer.py
Expand Up @@ -38,7 +38,9 @@ class InstantAnswerResult(BaseModel):
),
example=(2.32, 48.85, 2.367, 48.866),
)
maps_url: HttpUrl = Field(description="Direct URL to the result(s) on Qwant Maps.",)
maps_url: HttpUrl = Field(
description="Direct URL to the result(s) on Qwant Maps.",
)
maps_frame_url: HttpUrl = Field(
description="URL to the map displaying the results on Qwant Maps, with no user interface. "
"This URL can be used to display an `<iframe>`."
Expand Down
10 changes: 8 additions & 2 deletions idunn/api/places_list.py
Expand Up @@ -193,7 +193,10 @@ async def get_places_bbox(
)

return PlacesBboxResponse(
places=result_places, source=params.source, bbox=results_bbox, bbox_extended=bbox_extended,
places=result_places,
source=params.source,
bbox=results_bbox,
bbox_extended=bbox_extended,
)


Expand All @@ -220,7 +223,10 @@ async def _fetch_places_list(params: PlacesQueryParam):
raw_filters = [f for c in params.category for f in c.raw_filters()]

bbox_places = await run_in_threadpool(
fetch_es_pois, raw_filters=raw_filters, bbox=params.bbox, max_size=params.size,
fetch_es_pois,
raw_filters=raw_filters,
bbox=params.bbox,
max_size=params.size,
)
return [POI(p["_source"]) for p in bbox_places]

Expand Down
3 changes: 1 addition & 2 deletions idunn/api/status.py
Expand Up @@ -7,8 +7,7 @@


def get_status():
"""Returns the status of the elastic cluster
"""
"""Returns the status of the elastic cluster"""
es = get_elasticsearch()
try:
cluster_health = es.cluster.health()
Expand Down
4 changes: 3 additions & 1 deletion idunn/blocks/wikipedia.py
Expand Up @@ -48,7 +48,9 @@ def wrapped_f(*args, **kwargs):
except pybreaker.CircuitBreakerError:
prometheus.exception("CircuitBreakerError")
logger.error(
"Got CircuitBreakerError in %s", f.__name__, exc_info=True,
"Got CircuitBreakerError in %s",
f.__name__,
exc_info=True,
)
except HTTPError:
prometheus.exception("HTTPError")
Expand Down
3 changes: 2 additions & 1 deletion idunn/datasources/pages_jaunes.py
Expand Up @@ -140,7 +140,8 @@ def get_places_from_url(self, url, params=None, size=10):
and res.context.pages.next_page_url
):
pois += self.get_places_from_url(
res.context.pages.next_page_url, size=size - len(pois),
res.context.pages.next_page_url,
size=size - len(pois),
)

return pois
Expand Down
3 changes: 2 additions & 1 deletion idunn/directions/client.py
Expand Up @@ -174,7 +174,8 @@ def directions_combigo(self, start, end, mode, lang):
def get_directions(self, from_place, to_place, mode, lang, params: QueryParams):
if not DirectionsClient.is_in_allowed_zone(mode, from_place, to_place):
raise HTTPException(
status_code=422, detail="requested path is not inside an allowed area",
status_code=422,
detail="requested path is not inside an allowed area",
)

method = self.directions_qwant
Expand Down
4 changes: 2 additions & 2 deletions idunn/geocoder/nlu_client.py
Expand Up @@ -74,7 +74,7 @@ async def nlu_classifier(self, text):

@staticmethod
def regex_classifier(text, is_brand=False):
""" Match text with a category, using 'regex'
"""Match text with a category, using 'regex'
>>> NLU_Helper.regex_classifier("restau").value
'restaurant'
>>> NLU_Helper.regex_classifier("pub").value
Expand All @@ -98,7 +98,7 @@ async def classify_category(self, text, is_brand=False):

@classmethod
def fuzzy_match(cls, query, bragi_res):
""" Does the response match the query reasonably well ?
"""Does the response match the query reasonably well ?
>>> NLU_Helper.fuzzy_match("bastille", {"name": "Beuzeville-la-Bastille"})
False
>>> NLU_Helper.fuzzy_match("paris 20", {"name": "Paris 20e Arrondissement"})
Expand Down
6 changes: 5 additions & 1 deletion idunn/utils/logging.py
Expand Up @@ -23,7 +23,11 @@ def get_logging_dict(settings):
},
"loggers": {
"uvicorn": {"level": "INFO", "handlers": ["console"], "propagate": False},
"uvicorn.access": {"level": "WARNING", "handlers": ["console"], "propagate": False,},
"uvicorn.access": {
"level": "WARNING",
"handlers": ["console"],
"propagate": False,
},
"gunicorn": {"level": "INFO", "handlers": ["console"], "propagate": False},
# "gunicorn.error" logger needs to be defined explicitly,
# as it will be used by UvicornWorker to configure its own error logger
Expand Down
8 changes: 6 additions & 2 deletions idunn/utils/prometheus.py
Expand Up @@ -52,15 +52,19 @@ def expose_metrics_multiprocess():


REQUEST_DURATION = Histogram(
"http_request_duration_seconds", "Time spent processing a request.", ["method", "handler"],
"http_request_duration_seconds",
"Time spent processing a request.",
["method", "handler"],
)
REQUEST_COUNT = Counter(
"http_requests_total",
"Request count by method, handler and response code.",
["method", "handler", "code"],
)
REQUESTS_INPROGRESS = Gauge(
"http_requests_inprogress", "Requests in progress by method and handler", ["method", "handler"],
"http_requests_inprogress",
"Requests in progress by method and handler",
["method", "handler"],
)


Expand Down
4 changes: 3 additions & 1 deletion idunn/utils/result_filter.py
Expand Up @@ -157,7 +157,9 @@ def coverage(terms):

if not check_coverage:
logger.info(
"Removed `%s` from results because query `%s` is not accurate enough", name, query,
"Removed `%s` from results because query `%s` is not accurate enough",
name,
query,
)
return False

Expand Down
11 changes: 10 additions & 1 deletion tests/test_accessibility.py
Expand Up @@ -13,7 +13,16 @@ def test_accessibility_block():


def test_accessibility_unknown():
web_block = AccessibilityBlock.from_es(POI({"properties": {"wheelchair": "toto",}}), lang="en")
web_block = AccessibilityBlock.from_es(
POI(
{
"properties": {
"wheelchair": "toto",
}
}
),
lang="en",
)
assert web_block is None


Expand Down
14 changes: 12 additions & 2 deletions tests/test_autocomplete.py
Expand Up @@ -127,7 +127,12 @@ def test_autocomplete_with_nlu_brand_focus(mock_autocomplete_get, mock_NLU_with_
assert_intention(
client,
params={"q": "auchan", "lang": "fr", "limit": 7, "nlu": True, "lat": 48.9, "lon": 2.3},
expected_intention=[{"filter": {"q": "auchan"}, "description": {"query": "auchan"},}],
expected_intention=[
{
"filter": {"q": "auchan"},
"description": {"query": "auchan"},
}
],
expected_intention_place=None,
)

Expand Down Expand Up @@ -183,6 +188,11 @@ def test_no_intention_for_brand_with_no_matching_feature(

assert_intention(
client,
params={"q": "this is not a brand", "lang": "fr", "limit": 7, "nlu": True,},
params={
"q": "this is not a brand",
"lang": "fr",
"limit": 7,
"nlu": True,
},
expected_intention=[],
)
22 changes: 12 additions & 10 deletions tests/test_categories.py
Expand Up @@ -259,8 +259,8 @@ def test_bbox():
@freeze_time("2018-06-14 8:30:00", tz_offset=2)
def test_size_list():
"""
Test the bbox query with a list size=1:
Same test as test_bbox but with a max list size of 1
Test the bbox query with a list size=1:
Same test as test_bbox but with a max list size of 1
"""
client = TestClient(app)

Expand Down Expand Up @@ -481,7 +481,7 @@ def test_extend_bbox():

def test_invalid_bbox():
"""
Test an invalid bbox query:
Test an invalid bbox query:
"""
client = TestClient(app)

Expand Down Expand Up @@ -512,7 +512,7 @@ def test_invalid_bbox():

def test_category_and_raw_filter():
"""
Test we get a 400 if category and raw_filter are both present:
Test we get a 400 if category and raw_filter are both present:
"""
client = TestClient(app)

Expand All @@ -529,7 +529,7 @@ def test_category_and_raw_filter():

def test_category_or_raw_filter():
"""
Test we get a 400 if none of category or raw_filter is present:
Test we get a 400 if none of category or raw_filter is present:
"""
client = TestClient(app)

Expand All @@ -542,7 +542,7 @@ def test_category_or_raw_filter():

def test_valid_category():
"""
Test a valid category filter which should fetch only one cinema in a bbox around Brest city.
Test a valid category filter which should fetch only one cinema in a bbox around Brest city.
"""
client = TestClient(app)

Expand Down Expand Up @@ -586,7 +586,7 @@ def test_valid_category():
)
def test_places_with_explicit_source_osm(enable_pj_source):
"""
If source=osm is passed to the query, pj_source should be ignored
If source=osm is passed to the query, pj_source should be ignored
"""
client = TestClient(app)
response = client.get(
Expand Down Expand Up @@ -625,7 +625,7 @@ def test_places_with_explicit_source_osm(enable_pj_source):

def test_invalid_category():
"""
Test we get a 400 if the parameter category is invalid:
Test we get a 400 if the parameter category is invalid:
"""
client = TestClient(app)
response = client.get(
Expand All @@ -638,7 +638,7 @@ def test_invalid_category():

def test_endpoint_categories():
"""
Test the endpoint 'categories':
Test the endpoint 'categories':
"""
client = TestClient(app)

Expand All @@ -654,7 +654,9 @@ def test_endpoint_categories():


@pytest.mark.parametrize(
"enable_pj_source", [("legacy", "musee_picasso_short")], indirect=True,
"enable_pj_source",
[("legacy", "musee_picasso_short")],
indirect=True,
)
def test_pj_categories_filter_legacy(enable_pj_source):
client = TestClient(app)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_contact.py
Expand Up @@ -8,5 +8,6 @@ def test_contact_block():
)

assert web_block == ContactBlock(
url="mailto:info@pershinghall.com", email="info@pershinghall.com",
url="mailto:info@pershinghall.com",
email="info@pershinghall.com",
)
13 changes: 10 additions & 3 deletions tests/test_directions.py
Expand Up @@ -19,7 +19,9 @@ def mock_directions_car():
}
):
fixture_path = os.path.join(
os.path.dirname(__file__), "fixtures/directions", "qwant_directions_car.json",
os.path.dirname(__file__),
"fixtures/directions",
"qwant_directions_car.json",
)
with responses.RequestsMock() as rsps:
rsps.add(
Expand All @@ -44,7 +46,9 @@ def mock_directions_car_with_rate_limiter(redis, mock_directions_car):
def mock_directions_public_transport():
with override_settings({"COMBIGO_API_BASE_URL": "http://api.test"}):
fixture_path = os.path.join(
os.path.dirname(__file__), "fixtures/directions", "combigo_v1.1_publictransport.json",
os.path.dirname(__file__),
"fixtures/directions",
"combigo_v1.1_publictransport.json",
)
with responses.RequestsMock() as rsps:
rsps.add(
Expand Down Expand Up @@ -183,7 +187,10 @@ def test_directions_public_transport_restricted_areas():

def test_directions_not_configured():
with override_settings(
{"QWANT_DIRECTIONS_API_BASE_URL": None, "MAPBOX_DIRECTIONS_ACCESS_TOKEN": None,}
{
"QWANT_DIRECTIONS_API_BASE_URL": None,
"MAPBOX_DIRECTIONS_ACCESS_TOKEN": None,
}
):
client = TestClient(app)
response = client.get(
Expand Down
12 changes: 10 additions & 2 deletions tests/test_environment_weather.py
Expand Up @@ -147,7 +147,12 @@ def test_weather_city():

res = Weather.from_es(Admin(testee), lang="en")

assert res == Weather(**{"temperature": 291.89, "icon": "01d",})
assert res == Weather(
**{
"temperature": 291.89,
"icon": "01d",
}
)


@enable_weather_api()
Expand All @@ -157,7 +162,10 @@ def test_wrong_icon_value():
"""
with raises(ValidationError):
Weather(
**{"temperature": 291.89, "icon": "01g",}
**{
"temperature": 291.89,
"icon": "01g",
}
)


Expand Down

0 comments on commit 1504697

Please sign in to comment.