def test_set_rate_after_get_the_day_after(): # When setting a rate, the cache for the whole currency is reset, or else we get old fallback # values for dates where the currency server returned no value. setup_daily_rate() CAD.value_in(USD, date(2008, 4, 21)) # value will be cached USD.set_CAD_value(1/42, date(2008, 4, 20)) assert_almost_equal(CAD.value_in(USD, date(2008, 4, 21)), 42)
def test_physical_rates_db_remember_rates(tmpdir): # When a rates db uses a real file, rates are remembered dbpath = str(tmpdir.join('foo.db')) db = RatesDB(dbpath) db.set_CAD_value(date(2008, 4, 20), 'USD', 1/0.996115) db = RatesDB(dbpath) assert_almost_equal(db.get_rate(date(2008, 4, 20), 'CAD', 'USD'), 0.996115)
def test_set_rate_after_get_the_day_after(): # When setting a rate, the cache for the whole currency is reset, or else we get old fallback # values for dates where the currency server returned no value. setup_daily_rate() CAD.value_in(USD, date(2008, 4, 21)) # value will be cached USD.set_CAD_value(1 / 42, date(2008, 4, 20)) assert_almost_equal(CAD.value_in(USD, date(2008, 4, 21)), 42)
def test_physical_rates_db_remember_rates(tmpdir): # When a rates db uses a real file, rates are remembered dbpath = str(tmpdir.join('foo.db')) db = RatesDB(dbpath) db.set_CAD_value(date(2008, 4, 20), 'USD', 1 / 0.996115) db = RatesDB(dbpath) assert_almost_equal(db.get_rate(date(2008, 4, 20), 'CAD', 'USD'), 0.996115)
def test_set_rate_twice(): # When setting a rate for an index that already exists, the old rate is replaced by the new. setup_daily_rate() USD.set_CAD_value(1/42, date(2008, 4, 20)) assert_almost_equal(CAD.value_in(USD, date(2008, 4, 20)), 42)
def test_get_rate_reverse(): # It's possible to get the reverse value of a rate using the same data. setup_daily_rate() assert_almost_equal(USD.value_in(CAD, date(2008, 4, 20)), 1 / 0.996115)
def test_get_rate_with_daily_rate(): # Getting the rate exactly as set_rate happened returns the same rate. setup_daily_rate() assert_almost_equal(CAD.value_in(USD, date(2008, 4, 20)), 0.996115)
def test_get_rate_with_pivotal(): # It's possible to get a rate by using 2 records. # if 1 CAD = 0.996115 USD and 1 CAD = 0.633141 then 0.996115 USD = 0.633141 then 1 USD = 0.633141 / 0.996115 EUR setup_rates_of_multiple_currencies() assert_almost_equal(USD.value_in(EUR, date(2008, 4, 20)), 0.633141 / 0.996115)
def test_get_rate_multiple_currencies(): # Don't mix currency rates up. setup_rates_of_multiple_currencies() assert_almost_equal(CAD.value_in(USD, date(2008, 4, 20)), 0.996115) assert_almost_equal(CAD.value_in(EUR, date(2008, 4, 20)), 0.633141)
def test_set_rate_after_get(): # When setting a rate after a get of the same rate, the rate cache is correctly updated. setup_daily_rate() CAD.value_in(USD, date(2008, 4, 20)) # value will be cached USD.set_CAD_value(1/42, date(2008, 4, 20)) assert_almost_equal(CAD.value_in(USD, date(2008, 4, 20)), 42)
def test_set_rate_after_get(): # When setting a rate after a get of the same rate, the rate cache is correctly updated. setup_daily_rate() CAD.value_in(USD, date(2008, 4, 20)) # value will be cached USD.set_CAD_value(1 / 42, date(2008, 4, 20)) assert_almost_equal(CAD.value_in(USD, date(2008, 4, 20)), 42)
def test_set_rate_twice(): # When setting a rate for an index that already exists, the old rate is replaced by the new. setup_daily_rate() USD.set_CAD_value(1 / 42, date(2008, 4, 20)) assert_almost_equal(CAD.value_in(USD, date(2008, 4, 20)), 42)