Example #1
0
def visibility(vis: Number, unit: str = "m") -> str:
    """
    Format visibility details into a spoken word string
    """
    if not vis:
        return "Visibility unknown"
    if vis.value is None or "/" in vis.repr:
        ret_vis = vis.spoken
    else:
        ret_vis = translate.visibility(vis, unit=unit)
        if unit == "m":
            unit = "km"
        ret_vis = ret_vis[:ret_vis.find(" (")].lower().replace(unit,
                                                               "").strip()
        ret_vis = _core.spoken_number(_core.remove_leading_zeros(ret_vis))
    ret = "Visibility " + ret_vis
    if unit in SPOKEN_UNITS:
        if "/" in vis.repr and "half" not in ret:
            ret += " of a"
        ret += " " + SPOKEN_UNITS[unit]
        if not (("one half" in ret and " and " not in ret) or "of a" in ret):
            ret += "s"
    else:
        ret += unit
    return ret
Example #2
0
 def test_remove_leading_zeros(self):
     """
     Tests removing leading zeros from a number
     """
     for num, stripped in (
         ("", ""),
         ("5", "5"),
         ("010", "10"),
         ("M10", "M10"),
         ("M002", "M2"),
         ("-09.9", "-9.9"),
         ("000", "0"),
         ("M00", "0"),
     ):
         self.assertEqual(_core.remove_leading_zeros(num), stripped)
Example #3
0
 def test_remove_leading_zeros(self):
     """
     Tests removing leading zeros from a number
     """
     for num, stripped in (
         ('', ''),
         ('5', '5'),
         ('010', '10'),
         ('M10', 'M10'),
         ('M002', 'M2'),
         ('-09.9', '-9.9'),
         ('000', '0'),
         ('M00', '0'),
     ):
         self.assertEqual(_core.remove_leading_zeros(num), stripped)