tests: Prep historical tests for parametrizing on output format.
This commit is contained in:
parent
2d753c31aa
commit
7c11ae408c
1 changed files with 36 additions and 22 deletions
|
@ -38,6 +38,9 @@ class FakeConfig:
|
|||
|
||||
|
||||
output = pytest.fixture(lambda: io.StringIO())
|
||||
parametrize_format = pytest.mark.parametrize('output_format', [
|
||||
oxrhist.Formats.LEDGER,
|
||||
])
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def single_responder():
|
||||
|
@ -57,7 +60,7 @@ def build_config(
|
|||
from_currency=None,
|
||||
to_currency=None,
|
||||
from_date=None,
|
||||
ledger=False,
|
||||
output_format=oxrhist.Formats.RAW,
|
||||
signed_currencies=None,
|
||||
denomination=None,
|
||||
base='USD',
|
||||
|
@ -69,7 +72,7 @@ def build_config(
|
|||
'from_currency': from_currency,
|
||||
'to_currency': base if to_currency is None else to_currency,
|
||||
'from_date': from_date,
|
||||
'output_format': oxrhist.Formats['LEDGER' if ledger else 'RAW'],
|
||||
'output_format': output_format,
|
||||
'signed_currencies': [base] if signed_currencies is None else signed_currencies,
|
||||
'denomination': denomination,
|
||||
})
|
||||
|
@ -126,61 +129,68 @@ def test_back_conversion(single_responder, output, any_date):
|
|||
assert next(lines) == '2.00 USD = 289 ALL\n'
|
||||
assert next(lines, None) is None
|
||||
|
||||
def test_ledger_rate(single_responder, output, any_date):
|
||||
@parametrize_format
|
||||
def test_ledger_rate(single_responder, output, any_date, output_format):
|
||||
config = build_config(single_responder, any_date,
|
||||
from_currency='ANG', ledger=True)
|
||||
from_currency='ANG', output_format=output_format)
|
||||
lines = lines_from_run(config, output)
|
||||
check_fx_amount(config, lines, '1 ANG', '0.5586', 'USD', '$')
|
||||
check_fx_amount(config, lines, '1 USD', '1.79', 'ANG')
|
||||
assert next(lines, None) is None
|
||||
|
||||
def test_ledger_conversion(single_responder, output, any_date):
|
||||
config = build_config(single_responder, any_date,
|
||||
from_currency='ALL', amount=300, ledger=True)
|
||||
@parametrize_format
|
||||
def test_ledger_conversion(single_responder, output, any_date, output_format):
|
||||
config = build_config(single_responder, any_date, from_currency='ALL',
|
||||
amount=300, output_format=output_format)
|
||||
lines = lines_from_run(config, output)
|
||||
check_fx_amount(config, lines, '300 ALL', '0.00691', 'USD', '$')
|
||||
assert next(lines) == '$2.08\n'
|
||||
assert next(lines, None) is None
|
||||
|
||||
def test_signed_currencies(single_responder, output, any_date):
|
||||
config = build_config(single_responder, any_date,
|
||||
from_currency='AED', ledger=True, signed_currencies=['EUR'])
|
||||
@parametrize_format
|
||||
def test_signed_currencies(single_responder, output, any_date, output_format):
|
||||
config = build_config(single_responder, any_date, from_currency='AED',
|
||||
output_format=output_format, signed_currencies=['EUR'])
|
||||
lines = lines_from_run(config, output)
|
||||
check_fx_amount(config, lines, '1 AED', '0.272', 'USD', '$')
|
||||
check_fx_amount(config, lines, '1 USD', '3.672', 'AED')
|
||||
assert next(lines, None) is None
|
||||
|
||||
def test_denomination(single_responder, output, any_date):
|
||||
@parametrize_format
|
||||
def test_denomination(single_responder, output, any_date, output_format):
|
||||
config = build_config(single_responder, any_date,
|
||||
from_currency='ANG', to_currency='AED', amount=10,
|
||||
ledger=True, denomination='USD')
|
||||
output_format=output_format, denomination='USD')
|
||||
lines = lines_from_run(config, output)
|
||||
check_fx_amount(config, lines, '10.00 ANG', '0.558', 'USD', '$')
|
||||
check_fx_amount(config, lines, '20.52 AED', '0.272', 'USD', '$')
|
||||
assert next(lines, None) is None
|
||||
|
||||
def test_redundant_denomination(single_responder, output, any_date):
|
||||
@parametrize_format
|
||||
def test_redundant_denomination(single_responder, output, any_date, output_format):
|
||||
config = build_config(single_responder, any_date,
|
||||
from_currency='ANG', to_currency='USD', amount=10,
|
||||
ledger=True, denomination='USD')
|
||||
output_format=output_format, denomination='USD')
|
||||
lines = lines_from_run(config, output)
|
||||
check_fx_amount(config, lines, '10.00 ANG', '0.558', 'USD', '$')
|
||||
assert next(lines) == '$5.59\n'
|
||||
assert next(lines, None) is None
|
||||
|
||||
def test_from_denomination(single_responder, output, any_date):
|
||||
@parametrize_format
|
||||
def test_from_denomination(single_responder, output, any_date, output_format):
|
||||
config = build_config(single_responder, any_date,
|
||||
from_currency='USD', to_currency='ALL', amount=10,
|
||||
ledger=True, denomination='USD')
|
||||
output_format=output_format, denomination='USD')
|
||||
lines = lines_from_run(config, output)
|
||||
assert next(lines) == '$10.00\n'
|
||||
check_fx_amount(config, lines, '1,445 ALL', '0.00691', 'USD', '$')
|
||||
assert next(lines, None) is None
|
||||
|
||||
def test_rate_precision_added_as_needed(single_responder, output, any_date):
|
||||
@parametrize_format
|
||||
def test_rate_precision_added_as_needed(single_responder, output, any_date, output_format):
|
||||
config = build_config(single_responder, any_date,
|
||||
from_currency='RUB', to_currency='USD', amount=63805,
|
||||
ledger=True, denomination='USD')
|
||||
output_format=output_format, denomination='USD')
|
||||
lines = lines_from_run(config, output)
|
||||
# 63,805 / 57.0763 (the RUB rate) == $1,117.89
|
||||
# But using the truncated rate: 63,805 * .01752 == $1,117.86
|
||||
|
@ -190,19 +200,23 @@ def test_rate_precision_added_as_needed(single_responder, output, any_date):
|
|||
assert next(lines) == '$1,117.89\n'
|
||||
assert next(lines, None) is None
|
||||
|
||||
def test_from_date_rates(alternate_responder, output, any_date):
|
||||
@parametrize_format
|
||||
def test_from_date_rates(alternate_responder, output, any_date, output_format):
|
||||
config = build_config(alternate_responder, any_date,
|
||||
from_currency='ANG', to_currency='AED',
|
||||
from_date=any_date, ledger=True, denomination='USD')
|
||||
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')
|
||||
assert next(lines, None) is None
|
||||
|
||||
def test_from_date_conversion(alternate_responder, output, any_date):
|
||||
@parametrize_format
|
||||
def test_from_date_conversion(alternate_responder, output, any_date, output_format):
|
||||
config = build_config(alternate_responder, any_date,
|
||||
from_currency='ANG', to_currency='AED', amount=10,
|
||||
from_date=any_date, ledger=True, denomination='USD')
|
||||
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')
|
||||
|
|
Loading…
Reference in a new issue