def testFormatTimedelta(self): table = { datetime.timedelta(0, 0) : '0 00:00:00', datetime.timedelta(0, 10) : '0 00:00:10', datetime.timedelta(0, 60) : '0 00:01:00', datetime.timedelta(0, 61) : '0 00:01:01', datetime.timedelta(0, 3661) : '0 01:01:01', datetime.timedelta(1, 3661) : '1 01:01:01', datetime.timedelta(13, 65660): '13 18:14:20', } for delta, expected in table.items(): self.assertEqual(tu.format_timedelta(delta), expected)
def format_eta(self) -> str: """ Returns the attribute *eta* formatted as a string. * If eta is -1 the result is 'not available' * If eta is -2 the result is 'unknown' * Otherwise eta is formatted as <days> <hours>:<minutes>:<seconds>. """ eta = self._fields["eta"].value if eta == -1: return "not available" if eta == -2: return "unknown" return format_timedelta(self.eta)
def test_format_timedelta(delta, expected): assert utils.format_timedelta(delta), expected