def test_prepare_value_string(self):
        """
        Test string fractions are returns as is
        """
        field = DecimalFractionField()
        result = field.prepare_value('1/4')
        self.assertEqual('1/4', result)

        result = field.prepare_value('1 1/4')
        self.assertEqual('1 1/4', result)
    def test_prepare_value_string(self):
        """
        Test string fractions are returns as is
        """
        field = DecimalFractionField()
        result = field.prepare_value('1/4')
        self.assertEqual('1/4', result)

        result = field.prepare_value('1 1/4')
        self.assertEqual('1 1/4', result)
 def test_prepare_value_limit_denominator(self):
     """
     Test `prepare_value()` when the field has been initialized
     with the limit_denominator paramter
     """
     field = DecimalFractionField(limit_denominator=3)
     result = field.prepare_value(Decimal(1/3.0))
     self.assertEqual('1/3', result)
 def test_prepare_value_float(self):
     """
     Test that a :class:`float` is properly
     converted to a string fraction
     """
     field = DecimalFractionField()
     result = field.prepare_value(float(.5))
     self.assertEqual('1/2', result)
 def test_prepare_value_decimal(self):
     """
     Test that a :class:`decimal.Decimal` is properly
     converted to a string fraction
     """
     field = DecimalFractionField()
     result = field.prepare_value(Decimal('.5'))
     self.assertEqual('1/2', result)
 def test_prepare_value_int(self):
     """
     Test that a standard int as input is returned
     as a string of that int, so `1` is returned as `'1'`
     """
     field = DecimalFractionField()
     result = field.prepare_value(1)
     self.assertEqual('1', result)
 def test_prepare_value_limit_denominator(self):
     """
     Test `prepare_value()` when the field has been initialized
     with the limit_denominator paramter
     """
     field = DecimalFractionField(limit_denominator=3)
     result = field.prepare_value(Decimal(1 / 3.0))
     self.assertEqual('1/3', result)
 def test_prepare_value_float(self):
     """
     Test that a :class:`float` is properly
     converted to a string fraction
     """
     field = DecimalFractionField()
     result = field.prepare_value(float(.5))
     self.assertEqual('1/2', result)
 def test_prepare_value_decimal(self):
     """
     Test that a :class:`decimal.Decimal` is properly
     converted to a string fraction
     """
     field = DecimalFractionField()
     result = field.prepare_value(Decimal('.5'))
     self.assertEqual('1/2', result)
 def test_prepare_value_int(self):
     """
     Test that a standard int as input is returned
     as a string of that int, so `1` is returned as `'1'`
     """
     field = DecimalFractionField()
     result = field.prepare_value(1)
     self.assertEqual('1', result)
    def test_prepare_value_coerce_thirds(self):
        """
        Test that when coerce_thirds is specified, then .66, .67, and .33, etc.
        are converted properly to 1/3 and 2/3
        """
        field = DecimalFractionField(coerce_thirds=True)
        result = field.prepare_value(Decimal(1/3.0))
        self.assertEqual('1/3', result)

        result = field.prepare_value(Decimal(1/3.0))
        self.assertEqual('1/3', result)

        result = field.prepare_value(Decimal(2/3.0))
        self.assertEqual('2/3', result)

        result = field.prepare_value(Decimal(2/6.0))
        self.assertEqual('1/3', result)

        result = field.prepare_value(Decimal(4/6.0))
        self.assertEqual('2/3', result)

        result = field.prepare_value(Decimal(4/3.0))
        self.assertEqual('1 1/3', result)

        result = field.prepare_value(Decimal(5/3.0))
        self.assertEqual('1 2/3', result)
    def test_prepare_value_coerce_thirds(self):
        """
        Test that when coerce_thirds is specified, then .66, .67, and .33, etc.
        are converted properly to 1/3 and 2/3
        """
        field = DecimalFractionField(coerce_thirds=True)
        result = field.prepare_value(Decimal(1 / 3.0))
        self.assertEqual('1/3', result)

        result = field.prepare_value(Decimal(1 / 3.0))
        self.assertEqual('1/3', result)

        result = field.prepare_value(Decimal(2 / 3.0))
        self.assertEqual('2/3', result)

        result = field.prepare_value(Decimal(2 / 6.0))
        self.assertEqual('1/3', result)

        result = field.prepare_value(Decimal(4 / 6.0))
        self.assertEqual('2/3', result)

        result = field.prepare_value(Decimal(4 / 3.0))
        self.assertEqual('1 1/3', result)

        result = field.prepare_value(Decimal(5 / 3.0))
        self.assertEqual('1 2/3', result)