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

Commit

Permalink
black formatted notebooks
Browse files Browse the repository at this point in the history
Signed-off-by: Kharude, Sachin <sachin.kharude@here.com>
  • Loading branch information
Kharude, Sachin committed Sep 2, 2021
1 parent 6f6c11e commit e178ee9
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 43 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
all: black build install typing lint test docs

black:
black -l 99 here_location_services tests
black -l 99 here_location_services tests docs/notebooks
isort --atomic .

build:
Expand Down Expand Up @@ -42,7 +42,7 @@ typing:
lint:
isort --check --diff here_location_services tests
flake8 -v --statistics --count .
black -l 99 --diff --check here_location_services tests
black -l 99 --diff --check here_location_services tests docs/notebooks

test:
pytest -v -s --cov=here_location_services tests
Expand Down
4 changes: 2 additions & 2 deletions docs/notebooks/authentication.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@
"metadata": {},
"outputs": [],
"source": [
"# credentials will be picked up from credentials.properties file placed at default location. \n",
"# credentials will be picked up from credentials.properties file placed at default location.\n",
"from here_location_services import LS\n",
"\n",
"# platform credentials will be picked from the default credentials file's location mentioned above\n",
"# and api_key should not be set in env variable LS_API_KEY in order to use oauth credentials.\n",
"ls = LS() "
"ls = LS()"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/notebooks/autosuggest.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"metadata": {},
"outputs": [],
"source": [
"os.environ[\"LS_API_KEY\"] = \"MY-API-KEY\" # replace your API key here."
"os.environ[\"LS_API_KEY\"] = \"MY-API-KEY\" # replace your API key here."
]
},
{
Expand Down
14 changes: 10 additions & 4 deletions docs/notebooks/isoline_routing_restaurant_search.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"outputs": [],
"source": [
"import os\n",
"os.environ[\"LS_API_KEY\"] = \"MY-API-KEY\" # replace your API key here."
"\n",
"os.environ[\"LS_API_KEY\"] = \"MY-API-KEY\" # replace your API key here."
]
},
{
Expand All @@ -39,7 +40,10 @@
"\n",
"from here_location_services import LS\n",
"from here_map_widget import Map, Marker, GeoJSON, Group\n",
"from here_location_services.config.isoline_routing_config import RANGE_TYPE, ISOLINE_ROUTING_TRANSPORT_MODE\n",
"from here_location_services.config.isoline_routing_config import (\n",
" RANGE_TYPE,\n",
" ISOLINE_ROUTING_TRANSPORT_MODE,\n",
")\n",
"\n",
"\n",
"LS_API_KEY = os.environ.get(\"LS_API_KEY\")\n",
Expand Down Expand Up @@ -126,7 +130,9 @@
"metadata": {},
"outputs": [],
"source": [
"search = ls.discover(center=[centroid.y, centroid.x], limit=10, query='restaurant', country_codes=[\"IND\"])\n",
"search = ls.discover(\n",
" center=[centroid.y, centroid.x], limit=10, query=\"restaurant\", country_codes=[\"IND\"]\n",
")\n",
"search.items"
]
},
Expand All @@ -138,7 +144,7 @@
"source": [
"group = Group(volatility=True)\n",
"\n",
"restaurants =[]\n",
"restaurants = []\n",
"for restaurant in search.items:\n",
" restaurants.append(\n",
" Marker(\n",
Expand Down
25 changes: 17 additions & 8 deletions docs/notebooks/location_services.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"execution_count": null,
"source": [
"import os\n",
"os.environ[\"LS_API_KEY\"] = \"MY-API-KEY\" # replace your API key here."
"\n",
"os.environ[\"LS_API_KEY\"] = \"MY-API-KEY\" # replace your API key here."
],
"outputs": [],
"metadata": {}
Expand Down Expand Up @@ -108,14 +109,19 @@
"source": [
"# Isoline routing example\n",
"\n",
"from here_location_services.config.isoline_routing_config import RANGE_TYPE, ISOLINE_ROUTING_TRANSPORT_MODE\n",
"from here_location_services.config.isoline_routing_config import (\n",
" RANGE_TYPE,\n",
" ISOLINE_ROUTING_TRANSPORT_MODE,\n",
")\n",
"from datetime import datetime\n",
"\n",
"iso_response = ls.calculate_isoline(origin=[52.53086, 13.38469],\n",
"iso_response = ls.calculate_isoline(\n",
" origin=[52.53086, 13.38469],\n",
" range=\"1800\",\n",
" departure_time=datetime.now(),\n",
" range_type=RANGE_TYPE.time,\n",
" transport_mode=ISOLINE_ROUTING_TRANSPORT_MODE.car,)\n",
" transport_mode=ISOLINE_ROUTING_TRANSPORT_MODE.car,\n",
")\n",
"\n",
"data = iso_response.to_geojson()\n",
"geo_layer = GeoJSON(data=data)\n",
Expand All @@ -125,7 +131,7 @@
"m = Map(api_key=LS_API_KEY, center=[52.53086, 13.38469], zoom=9)\n",
"m.add_layer(geo_layer)\n",
"m.add_object(iso_marker)\n",
"m\n"
"m"
],
"outputs": [],
"metadata": {}
Expand Down Expand Up @@ -168,8 +174,11 @@
"source": [
"from here_location_services.config.search_config import PLACES_CATEGORIES\n",
"\n",
"browse_response = ls.browse(center=[52.53086, 13.38469], bounding_box=[13.08836,52.33812,13.761,52.6755],\n",
" categories=[PLACES_CATEGORIES.restaurant])\n",
"browse_response = ls.browse(\n",
" center=[52.53086, 13.38469],\n",
" bounding_box=[13.08836, 52.33812, 13.761, 52.6755],\n",
" categories=[PLACES_CATEGORIES.restaurant],\n",
")\n",
"\n",
"data = browse_response.to_geojson()\n",
"geo_layer = GeoJSON(data=data)\n",
Expand All @@ -194,7 +203,7 @@
"cell_type": "code",
"execution_count": null,
"source": [
"lookup = ls.lookup(location_id=browse_response.items[0]['id'])\n",
"lookup = ls.lookup(location_id=browse_response.items[0][\"id\"])\n",
"\n",
"lookup.response"
],
Expand Down
18 changes: 9 additions & 9 deletions docs/notebooks/matrix_routing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
"metadata": {},
"outputs": [],
"source": [
"distance_matrix= result.to_distnaces_matrix()\n",
"distance_matrix = result.to_distnaces_matrix()\n",
"distance_matrix"
]
},
Expand All @@ -185,7 +185,7 @@
"metadata": {},
"outputs": [],
"source": [
"travel_times_matrix= result.to_travel_times_matrix()\n",
"travel_times_matrix = result.to_travel_times_matrix()\n",
"travel_times_matrix"
]
},
Expand Down Expand Up @@ -234,7 +234,7 @@
"from here_map_widget import Map, Bbox, Rectangle, Marker\n",
"import os\n",
"\n",
"m = Map(api_key=os.environ['LS_API_KEY'], center=[52.5034, 13.4079], zoom=11.4)\n",
"m = Map(api_key=os.environ[\"LS_API_KEY\"], center=[52.5034, 13.4079], zoom=11.4)\n",
"\n",
"style = {\"strokeColor\": \"#829\", \"lineWidth\": 4}\n",
"\n",
Expand Down Expand Up @@ -262,7 +262,7 @@
" AutoCircleRegion,\n",
" MATRIX_ATTRIBUTES,\n",
" PROFILE,\n",
" WorldRegion\n",
" WorldRegion,\n",
")\n",
"\n",
"LS_API_KEY = os.environ.get(\"LS_API_KEY\") # Get API KEY from environment.\n",
Expand Down Expand Up @@ -294,7 +294,7 @@
" origins=origins,\n",
" region_definition=region_definition,\n",
" matrix_attributes=matrix_attributes,\n",
" async_req=True\n",
" async_req=True,\n",
")"
]
},
Expand All @@ -313,7 +313,7 @@
"metadata": {},
"outputs": [],
"source": [
"distance_matrix= result.to_distnaces_matrix()\n",
"distance_matrix = result.to_distnaces_matrix()\n",
"distance_matrix"
]
},
Expand All @@ -338,7 +338,7 @@
" origins=origins,\n",
" region_definition=region_definition,\n",
" matrix_attributes=matrix_attributes,\n",
" async_req=True\n",
" async_req=True,\n",
")"
]
},
Expand Down Expand Up @@ -373,7 +373,7 @@
"\n",
"from here_map_widget import Circle, Point\n",
"\n",
"m = Map(api_key=os.environ[\"LS_API_KEY\"], center=[center[\"lat\"],center[\"lng\"]] , zoom=10.4)\n",
"m = Map(api_key=os.environ[\"LS_API_KEY\"], center=[center[\"lat\"], center[\"lng\"]], zoom=10.4)\n",
"\n",
"style = {\"strokeColor\": \"#829\", \"lineWidth\": 4}\n",
"\n",
Expand Down Expand Up @@ -487,7 +487,7 @@
" origins=origins,\n",
" region_definition=region_definition,\n",
" matrix_attributes=matrix_attributes,\n",
" async_req=True\n",
" async_req=True,\n",
")"
]
},
Expand Down
24 changes: 8 additions & 16 deletions docs/notebooks/routing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,13 @@
"source": [
"from here_location_services.config.routing_config import PlaceOptions\n",
"\n",
"dpo = PlaceOptions(sideof_street_hint=[52.500541,13.363060])\n",
"dpo = PlaceOptions(sideof_street_hint=[52.500541, 13.363060])\n",
"\n",
"result = ls.car_route(\n",
" origin=[52.511985,13.240523],\n",
" destination=[52.500541,13.363060],\n",
" return_results=[\n",
" ROUTING_RETURN.polyline,\n",
" ROUTING_RETURN.elevation,\n",
" ROUTING_RETURN.summary\n",
" ],\n",
" destination_place_options=dpo\n",
" origin=[52.511985, 13.240523],\n",
" destination=[52.500541, 13.363060],\n",
" return_results=[ROUTING_RETURN.polyline, ROUTING_RETURN.elevation, ROUTING_RETURN.summary],\n",
" destination_place_options=dpo,\n",
")"
]
},
Expand Down Expand Up @@ -228,13 +224,9 @@
"outputs": [],
"source": [
"result2 = ls.car_route(\n",
" origin=[52.511985,13.240523],\n",
" destination=[52.500541,13.363060],\n",
" return_results=[\n",
" ROUTING_RETURN.polyline,\n",
" ROUTING_RETURN.elevation,\n",
" ROUTING_RETURN.summary\n",
" ],\n",
" origin=[52.511985, 13.240523],\n",
" destination=[52.500541, 13.363060],\n",
" return_results=[ROUTING_RETURN.polyline, ROUTING_RETURN.elevation, ROUTING_RETURN.summary],\n",
")"
]
},
Expand Down
2 changes: 1 addition & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Development, use pip install -e .[dev]
coverage
black
black[jupyter]>=21.8b0
mypy
proxy.py
pytest
Expand Down
8 changes: 8 additions & 0 deletions tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest

from here_location_services import LS
from here_location_services.apis import Api as BaseApi
from here_location_services.exceptions import (
ApiError,
AuthenticationException,
Expand Down Expand Up @@ -48,3 +49,10 @@ def test_raise_response_exception():
mock_response = get_mock_response(500, reason, text)
with pytest.raises(Exception):
Api.raise_response_exception(mock_response)


def test_auth_exception():
"""Test if both api key and auth token in not provided."""
api = BaseApi(api_key=None, auth=None)
with pytest.raises(Exception):
api._get_url_string()

0 comments on commit e178ee9

Please sign in to comment.