diff --git a/examples/compare_providers.ipynb b/examples/compare_providers.ipynb index a7b05b2..89e042b 100644 --- a/examples/compare_providers.ipynb +++ b/examples/compare_providers.ipynb @@ -1403,7 +1403,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.7" + "version": "3.7.3" } }, "nbformat": 4, diff --git a/routingpy/routers/heremaps.py b/routingpy/routers/heremaps.py index 9dd906b..c7b2e64 100644 --- a/routingpy/routers/heremaps.py +++ b/routingpy/routers/heremaps.py @@ -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 diff --git a/tests/test_heremaps.py b/tests/test_heremaps.py index a3d0a19..ca00ea4 100644 --- a/tests/test_heremaps.py +++ b/tests/test_heremaps.py @@ -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))