0 3 0
Brett Smith - 3 months ago 2020-05-20 19:21:13
brettcsmith@brettcsmith.org
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.
3 files changed with 12 insertions and 11 deletions:
↑ Collapse Diff ↑
...
 
@@ -185,11 +185,13 @@ def load_rates(config, loaders, date):
185 185
 

	
186 186
 
def run(config, stdout, stderr):
187 187
 
    loaders = config.get_loaders()
188
 
    cost_rates = load_rates(config, loaders, config.args.date)
188
 
    date_rates = load_rates(config, loaders, config.args.date)
189 189
 
    if config.args.from_date is None:
190
 
        cost_rates = date_rates
190 191
 
        price_rates = None
191 192
 
    else:
192
 
        price_rates = load_rates(config, loaders, config.args.from_date)
193
 
        cost_rates = load_rates(config, loaders, config.args.from_date)
194
 
        price_rates = date_rates
193 195
 
    formatter = config.args.output_format.value(
194 196
 
        cost_rates,
195 197
 
        price_rates,
...
 
@@ -5,7 +5,7 @@ from setuptools import setup
5 5
 
setup(
6 6
 
    name='oxrlib',
7 7
 
    description="Library to query the Open Exchange Rates (OXR) API",
8
 
    version='2.1',
8
 
    version='2.2',
9 9
 
    author='Brett Smith',
10 10
 
    author_email='brettcsmith@brettcsmith.org',
11 11
 
    license='GNU AGPLv3+',
...
 
@@ -225,8 +225,8 @@ def test_from_date_rates(alternate_responder, output, any_date, output_format):
225 225
 
                          from_date=any_date, output_format=output_format,
226 226
 
                          denomination='USD')
227 227
 
    lines = lines_from_run(config, output)
228
 
    check_fx_amount(config, lines, '1 ANG', '2.051', 'AED', None, '1.909')
229
 
    check_fx_amount(config, lines, '1 AED', '0.487', 'ANG', None, '0.523')
228
 
    check_fx_amount(config, lines, '1 ANG', '1.909', 'AED', None, '2.051')
229
 
    check_fx_amount(config, lines, '1 AED', '0.523', 'ANG', None, '0.487')
230 230
 
    assert next(lines, None) is None
231 231
 

	
232 232
 
@parametrize_format
...
 
@@ -236,8 +236,8 @@ def test_from_date_conversion(alternate_responder, output, any_date, output_form
236 236
 
                          from_date=any_date, output_format=output_format,
237 237
 
                          denomination='USD')
238 238
 
    lines = lines_from_run(config, output)
239
 
    check_fx_amount(config, lines, '10.00 ANG', '0.558', 'USD', '$', '0.507')
240
 
    check_fx_amount(config, lines, '20.52 AED', '0.272', 'USD', '$', '0.265')
239
 
    check_fx_amount(config, lines, '10.00 ANG', '0.507', 'USD', '$', '0.558')
240
 
    check_fx_amount(config, lines, '19.10 AED', '0.265', 'USD', '$', '0.272')
241 241
 
    assert next(lines, None) is None
242 242
 

	
243 243
 
@parametrize_format
...
 
@@ -252,11 +252,10 @@ def test_rate_consistent_as_cost_and_price(alternate_responder, any_date, output
252 252
 
    config = build_config(date=any_date, **config_kwargs)
253 253
 
    with io.StringIO() as output:
254 254
 
        lines = lines_from_run(config, output)
255
 
        match = re.search(r'\{=?(\d+\.\d+ USD)\}', next(lines, "<EOF>"))
256
 
    assert match
257
 
    expect_rate = f' @ {match.group(1)}\n'
255
 
        match = re.search(r'\{=?\d+\.\d+ USD\}', next(lines, "<EOF>"))
256
 
    assert match is not None
258 257
 
    future_date = any_date.replace(year=any_date.year + 1)
259 258
 
    config = build_config(date=future_date, from_date=any_date, **config_kwargs)
260 259
 
    with io.StringIO() as output:
261 260
 
        lines = lines_from_run(config, output)
262
 
        assert next(lines, "<EOF>").endswith(expect_rate)
261
 
        assert match.group(0) in next(lines, "<EOF>")
0 comments (0 inline, 0 general)