def test_conversion_of_multiple_currencies(): assert amount_in_euro( Wallet(EUR(10), DZD(50), KRW(200), XBT(0.00002354)), fixed_exchange_rates(rate('DZD', 'EUR', 0.01), rate('KRW', 'EUR', 0.001), rate('XBT', 'EUR', 4000))) == EUR(10.79)
def test_real_conversion(): assert Wallet(EUR(10), USD(0.01)).amount(EUR, google_exchange_rates()) > EUR(10)
def test_wallet_should_sum_items_with_same_currency(amounts): assume(len(amounts) > 1) assert amount_in_euro(Wallet(*amounts)) == sum(amounts, EUR(0))
def test_wallet_should_change_item_to_required_currency(): assert amount_in_euro(Wallet(USD(10)), fixed_exchange_rates(rate('USD', 'EUR', 1.1))) == EUR(11)
def test_money_should_be_changed_with_an_exchange_rate(): assert EUR(10).change(USD, fixed_exchange_rates(rate('EUR', 'USD', 1.19))) == USD(11.9)
def test_empty_wallet_should_have_amount_of_0(): assert amount_in_euro(Wallet()) == EUR(0)
def test_money_should_raise_error_when_currency_mismatch(eur, usd): with pytest.raises(TypeError) as exception: _ = EUR(eur) + USD(usd) assert str(exception.value) == 'Mismatch currency, expected EUR got USD'
def test_money_should_have_a_neutral_element_for_add(element): assert EUR(0) + element == element + EUR(0) == element
def test_money_should_be_addable_when_same_currency(x, y): assert EUR(x) + EUR(y) == EUR(x + y)
def test_eur_should_have_2_digits_precision(): assert EUR.stock(0.01) == EUR(0.01) assert EUR.stock(0.001) == EUR(0)
def test_precision_should_round_to_nearest_value(): assert EUR.stock(1.234) == EUR(1.23) assert EUR.stock(1.235) == EUR(1.24) assert EUR.stock(1.236) == EUR(1.24)