def test_typical(self): qty_names = ['sec', 'mins', 'hours', 'days'] qty_factors = [1, 60, 3600, 3600 * 24] ret_val = io_utils.format_quantity(315, qty_names, qty_factors) self.assertEqual(ret_val, '5.25 mins') ret_val = io_utils.format_quantity(6300, qty_names, qty_factors) self.assertEqual(ret_val, '1.75 hours')
def test_not_iterable(self): with self.assertRaises(TypeError): _ = io_utils.format_quantity(315, 14, [1, 60, 3600]) with self.assertRaises(TypeError): _ = io_utils.format_quantity(315, ['sec', 'mins', 'hours'], slice(None))
def test_unequal_lengths(self): with self.assertRaises(ValueError): _ = io_utils.format_quantity(315, ['sec', 'mins', 'hours'], [1, 60, 3600, 3600 * 24]) with self.assertRaises(ValueError): _ = io_utils.format_quantity(315, ['sec', 'mins', 'hours'], [1, 60])
def test_illegal(self): with self.assertRaises(ValueError): _ = io_utils.format_quantity(315, ['sec', 'mins', 'hours'], [1, 60, 3600, 3600 * 24]) with self.assertRaises(ValueError): _ = io_utils.format_quantity(315, ['sec', 'mins', 'hours'], [1, 60]) with self.assertRaises(TypeError): _ = io_utils.format_quantity(315, ['sec', 14, 'hours'], [1, 60, 3600 * 24]) with self.assertRaises(TypeError): _ = io_utils.format_quantity('hello', ['sec', 'mins', 'hours'], [1, 60, 3600])
def test_incorrect_number_to_format(self): with self.assertRaises(TypeError): _ = io_utils.format_quantity('hello', ['sec', 'mins', 'hours'], [1, 60, 3600])
def test_incorrect_element_types(self): with self.assertRaises(TypeError): _ = io_utils.format_quantity(315, ['sec', 14, 'hours'], [1, 60, 3600 * 24])