historical: Fix the rate ordering with two dates.

Darnit, I wrote the tests first, and I wrote them right, and then I
mixed up the ordering in the code, and somehow I convinced myself
the code was the right and the tests were wrong. But no, I had the
tests right, this is really what we want. This gets the output to
follow the examples from our bookkeeping documentation.
This commit is contained in:
Brett Smith 2020-05-20 15:20:37 -04:00
parent ae3e4617d3
commit c9382a2604
3 changed files with 12 additions and 11 deletions

View file

@ -185,11 +185,13 @@ def load_rates(config, loaders, date):
def run(config, stdout, stderr):
loaders = config.get_loaders()
cost_rates = load_rates(config, loaders, config.args.date)
date_rates = load_rates(config, loaders, config.args.date)
if config.args.from_date is None:
cost_rates = date_rates
price_rates = None
else:
price_rates = load_rates(config, loaders, config.args.from_date)
cost_rates = load_rates(config, loaders, config.args.from_date)
price_rates = date_rates
formatter = config.args.output_format.value(
cost_rates,
price_rates,

View file

@ -5,7 +5,7 @@ from setuptools import setup
setup(
name='oxrlib',
description="Library to query the Open Exchange Rates (OXR) API",
version='2.1',
version='2.2',
author='Brett Smith',
author_email='brettcsmith@brettcsmith.org',
license='GNU AGPLv3+',

View file

@ -225,8 +225,8 @@ def test_from_date_rates(alternate_responder, output, any_date, output_format):
from_date=any_date, output_format=output_format,
denomination='USD')
lines = lines_from_run(config, output)
check_fx_amount(config, lines, '1 ANG', '2.051', 'AED', None, '1.909')
check_fx_amount(config, lines, '1 AED', '0.487', 'ANG', None, '0.523')
check_fx_amount(config, lines, '1 ANG', '1.909', 'AED', None, '2.051')
check_fx_amount(config, lines, '1 AED', '0.523', 'ANG', None, '0.487')
assert next(lines, None) is None
@parametrize_format
@ -236,8 +236,8 @@ def test_from_date_conversion(alternate_responder, output, any_date, output_form
from_date=any_date, output_format=output_format,
denomination='USD')
lines = lines_from_run(config, output)
check_fx_amount(config, lines, '10.00 ANG', '0.558', 'USD', '$', '0.507')
check_fx_amount(config, lines, '20.52 AED', '0.272', 'USD', '$', '0.265')
check_fx_amount(config, lines, '10.00 ANG', '0.507', 'USD', '$', '0.558')
check_fx_amount(config, lines, '19.10 AED', '0.265', 'USD', '$', '0.272')
assert next(lines, None) is None
@parametrize_format
@ -252,11 +252,10 @@ def test_rate_consistent_as_cost_and_price(alternate_responder, any_date, output
config = build_config(date=any_date, **config_kwargs)
with io.StringIO() as output:
lines = lines_from_run(config, output)
match = re.search(r'\{=?(\d+\.\d+ USD)\}', next(lines, "<EOF>"))
assert match
expect_rate = f' @ {match.group(1)}\n'
match = re.search(r'\{=?\d+\.\d+ USD\}', next(lines, "<EOF>"))
assert match is not None
future_date = any_date.replace(year=any_date.year + 1)
config = build_config(date=future_date, from_date=any_date, **config_kwargs)
with io.StringIO() as output:
lines = lines_from_run(config, output)
assert next(lines, "<EOF>").endswith(expect_rate)
assert match.group(0) in next(lines, "<EOF>")