def convert(self):
        try:
            converter = TemperatureConverter(self.input_value)
            self.clear_error()
            if self.cast_type == 'fahrenheit':
                self.output_value = converter.convert_to_fahrenheit()
            elif self.cast_type == 'kelvin':
                self.output_value = converter.convert_to_kelvin()
            elif self.cast_type == 'newton':
                self.output_value = converter.convert_to_newton()

        except ValueError:
            self.clear_output()
            self.error = 'The value is not numeric.\nEnter a numeric value.'
    def convert(self):
        try:
            self.logger.log('Button clicked')
            self.logger.log('Input value is %s' % self.input_value)
            self.logger.log('Selected cast type is %s' % self.cast_type)
            converter = TemperatureConverter(self.input_value)
            self.clear_error()
            if self.cast_type == 'fahrenheit':
                self.output_value = converter.convert_to_fahrenheit()
            elif self.cast_type == 'kelvin':
                self.output_value = converter.convert_to_kelvin()
            elif self.cast_type == 'newton':
                self.output_value = converter.convert_to_newton()

            self.logger.log('Result: %s' % self.output_value)

        except ValueError:
            self.clear_output()
            self.error = 'The value is not numeric.\nEnter a numeric value.'
            self.logger.log('Error occurred: %s' % self.error)
 def test_convert_from_string_value_with_point_f(self):
     string_value = TemperatureConverter("-13.5")
     self.assertAlmostEqual(string_value.convert_to_fahrenheit(), 7.7)
 def test_convert_from_positive_value_f(self):
     positive_value = TemperatureConverter(15)
     self.assertAlmostEqual(positive_value.convert_to_fahrenheit(), 59)
 def test_convert_from_negative_value_f(self):
     negative_value = TemperatureConverter(-11)
     self.assertAlmostEqual(negative_value.convert_to_fahrenheit(), 12.2)
 def test_convert_from_zero_f(self):
     zero_value = TemperatureConverter(0)
     self.assertAlmostEqual(zero_value.convert_to_fahrenheit(), 32)