def test_to_python_hyphenated_mixed_fraction_string(self):
        field = DecimalFractionField()
        value = '1-1/2'
        result = field.to_python(value)
        self.assertEqual(Decimal(3/2.0).quantize(Decimal('0.000')),
                         result.quantize(Decimal('0.000')))

        value = '1 - 1/2'
        result = field.to_python(value)
        self.assertEqual(Decimal(3/2.0).quantize(Decimal('0.000')),
                         result.quantize(Decimal('0.000')))
    def test_to_python_hyphenated_mixed_fraction_string(self):
        field = DecimalFractionField()
        value = '1-1/2'
        result = field.to_python(value)
        self.assertEqual(
            Decimal(3 / 2.0).quantize(Decimal('0.000')),
            result.quantize(Decimal('0.000')))

        value = '1 - 1/2'
        result = field.to_python(value)
        self.assertEqual(
            Decimal(3 / 2.0).quantize(Decimal('0.000')),
            result.quantize(Decimal('0.000')))
 def test_to_python_int(self):
     """
     Test that whena :class:`int` is passed to to_python()
     the value is returned as as :class:`decimal.Decimal`
     """
     field = DecimalFractionField()
     value = 1
     result = field.to_python(value)
     self.assertEqual(Decimal(value), result)
 def test_to_python_decimal(self):
     """
     Test that whena :class:`decimal.Decimal` is passed to to_python()
     the value is returned as is
     """
     field = DecimalFractionField()
     value = Decimal(.5)
     result = field.to_python(value)
     self.assertEqual(value, result)
 def test_to_python_int(self):
     """
     Test that whena :class:`int` is passed to to_python()
     the value is returned as as :class:`decimal.Decimal`
     """
     field = DecimalFractionField()
     value = 1
     result = field.to_python(value)
     self.assertEqual(Decimal(value), result)
 def test_to_python_decimal(self):
     """
     Test that whena :class:`decimal.Decimal` is passed to to_python()
     the value is returned as is
     """
     field = DecimalFractionField()
     value = Decimal(.5)
     result = field.to_python(value)
     self.assertEqual(value, result)
    def test_to_python_validation_errors(self):
        field = DecimalFractionField()
        with self.assertRaises(ValidationError):
            field.to_python('abcd')

        with self.assertRaises(ValidationError):
            field.to_python('1 1 1/3')

        with self.assertRaises(ValidationError):
            field.to_python('1 1')
 def test_to_python_fraction_string(self):
     field = DecimalFractionField()
     value = '1/2'
     result = field.to_python(value)
     self.assertEqual(Decimal('.5'), result)
 def test_to_python_float_string(self):
     field = DecimalFractionField()
     value = '0.5'
     result = field.to_python(value)
     self.assertEqual(Decimal(value), result)
 def test_to_python_fraction_string(self):
     field = DecimalFractionField()
     value = '1/2'
     result = field.to_python(value)
     self.assertEqual(Decimal('.5'), result)
 def test_to_python_float_string(self):
     field = DecimalFractionField()
     value = '0.5'
     result = field.to_python(value)
     self.assertEqual(Decimal(value), result)