def test_coerce_requires_float_number(self): t = xso.Float() values = ["foo", [], ()] for value in values: with self.assertRaisesRegex(TypeError, "must be real number"): t.coerce(value)
def test_coerce_passes_decimal(self): t = xso.Float() values = [ decimal.Decimal("1.23"), ] for value in values: self.assertEqual(float(value), t.coerce(value))
def test_coerce_passes_real_numbers(self): t = xso.Float() values = [ # decimal.Decimal("1.23"), fractions.Fraction(1, 9), 1.234, 20, -1, -3.4, ] for value in values: self.assertEqual(float(value), t.coerce(value))
def test_format(self): t = xso.Float() self.assertEqual("123.3", t.format(123.3))
def test_parse_failure(self): t = xso.Float() with self.assertRaises(ValueError): t.parse("123.3f")
def test_parse(self): t = xso.Float() self.assertEqual(123.3, t.parse("123.3"))
def test_is_abstract_type(self): self.assertIsInstance(xso.Float(), xso.AbstractType)