def calculate_input(self): # try to parse new value this_input = self.text_ctrl_input.GetValue() if not this_input: return try: this_answer = ucal.interpret(this_input) except (ucal.ParserError, ucal.QuantityError) as e: this_answer = e.args[0] except decimal.DecimalException: this_answer = "Undefined" # add new value self.add_history(this_input, this_answer) # delete input self.text_ctrl_input.SetValue("")
def test_target_compound_units(self): """Test conversion to specified units.""" self.assertEqual(ucal.interpret('1in^2 to mm^2'), '645.16 mm^2')
def test_target_units_fallback(self): """Test fallback conversion if target units are invalid.""" self.assertEqual(ucal.interpret('1 in kg'), '0.0254 kg m')
def test_target_simple_units(self): """Test conversion to specified units.""" self.assertEqual(ucal.interpret('1m to mm'), '1000 mm') self.assertEqual(ucal.interpret('1m as mm'), '1000 mm') self.assertEqual(ucal.interpret('1m in mm'), '1000 mm')
def test_binary_conversion(self): """Test conversion to hexademical numbers.""" self.assertEqual(ucal.interpret('67 in bin'), '0b1000011')
def test_hexadecimal_conversion(self): """Test conversion to hexademical numbers.""" self.assertEqual(ucal.interpret('67 in hex'), '0x43') self.assertEqual(ucal.interpret('123 in hex'), '0x7B')
def test_binary_errors(self): """Test binary number error detection.""" self.assertIn('only integers', ucal.interpret('1m in bin'))
def test_hexadecimal_errors(self): """Test hexadecimal number error detection.""" self.assertIn('only integers', ucal.interpret('1m in hex'))