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