Esempio n. 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("")
Esempio n. 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')
Esempio n. 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')
Esempio n. 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')
Esempio n. 5
0
 def test_binary_conversion(self):
     """Test conversion to hexademical numbers."""
     self.assertEqual(ucal.interpret('67 in bin'), '0b1000011')
Esempio n. 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')
Esempio n. 7
0
 def test_binary_errors(self):
     """Test binary number error detection."""
     self.assertIn('only integers', ucal.interpret('1m in bin'))
Esempio n. 8
0
 def test_hexadecimal_errors(self):
     """Test hexadecimal number error detection."""
     self.assertIn('only integers', ucal.interpret('1m in hex'))