def test_money_property_get(): w = get_wallet() assert w.amount == Money(42, 'EUR')
def test_money_property_set_invalid_unit(): w = get_wallet() with pytest.raises(UnitMixupError): w.amount = Money(3, 'USD')
def money_sum(iterable): return sum(iterable, Money(0, price.currency))
def usd(value): """ Get Money with USD currency for given value. """ return Money(value, "USD")
def test_repr(): assert repr(Money(42, 'EUR')) == "Money('42', 'EUR')" assert repr(Money('42.123', 'EUR')) == "Money('42.123', 'EUR')" assert repr(Money('42.0', 'EUR')) == "Money('42.0', 'EUR')" assert repr(Money('42.123', 'EUR')) == "Money('42.123', 'EUR')" assert repr(Money('42.123', 'USD')) == "Money('42.123', 'USD')"
def test_str(): assert str(Money('42.25', 'EUR')) == '42.25 EUR' assert str(Money('100', 'USD')) == '100 USD' assert str(Money(42, 'EUR')) == '42 EUR' assert str(Money('12.345', 'EUR')) == '12.345 EUR'
def test_money_init_from_value_with_currency(): class Dollar(int): currency = 'USD' assert Money(Dollar(42)) == Money(42, 'USD')
def test_money_init_from_money(): assert Money(Money(123, 'GBP')) == Money(123, 'GBP')
def test_money_without_currency(): with pytest.raises(TypeError): Money(42)
def test_money_init_does_not_call_settings(): def guarded_getattr(self, name): assert False, 'nobody should read settings yet' with patch.object(type(settings), '__getattr__', guarded_getattr): Money(42, 'EUR')
def money(value): return Money(value, 'USD')