Skip to content
This repository was archived by the owner on Sep 5, 2023. It is now read-only.

Commit e178ee9

Browse files
author
Kharude, Sachin
committed
black formatted notebooks
Signed-off-by: Kharude, Sachin <[email protected]>
1 parent 6f6c11e commit e178ee9

9 files changed

+58
-43
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
all: black build install typing lint test docs
44

55
black:
6-
black -l 99 here_location_services tests
6+
black -l 99 here_location_services tests docs/notebooks
77
isort --atomic .
88

99
build:
@@ -42,7 +42,7 @@ typing:
4242
lint:
4343
isort --check --diff here_location_services tests
4444
flake8 -v --statistics --count .
45-
black -l 99 --diff --check here_location_services tests
45+
black -l 99 --diff --check here_location_services tests docs/notebooks
4646

4747
test:
4848
pytest -v -s --cov=here_location_services tests

docs/notebooks/authentication.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,12 @@
132132
"metadata": {},
133133
"outputs": [],
134134
"source": [
135-
"# credentials will be picked up from credentials.properties file placed at default location. \n",
135+
"# credentials will be picked up from credentials.properties file placed at default location.\n",
136136
"from here_location_services import LS\n",
137137
"\n",
138138
"# platform credentials will be picked from the default credentials file's location mentioned above\n",
139139
"# and api_key should not be set in env variable LS_API_KEY in order to use oauth credentials.\n",
140-
"ls = LS() "
140+
"ls = LS()"
141141
]
142142
},
143143
{

docs/notebooks/autosuggest.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"metadata": {},
2828
"outputs": [],
2929
"source": [
30-
"os.environ[\"LS_API_KEY\"] = \"MY-API-KEY\" # replace your API key here."
30+
"os.environ[\"LS_API_KEY\"] = \"MY-API-KEY\" # replace your API key here."
3131
]
3232
},
3333
{

docs/notebooks/isoline_routing_restaurant_search.ipynb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"outputs": [],
2626
"source": [
2727
"import os\n",
28-
"os.environ[\"LS_API_KEY\"] = \"MY-API-KEY\" # replace your API key here."
28+
"\n",
29+
"os.environ[\"LS_API_KEY\"] = \"MY-API-KEY\" # replace your API key here."
2930
]
3031
},
3132
{
@@ -39,7 +40,10 @@
3940
"\n",
4041
"from here_location_services import LS\n",
4142
"from here_map_widget import Map, Marker, GeoJSON, Group\n",
42-
"from here_location_services.config.isoline_routing_config import RANGE_TYPE, ISOLINE_ROUTING_TRANSPORT_MODE\n",
43+
"from here_location_services.config.isoline_routing_config import (\n",
44+
" RANGE_TYPE,\n",
45+
" ISOLINE_ROUTING_TRANSPORT_MODE,\n",
46+
")\n",
4347
"\n",
4448
"\n",
4549
"LS_API_KEY = os.environ.get(\"LS_API_KEY\")\n",
@@ -126,7 +130,9 @@
126130
"metadata": {},
127131
"outputs": [],
128132
"source": [
129-
"search = ls.discover(center=[centroid.y, centroid.x], limit=10, query='restaurant', country_codes=[\"IND\"])\n",
133+
"search = ls.discover(\n",
134+
" center=[centroid.y, centroid.x], limit=10, query=\"restaurant\", country_codes=[\"IND\"]\n",
135+
")\n",
130136
"search.items"
131137
]
132138
},
@@ -138,7 +144,7 @@
138144
"source": [
139145
"group = Group(volatility=True)\n",
140146
"\n",
141-
"restaurants =[]\n",
147+
"restaurants = []\n",
142148
"for restaurant in search.items:\n",
143149
" restaurants.append(\n",
144150
" Marker(\n",

docs/notebooks/location_services.ipynb

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"execution_count": null,
1616
"source": [
1717
"import os\n",
18-
"os.environ[\"LS_API_KEY\"] = \"MY-API-KEY\" # replace your API key here."
18+
"\n",
19+
"os.environ[\"LS_API_KEY\"] = \"MY-API-KEY\" # replace your API key here."
1920
],
2021
"outputs": [],
2122
"metadata": {}
@@ -108,14 +109,19 @@
108109
"source": [
109110
"# Isoline routing example\n",
110111
"\n",
111-
"from here_location_services.config.isoline_routing_config import RANGE_TYPE, ISOLINE_ROUTING_TRANSPORT_MODE\n",
112+
"from here_location_services.config.isoline_routing_config import (\n",
113+
" RANGE_TYPE,\n",
114+
" ISOLINE_ROUTING_TRANSPORT_MODE,\n",
115+
")\n",
112116
"from datetime import datetime\n",
113117
"\n",
114-
"iso_response = ls.calculate_isoline(origin=[52.53086, 13.38469],\n",
118+
"iso_response = ls.calculate_isoline(\n",
119+
" origin=[52.53086, 13.38469],\n",
115120
" range=\"1800\",\n",
116121
" departure_time=datetime.now(),\n",
117122
" range_type=RANGE_TYPE.time,\n",
118-
" transport_mode=ISOLINE_ROUTING_TRANSPORT_MODE.car,)\n",
123+
" transport_mode=ISOLINE_ROUTING_TRANSPORT_MODE.car,\n",
124+
")\n",
119125
"\n",
120126
"data = iso_response.to_geojson()\n",
121127
"geo_layer = GeoJSON(data=data)\n",
@@ -125,7 +131,7 @@
125131
"m = Map(api_key=LS_API_KEY, center=[52.53086, 13.38469], zoom=9)\n",
126132
"m.add_layer(geo_layer)\n",
127133
"m.add_object(iso_marker)\n",
128-
"m\n"
134+
"m"
129135
],
130136
"outputs": [],
131137
"metadata": {}
@@ -168,8 +174,11 @@
168174
"source": [
169175
"from here_location_services.config.search_config import PLACES_CATEGORIES\n",
170176
"\n",
171-
"browse_response = ls.browse(center=[52.53086, 13.38469], bounding_box=[13.08836,52.33812,13.761,52.6755],\n",
172-
" categories=[PLACES_CATEGORIES.restaurant])\n",
177+
"browse_response = ls.browse(\n",
178+
" center=[52.53086, 13.38469],\n",
179+
" bounding_box=[13.08836, 52.33812, 13.761, 52.6755],\n",
180+
" categories=[PLACES_CATEGORIES.restaurant],\n",
181+
")\n",
173182
"\n",
174183
"data = browse_response.to_geojson()\n",
175184
"geo_layer = GeoJSON(data=data)\n",
@@ -194,7 +203,7 @@
194203
"cell_type": "code",
195204
"execution_count": null,
196205
"source": [
197-
"lookup = ls.lookup(location_id=browse_response.items[0]['id'])\n",
206+
"lookup = ls.lookup(location_id=browse_response.items[0][\"id\"])\n",
198207
"\n",
199208
"lookup.response"
200209
],

docs/notebooks/matrix_routing.ipynb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
"metadata": {},
176176
"outputs": [],
177177
"source": [
178-
"distance_matrix= result.to_distnaces_matrix()\n",
178+
"distance_matrix = result.to_distnaces_matrix()\n",
179179
"distance_matrix"
180180
]
181181
},
@@ -185,7 +185,7 @@
185185
"metadata": {},
186186
"outputs": [],
187187
"source": [
188-
"travel_times_matrix= result.to_travel_times_matrix()\n",
188+
"travel_times_matrix = result.to_travel_times_matrix()\n",
189189
"travel_times_matrix"
190190
]
191191
},
@@ -234,7 +234,7 @@
234234
"from here_map_widget import Map, Bbox, Rectangle, Marker\n",
235235
"import os\n",
236236
"\n",
237-
"m = Map(api_key=os.environ['LS_API_KEY'], center=[52.5034, 13.4079], zoom=11.4)\n",
237+
"m = Map(api_key=os.environ[\"LS_API_KEY\"], center=[52.5034, 13.4079], zoom=11.4)\n",
238238
"\n",
239239
"style = {\"strokeColor\": \"#829\", \"lineWidth\": 4}\n",
240240
"\n",
@@ -262,7 +262,7 @@
262262
" AutoCircleRegion,\n",
263263
" MATRIX_ATTRIBUTES,\n",
264264
" PROFILE,\n",
265-
" WorldRegion\n",
265+
" WorldRegion,\n",
266266
")\n",
267267
"\n",
268268
"LS_API_KEY = os.environ.get(\"LS_API_KEY\") # Get API KEY from environment.\n",
@@ -294,7 +294,7 @@
294294
" origins=origins,\n",
295295
" region_definition=region_definition,\n",
296296
" matrix_attributes=matrix_attributes,\n",
297-
" async_req=True\n",
297+
" async_req=True,\n",
298298
")"
299299
]
300300
},
@@ -313,7 +313,7 @@
313313
"metadata": {},
314314
"outputs": [],
315315
"source": [
316-
"distance_matrix= result.to_distnaces_matrix()\n",
316+
"distance_matrix = result.to_distnaces_matrix()\n",
317317
"distance_matrix"
318318
]
319319
},
@@ -338,7 +338,7 @@
338338
" origins=origins,\n",
339339
" region_definition=region_definition,\n",
340340
" matrix_attributes=matrix_attributes,\n",
341-
" async_req=True\n",
341+
" async_req=True,\n",
342342
")"
343343
]
344344
},
@@ -373,7 +373,7 @@
373373
"\n",
374374
"from here_map_widget import Circle, Point\n",
375375
"\n",
376-
"m = Map(api_key=os.environ[\"LS_API_KEY\"], center=[center[\"lat\"],center[\"lng\"]] , zoom=10.4)\n",
376+
"m = Map(api_key=os.environ[\"LS_API_KEY\"], center=[center[\"lat\"], center[\"lng\"]], zoom=10.4)\n",
377377
"\n",
378378
"style = {\"strokeColor\": \"#829\", \"lineWidth\": 4}\n",
379379
"\n",
@@ -487,7 +487,7 @@
487487
" origins=origins,\n",
488488
" region_definition=region_definition,\n",
489489
" matrix_attributes=matrix_attributes,\n",
490-
" async_req=True\n",
490+
" async_req=True,\n",
491491
")"
492492
]
493493
},

