def test_human_readable_timedelta_force_print_0_seconds(td, expected): """ Test the `human_readable_timedelta` function. Arguments: td: A timedelta. expected: The expected result. """ assert human_readable_timedelta(td) == expected
def eta_string(self, precision: int = 0) -> str: """ Return the Estimated Time of Arrival as a string. Arguments: precision: The precision to use, see [aria2p.utils.human_readable_timedelta]. Returns: The Estimated Time of Arrival as a string. """ eta = self.eta if eta == timedelta.max: return "-" return human_readable_timedelta(eta, precision=precision)
def test_human_readable_timedelta_only_minutes(): assert human_readable_timedelta(timedelta(seconds=60 * 3)) == "3m"
def test_human_readable_timedelta_only_hours(): assert human_readable_timedelta(timedelta(seconds=3600 * 3)) == "3h"
def test_human_readable_timedelta_only_days(): assert human_readable_timedelta(timedelta(days=3)) == "3d"
def test_human_readable_timedelta_0_hours_0_minutes(): assert human_readable_timedelta(timedelta(days=3, seconds=3)) == "3d3s"
def test_human_readable_timedelta_one_day_plus_more_than_1day_worth_seconds(): assert human_readable_timedelta(timedelta(days=1, seconds=3600 * 24 + 2)) == "2d2s"
def test_human_readable_timedelta_more_than_1day_worth_seconds(): assert human_readable_timedelta(timedelta(seconds=3600 * 24 + 2)) == "1d2s"
def test_human_readable_timedelta_more_than_3600_seconds(): assert human_readable_timedelta(timedelta(seconds=3601)) == "1h1s"
def test_human_readable_timedelta_more_than_60_seconds(): assert human_readable_timedelta(timedelta(seconds=75)) == "1m15s"
def test_human_readable_timedelta_one_second(): assert human_readable_timedelta(timedelta(seconds=1)) == "1s"
def test_human_readable_timedelta_force_print_0_seconds(): assert human_readable_timedelta(timedelta(seconds=0)) == "0s"