Beispiel #1
0
 def get_temperature(self, units='celsius'):
     # Returns random temperature within defined range
     current_temp = random.randrange(self.lower_bound, self.upper_bound)
     if units == 'fahrenheit':
         current_temp = utils.convert_temp_units(
             current_temp,
             units_from='celsius',
             units_to='fahrenheit'
         )
     return current_temp
Beispiel #2
0
 def test_unknown_to_units(self):
     """Unknown units cannot be converted from"""
     with self.assertRaises(KeyError):
         utils.convert_temp_units(68.0, 'fahrenheit', 'invalid')
Beispiel #3
0
 def test_convert_fahrenheit_to_celsius(self):
     """Fahrenheit is converted to celsius"""
     self.assertEquals(
         utils.convert_temp_units(68.0, 'fahrenheit', 'celsius'), 20.0)
Beispiel #4
0
 def test_unknown_from_units(self):
     """Unknown units cannot be converted from"""
     with self.assertRaises(KeyError):
         utils.convert_temp_units(68.0, 'invalid', 'celsius')
Beispiel #5
0
 def test_convert_celsius_to_fahrenheit(self):
     """Celsisus is converted to fahrenheit"""
     self.assertEquals(
         utils.convert_temp_units(20.0, 'celsius', 'fahrenheit'), 68.0)