Exemple #1
0
 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("")
Exemple #2
0
 def test_target_compound_units(self):
     """Test conversion to specified units."""
     self.assertEqual(ucal.interpret('1in^2 to mm^2'), '645.16 mm^2')
Exemple #3
0
 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')
Exemple #4
0
 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')
Exemple #5
0
 def test_binary_conversion(self):
     """Test conversion to hexademical numbers."""
     self.assertEqual(ucal.interpret('67 in bin'), '0b1000011')
Exemple #6
0
 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')
Exemple #7
0
 def test_binary_errors(self):
     """Test binary number error detection."""
     self.assertIn('only integers', ucal.interpret('1m in bin'))
Exemple #8
0
 def test_hexadecimal_errors(self):
     """Test hexadecimal number error detection."""
     self.assertIn('only integers', ucal.interpret('1m in hex'))