Skip to content

Commit

Permalink
makes heremaps matrix calls sources and destinations optional, closes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
TimMcCauley committed Apr 29, 2019
1 parent 3d20cd6 commit 588519e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 42 deletions.
2 changes: 1 addition & 1 deletion examples/compare_providers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1403,7 +1403,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
"version": "3.7.3"
}
},
"nbformat": 4,
Expand Down
80 changes: 51 additions & 29 deletions routingpy/routers/heremaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -1239,44 +1239,66 @@ def matrix(self,
params["app_code"] = self.app_code
params["app_id"] = self.app_id

try:
for i, start_idx in enumerate(sources):
if sources is None and destinations is None:

if isinstance(locations[start_idx], self.WayPoint):
params["start" +
str(i)] = locations[start_idx].make_waypoint()
elif isinstance(locations[start_idx], (list, tuple)):
for i, location in enumerate(locations):

if isinstance(location, self.WayPoint):
params["start" + str(i)] = location.make_waypoint()
params["destination" + str(i)] = location.make_waypoint()
elif isinstance(location, (list, tuple)):
params["start" + str(i)] = 'geo!' + convert._delimit_list([
convert._format_float(f)
for f in list(reversed(locations[start_idx]))
for f in list(reversed(location))
], ',')

except IndexError:
raise IndexError(
"Parameter sources out of locations range at index {}.".format(
start_idx))
except TypeError:
raise TypeError("Please add sources indices.")

try:
for i, dest_idx in enumerate(destinations):

if isinstance(locations[dest_idx], self.WayPoint):
params["destination" +
str(i)] = locations[dest_idx].make_waypoint()
elif isinstance(locations[dest_idx], (list, tuple)):
params["destination" +
str(i)] = 'geo!' + convert._delimit_list([
convert._format_float(f)
for f in list(reversed(locations[dest_idx]))
for f in list(reversed(location))
], ',')

except IndexError:
raise IndexError(
"Parameter destinations out of locations range at index {}.".
format(dest_idx))
except TypeError:
raise TypeError("Please add destinations indices.")
else:
try:
for i, start_idx in enumerate(sources):

if isinstance(locations[start_idx], self.WayPoint):
params["start" +
str(i)] = locations[start_idx].make_waypoint()
elif isinstance(locations[start_idx], (list, tuple)):
params["start" + str(
i)] = 'geo!' + convert._delimit_list([
convert._format_float(f)
for f in list(reversed(locations[start_idx]))
], ',')

except IndexError:
raise IndexError(
"Parameter sources out of locations range at index {}.".
format(start_idx))
except TypeError:
# Raised when sources == None
pass

try:
for i, dest_idx in enumerate(destinations):

if isinstance(locations[dest_idx], self.WayPoint):
params["destination" +
str(i)] = locations[dest_idx].make_waypoint()
elif isinstance(locations[dest_idx], (list, tuple)):
params["destination" + str(
i)] = 'geo!' + convert._delimit_list([
convert._format_float(f)
for f in list(reversed(locations[dest_idx]))
], ',')

except IndexError:
raise IndexError(
"Parameter destinations out of locations range at index {}."
.format(dest_idx))
except TypeError:
# Raised when destinations == None
pass

if isinstance(profile, str):
params["mode"] = profile
Expand Down
12 changes: 0 additions & 12 deletions tests/test_heremaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,8 @@ def test_index_sources_matrix(self):

self.assertRaises(IndexError, lambda: self.client.matrix(**query))

def test_none_sources_matrix(self):
query = deepcopy(ENDPOINTS_QUERIES[self.name]['matrix'])
query['sources'] = None

self.assertRaises(TypeError, lambda: self.client.matrix(**query))

def test_index_destinations_matrix(self):
query = deepcopy(ENDPOINTS_QUERIES[self.name]['matrix'])
query['destinations'] = [100]

self.assertRaises(IndexError, lambda: self.client.matrix(**query))

def test_none_destinations_matrix(self):
query = deepcopy(ENDPOINTS_QUERIES[self.name]['matrix'])
query['destinations'] = None

self.assertRaises(TypeError, lambda: self.client.matrix(**query))

0 comments on commit 588519e

Please sign in to comment.