• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mthh / routingpy / 19018276231

02 Nov 2025 09:17PM UTC coverage: 88.943%. First build
19018276231

Pull #150

github

web-flow
Merge e90838d9f into eb20b436a
Pull Request #150: feat: add geotiff support valhalla isochrones

9 of 9 new or added lines in 1 file covered. (100.0%)

1649 of 1854 relevant lines covered (88.94%)

0.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.33
/routingpy/convert.py
1
# -*- coding: utf-8 -*-
2
# Copyright (C) 2021 GIS OPS UG
3
#
4
#
5
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
6
# use this file except in compliance with the License. You may obtain a copy of
7
# the License at
8
#
9
#     http://www.apache.org/licenses/LICENSE-2.0
10
#
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
# License for the specific language governing permissions and limitations under
15
# the License.
16
#
17
"""Converts Python types to string representations suitable for GET queries.
18
"""
19
import datetime
1✔
20

21

22
def delimit_list(arg, delimiter=","):
1✔
23
    """Convert list to delimiter-separated string"""
24
    if not is_list(arg):
1✔
25
        raise TypeError("Expected a list or tuple, " "but got {}".format(type(arg).__name__))
1✔
26
    return delimiter.join(map(str, arg))
1✔
27

28

29
def convert_bool(boolean):
1✔
30
    """Convert to stringified boolean"""
31

32
    return str(boolean).lower()
1✔
33

34

35
def format_float(arg):
1✔
36
    """Formats a float value to be as short as possible.
37

38
    Trims extraneous trailing zeros and period to give API
39
    args the best possible chance of fitting within 2000 char
40
    URL length restrictions.
41

42
    For example:
43

44
    format_float(40) -> "40"
45
    format_float(40.0) -> "40"
46
    format_float(40.1) -> "40.1"
47
    format_float(40.001) -> "40.001"
48
    format_float(40.0010) -> "40.001"
49

50
    :param arg: The lat or lng float.
51
    :type arg: float
52

53
    :rtype: string
54
    """
55
    return "{}".format(round(float(arg), 6)).rstrip("0").rstrip(".")
1✔
56

57

58
def is_list(arg):
1✔
59
    """Checks if arg is list-like."""
60
    if isinstance(arg, dict):
1✔
61
        return False
1✔
62
    if isinstance(arg, str):  # Python 3-only, as str has __iter__
1✔
63
        return False
1✔
64
    return (
1✔
65
        not _has_method(arg, "strip") and _has_method(arg, "__getitem__") or _has_method(arg, "__iter__")
66
    )
67

68

69
def _has_method(arg, method):
1✔
70
    """Returns true if the given object has a method with the given name.
71

72
    :param arg: the object
73

74
    :param method: the method name
75
    :type method: string
76

77
    :rtype: bool
78
    """
79
    return hasattr(arg, method) and callable(getattr(arg, method))
1✔
80

81

82
def seconds_to_iso8601(seconds):
1✔
83
    """Convert the given number of seconds to ISO 8601 duration format.
84

85
    Example:
86
        >>> seconds_to_iso8601(3665)
87
        'PT1H1M5S'
88

89
    :param seconds: The number of seconds to convert.
90
    :type seconds: int
91

92
    :returns: The duration in ISO 8601 format.
93
    :rtype: string
94
    """
95
    duration = datetime.timedelta(seconds=seconds)
1✔
96
    hours = duration.seconds // 3600
1✔
97
    minutes = (duration.seconds // 60) % 60
1✔
98
    seconds = duration.seconds % 60
1✔
99

100
    iso8601_duration = "PT"
1✔
101
    if hours:
1✔
102
        iso8601_duration += f"{hours}H"
×
103

104
    if minutes:
1✔
105
        iso8601_duration += f"{minutes}M"
1✔
106

107
    if seconds or not (hours or minutes):
1✔
108
        iso8601_duration += f"{seconds}S"
×
109

110
    return iso8601_duration
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc