Exemple #1
0
    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)
Exemple #2
0
    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))
Exemple #3
0
    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))
Exemple #4
0
 def test_format(self):
     t = xso.Float()
     self.assertEqual("123.3", t.format(123.3))
Exemple #5
0
 def test_parse_failure(self):
     t = xso.Float()
     with self.assertRaises(ValueError):
         t.parse("123.3f")
Exemple #6
0
 def test_parse(self):
     t = xso.Float()
     self.assertEqual(123.3, t.parse("123.3"))
Exemple #7
0
 def test_is_abstract_type(self):
     self.assertIsInstance(xso.Float(), xso.AbstractType)