docs/notebooks/routing.ipynb

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,13 @@
176176
"source": [
177177
"from here_location_services.config.routing_config import PlaceOptions\n",
178178
"\n",
179-
"dpo = PlaceOptions(sideof_street_hint=[52.500541,13.363060])\n",
179+
"dpo = PlaceOptions(sideof_street_hint=[52.500541, 13.363060])\n",
180180
"\n",
181181
"result = ls.car_route(\n",
182-
" origin=[52.511985,13.240523],\n",
183-
" destination=[52.500541,13.363060],\n",
184-
" return_results=[\n",
185-
" ROUTING_RETURN.polyline,\n",
186-
" ROUTING_RETURN.elevation,\n",
187-
" ROUTING_RETURN.summary\n",
188-
" ],\n",
189-
" destination_place_options=dpo\n",
182+
" origin=[52.511985, 13.240523],\n",
183+
" destination=[52.500541, 13.363060],\n",
184+
" return_results=[ROUTING_RETURN.polyline, ROUTING_RETURN.elevation, ROUTING_RETURN.summary],\n",
185+
" destination_place_options=dpo,\n",
190186
")"
191187
]
192188
},
@@ -228,13 +224,9 @@
228224
"outputs": [],
229225
"source": [
230226
"result2 = ls.car_route(\n",
231-
" origin=[52.511985,13.240523],\n",
232-
" destination=[52.500541,13.363060],\n",
233-
" return_results=[\n",
234-
" ROUTING_RETURN.polyline,\n",
235-
" ROUTING_RETURN.elevation,\n",
236-
" ROUTING_RETURN.summary\n",
237-
" ],\n",
227+
" origin=[52.511985, 13.240523],\n",
228+
" destination=[52.500541, 13.363060],\n",
229+
" return_results=[ROUTING_RETURN.polyline, ROUTING_RETURN.elevation, ROUTING_RETURN.summary],\n",
238230
")"
239231
]
240232
},

requirements_dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Development, use pip install -e .[dev]
22
coverage
3-
black
3+
black[jupyter]>=21.8b0
44
mypy
55
proxy.py
66
pytest

tests/test_exceptions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import pytest
88

99
from here_location_services import LS
10+
from here_location_services.apis import Api as BaseApi
1011
from here_location_services.exceptions import (
1112
ApiError,
1213
AuthenticationException,
@@ -48,3 +49,10 @@ def test_raise_response_exception():
4849
mock_response = get_mock_response(500, reason, text)
4950
with pytest.raises(Exception):
5051
Api.raise_response_exception(mock_response)
52+
53+
54+
def test_auth_exception():
55+
"""Test if both api key and auth token in not provided."""
56+
api = BaseApi(api_key=None, auth=None)
57+
with pytest.raises(Exception):
58+
api._get_url_string()

0 commit comments

Comments
 (0)