mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-02-02 00:05:27 +00:00
make duration formatting more forgiving
This commit is contained in:
parent
3af4647804
commit
80963966b2
@ -48,12 +48,14 @@ def parse_size(s: typing.Optional[str]) -> typing.Optional[int]:
|
|||||||
raise ValueError("Invalid size specification.")
|
raise ValueError("Invalid size specification.")
|
||||||
|
|
||||||
|
|
||||||
def pretty_duration(secs):
|
def pretty_duration(secs: typing.Optional[float]) -> str:
|
||||||
formatters = [
|
formatters = [
|
||||||
(100, "{:.0f}s"),
|
(100, "{:.0f}s"),
|
||||||
(10, "{:2.1f}s"),
|
(10, "{:2.1f}s"),
|
||||||
(1, "{:1.2f}s"),
|
(1, "{:1.2f}s"),
|
||||||
]
|
]
|
||||||
|
if secs is None:
|
||||||
|
return ""
|
||||||
|
|
||||||
for limit, formatter in formatters:
|
for limit, formatter in formatters:
|
||||||
if secs >= limit:
|
if secs >= limit:
|
||||||
|
@ -47,6 +47,7 @@ def test_pretty_duration():
|
|||||||
assert human.pretty_duration(10000) == "10000s"
|
assert human.pretty_duration(10000) == "10000s"
|
||||||
assert human.pretty_duration(1.123) == "1.12s"
|
assert human.pretty_duration(1.123) == "1.12s"
|
||||||
assert human.pretty_duration(0.123) == "123ms"
|
assert human.pretty_duration(0.123) == "123ms"
|
||||||
|
assert human.pretty_duration(None) == ""
|
||||||
|
|
||||||
|
|
||||||
def test_format_address():
|
def test_format_address():
|
||||||
|
Loading…
Reference in New Issue
Block a user