Exemplo n.º 1
0
 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')
Exemplo n.º 2
0
    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))
Exemplo n.º 3
0
 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])
Exemplo n.º 4
0
 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])
Exemplo n.º 5
0
 def test_incorrect_number_to_format(self):
     with self.assertRaises(TypeError):
         _ = io_utils.format_quantity('hello', ['sec', 'mins', 'hours'],
                                      [1, 60, 3600])
Exemplo n.º 6
0
 def test_incorrect_element_types(self):
     with self.assertRaises(TypeError):
         _ = io_utils.format_quantity(315, ['sec', 14, 'hours'],
                                      [1, 60, 3600 * 24])