Example #1
0
def test_format_currency_sign_position_3_positive_preceding_cs():
    """Tests sign position 3, positive value, and preceding symbol."""
    test_currency = conf.Currency(
        currency_symbol='$', positive_sign='+', p_sign_posn=3
    )

    assert test_currency.format_currency('1.00') == '$+1.00'
Example #2
0
def test_format_currency_sign_position_other_negative_preceding_cs():
    """Tests 'other' sign position, negative value, and preceding symbol."""
    test_currency = conf.Currency(
        currency_symbol='$', negative_sign='-', n_sign_posn=None
    )

    assert test_currency.format_currency('-1.00') == '-$1.00'
Example #3
0
def test_format_currency_sign_position_4_negative_preceding_cs():
    """Tests sign position 4, positive value, and preceding symbol."""
    test_currency = conf.Currency(
        currency_symbol='$', negative_sign='-', n_sign_posn=4
    )

    assert test_currency.format_currency('-1.00') == '$1.00-'
Example #4
0
def test_format_currency_symbol_international():
    """Tests that international currency symbol works properly."""
    test_currency = conf.Currency(int_curr_symbol='USD')

    currency_string = test_currency.format_currency('1.00', international=True)

    assert currency_string == 'USD1.00'
Example #5
0
def test_format_currency_symbol_precedes_with_space_positive():
    """Tests currency symbol is applied preceding positive value with space."""
    test_currency = conf.Currency(
        currency_symbol='$', p_cs_precedes=True, p_sep_by_space=True
    )

    assert test_currency.format_currency('1.00') == '$ 1.00'
Example #6
0
def test_format_currency_symbol_follows_with_space_negative():
    """Tests currency symbol is applied following negative value with space."""
    test_currency = conf.Currency(
        currency_symbol='$', n_cs_precedes=False, n_sep_by_space=True
    )

    assert test_currency.format_currency('-1.00') == '1.00 $'
Example #7
0
def test_currency_format_grouping_by_1():
    """Tests that grouping works properly for groups of 1."""
    test_currency = conf.Currency(mon_grouping=1, mon_thousands_sep=',')

    assert test_currency.format_currency('1.00') == '1.00'
    assert test_currency.format_currency('10.00') == '1,0.00'
    assert test_currency.format_currency('100.00') == '1,0,0.00'
    assert test_currency.format_currency('1000.00') == '1,0,0,0.00'
Example #8
0
def test_format_currency_sign_position_other_positive_following_cs():
    """Tests 'other' sign position, positive value, and following symbol."""
    test_currency = conf.Currency(
        currency_symbol='$', p_cs_precedes=False,
        positive_sign='+', p_sign_posn=None
    )

    assert test_currency.format_currency('1.00') == '+1.00$'
Example #9
0
def test_format_currency_sign_position_4_negative_following_cs():
    """Tests sign position 4, negative value, and following symbol."""
    test_currency = conf.Currency(
        currency_symbol='$', n_cs_precedes=False,
        negative_sign='-', n_sign_posn=4
    )

    assert test_currency.format_currency('-1.00') == '1.00-$'
Example #10
0
def test_format_currency_sign_position_0_positive_following_cs():
    """Tests sign position 0, positive value, and following symbol."""
    test_currency = conf.Currency(
        currency_symbol='$', p_cs_precedes=False,
        positive_sign='+', p_sign_posn=0
    )

    assert test_currency.format_currency('1.00') == '(1.00$)'
def test_non_decimal_currency_format():
    """Tests that using a non-decimal currency will give correct result."""
    test_currency = conf.Currency(frac_digits=0)

    assert test_currency.format_currency(10) == '10'
    assert test_currency.format_currency('10') == '10'
    assert test_currency.format_currency('-100') == '100'
    assert test_currency.format_currency(-100) == '100'
def test_non_decimal_currency_format_rounding():
    """Tests that truncating the decimal part works as expected with decimal values."""
    test_currency = conf.Currency(frac_digits=0)

    assert test_currency.format_currency(Decimal('0.6')) == '1'
    assert test_currency.format_currency(Decimal('0.5')) == '1'
    assert test_currency.format_currency(Decimal('0.49')) == '0'
    assert test_currency.format_currency(Decimal('-0.49')) == '0'
    assert test_currency.format_currency(Decimal('-1.005')) == '1'
    assert test_currency.format_currency(Decimal('-1.5')) == '2'
Example #13
0
def test_format_currency_rounding_decimal():
    """Tests that rounding works as expected with decimal values."""
    test_currency = conf.Currency()

    assert test_currency.format_currency(Decimal('0.506')) == '0.51'
    assert test_currency.format_currency(Decimal('0.505')) == '0.51'
    assert test_currency.format_currency(Decimal('0.5049')) == '0.50'
    assert test_currency.format_currency(Decimal('0.005')) == '0.01'
    assert test_currency.format_currency(Decimal('0.0049')) == '0.00'
    assert test_currency.format_currency(Decimal('-0.0049')) == '0.00'
    assert test_currency.format_currency(Decimal('-0.005')) == '0.01'
Example #14
0
def test_format_currency_symbol_follows_positive():
    """Tests currency symbol is applied following positive value."""
    test_currency = conf.Currency(currency_symbol='$', p_cs_precedes=False)

    assert test_currency.format_currency('1.00') == '1.00$'
Example #15
0
def test_format_currency_symbol_precedes_negative():
    """Tests currency symbol is applied preceding negative value."""
    test_currency = conf.Currency(currency_symbol='$', n_cs_precedes=True)

    assert test_currency.format_currency('-1.00') == '$1.00'
Example #16
0
def test_currency_format_grouping_separator():
    """Tests that the grouping separator is properly applied."""
    test_currency = conf.Currency(mon_grouping=3, mon_thousands_sep='*')

    assert test_currency.format_currency('1000000.00') == '1*000*000.00'