Exemplo n.º 1
0
def test_comparing_money_with_different_type_raises():
    with pytest.raises(UnsupportedOperatorType):
        Money(D('42'), 'EUR') > 21
    with pytest.raises(UnsupportedOperatorType):
        Money(D('42'), 'EUR') >= D('42')
    with pytest.raises(UnsupportedOperatorType):
        Money(D('42'), 'EUR') < 21
    with pytest.raises(UnsupportedOperatorType):
        Money(D('42'), 'EUR') <= 42
Exemplo n.º 2
0
def test_money_init_with_changed_cent_factor():
    old_precision = Money.cent_factor
    Money.cent_factor = '.001'
    m = Money(D('10.00123231'), 'EUR')
    assert m.amount == D('10.001')
    assert m.currency == 'EUR'
    Money.cent_factor = old_precision
Exemplo n.º 3
0
def test_comparing_money_with_different_currencies_raises():
    with pytest.raises(CurrencyMismatch):
        Money(D('42'), 'EUR') > Money(D('84'), 'USD')
    with pytest.raises(CurrencyMismatch):
        Money(D('42'), 'USD') >= Money(D('84'), 'EUR')
    with pytest.raises(CurrencyMismatch):
        Money(D('42'), 'USD') < Money(D('21'), 'EUR')
    with pytest.raises(CurrencyMismatch):
        Money(D('42'), 'USD') <= Money(D('21'), 'EUR')
Exemplo n.º 4
0
def test_division_by_zero_raises_exception():
    with pytest.raises(ZeroDivisionError):
        Money(D('42'), 'EUR') / Money(D('0'), 'EUR')
Exemplo n.º 5
0
def test_division_by_one_returns_money():
    assert Money(D('42'), 'EUR') == Money(D('42'), 'EUR') / D('1')
Exemplo n.º 6
0
def test_money_not_equal_operator_with_other_objects():
    m1 = Money(D('42'), 'EUR')
    assert m1 != 42
    assert m1 != D('42')
    assert m1 != (D('42'), 'EUR')
Exemplo n.º 7
0
def test_money_init_decimal_amount():
    m = Money(D('10'), 'EUR')
    assert m.amount == D('10')
    assert m.currency == 'EUR'
Exemplo n.º 8
0
def test_money_init_invalid_amount():
    with pytest.raises(InvalidAmount):
        _ = Money('9,231', 'EUR')
Exemplo n.º 9
0
def test_addition_of_money_with_different_currencie_raises():
    m1 = Money(D('21'), 'EUR')
    m2 = Money(D('21'), 'USD')
    with pytest.raises(CurrencyMismatch):
        m1 + m2
Exemplo n.º 10
0
def test_multiplication_of_money_with_money_raises():
    with pytest.raises(UnsupportedOperatorType):
        Money(D('21'), 'EUR') * Money(D('2'), 'EUR')
Exemplo n.º 11
0
def test_money_init_integer_amount():
    m = Money(10, 'EUR')
    assert m.amount == D('10')
    assert m.currency == 'EUR'
Exemplo n.º 12
0
def test_subtraction_of_money_with_different_currencies_raises():
    with pytest.raises(CurrencyMismatch):
        Money(D('42'), 'EUR') - Money(D('42'), 'USD')
Exemplo n.º 13
0
def test_subtraction_of_money_with_other_types_raises():
    with pytest.raises(UnsupportedOperatorType):
        Money(D('42'), 'EUR') - D('42')
Exemplo n.º 14
0
def test_subtraction_of_money():
    assert Money(D('21'), 'EUR') == (
            Money(D('42'), 'EUR') - Money(D('21'), 'EUR'))
Exemplo n.º 15
0
def test_using_sum_on_money():
    m1 = Money(D('21'), 'EUR')
    m2 = Money(D('21'), 'EUR')
    assert Money(D('42'), 'EUR') == sum([m1, m2])
Exemplo n.º 16
0
def test_addition_of_money_with_other_types_raises():
    with pytest.raises(UnsupportedOperatorType):
        Money(D('21'), 'EUR') + D('21')
Exemplo n.º 17
0
def test_division_by_decimal_returns_money():
    assert Money(D('8.4'), 'EUR') == Money(D('42'), 'EUR') / D('5')
Exemplo n.º 18
0
def test_multiplication_of_money_with_decimal():
    assert Money(D('42'), 'EUR') == Money(D('21'), 'EUR') * D('2')
    assert Money(D('42'), 'EUR') == D('2') * Money(D('21'), 'EUR')
Exemplo n.º 19
0
def test_division_with_different_currency_raises():
    with pytest.raises(CurrencyMismatch):
        Money(D('42'), 'EUR') / Money(D('21'), 'USD')
Exemplo n.º 20
0
def test_money_init_rounds_amount_to_cent_factor():
    m = Money(D('10.00123231'), 'EUR')
    assert m.amount == D('10.00')
    assert m.currency == 'EUR'
Exemplo n.º 21
0
def test_money_init_float_amount():
    m = Money(10.0, 'EUR')
    assert m.amount == D('10')
    assert m.currency == 'EUR'
Exemplo n.º 22
0
def test_money_equal_operator():
    m1 = Money(D('42'), 'EUR')
    m2 = Money(D('42'), 'EUR')
    assert m1 == m2
Exemplo n.º 23
0
def test_multiplication_with_non_decimal_raises():
    with pytest.raises(UnsupportedOperatorType):
        Money(D('21'), 'EUR') * 2
Exemplo n.º 24
0
def test_addition_of_money():
    m1 = Money(D('21'), 'EUR')
    m2 = Money(D('21'), 'EUR')
    expected = Money(D('42'), 'EUR')
    assert m1 + m2 == expected
Exemplo n.º 25
0
def test_money_repr():
    m = Money(D('42'), 'EUR')
    assert "Money(amount=Decimal('42.00'), currency='EUR')" == repr(m)
Exemplo n.º 26
0
def test_division_of_money_with_money():
    assert D('2') == Money(D('42'), 'EUR') / Money(D('21'), 'EUR')
Exemplo n.º 27
0
def test_money_equal_operator_with_different_currencies():
    m1 = Money(D('42'), 'EUR')
    m2 = Money(D('42'), 'USD')
    assert not m1 == m2
Exemplo n.º 28
0
def test_money_init_string_amount():
    m = Money('10', 'EUR')
    assert m.amount == D('10')
    assert m.currency == 'EUR'
Exemplo n.º 29
0
def test_money_not_equal_operator_with_different_amount():
    m1 = Money(D('42'), 'EUR')
    m2 = Money(D('21'), 'EUR')
    assert m1 != m2
Exemplo n.º 30
0
def test_devision_of_money_with_money_fraction():
    assert D('8.4') == Money(D('42'), 'EUR') / Money(D('5'), 'EUR')