Changeset - 9b6d562d46f5
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-05-06 18:48:27
brettcsmith@brettcsmith.org
tests: Stop calling fixtures directly.

Avoid deprecation warnings from pytest.
2 files changed with 38 insertions and 38 deletions:
0 comments (0 inline, 0 general)
tests/test_Configuration.py
Show inline comments
...
 
@@ -13,26 +13,24 @@ import oxrlib.loaders
 

	
 
INI_DIR_PATH = relpath('config_ini')
 

	
 
def config_from(ini_filename, arglist=None):
 
    if arglist is None:
 
        arglist = ['historical', any_date().isoformat()]
 
def config_from(ini_filename, arglist):
 
    ini_path = INI_DIR_PATH / ini_filename
 
    return oxrlib.config.Configuration(['--config-file', ini_path.as_posix()] + arglist)
 

	
 
def test_full_config():
 
    config = config_from('full.ini')
 
def test_full_config(any_date):
 
    config = config_from('full.ini', ['historical', any_date.isoformat()])
 
    loaders = config.get_loaders().loaders
 
    assert type(loaders[0]) is oxrlib.loaders.FileCache
 
    assert type(loaders[1]) is oxrlib.loaders.OXRAPIRequest
 
    assert len(loaders) == 2
 
    assert type(config.cache) is oxrlib.cache.CacheWriter
 

	
 
def test_incomplete_config():
 
    config = config_from('incomplete.ini')
 
def test_incomplete_config(any_date):
 
    config = config_from('incomplete.ini', ['historical', any_date.isoformat()])
 
    assert not config.get_loaders().loaders
 

	
 
def test_empty_config():
 
    config = config_from(os.devnull)
 
def test_empty_config(any_date):
 
    config = config_from(os.devnull, ['historical', any_date.isoformat()])
 
    assert not config.get_loaders().loaders
 

	
 
@pytest.mark.parametrize('ini_filename,expected_currency,use_switch', [
tests/test_historical.py
Show inline comments
...
 
@@ -43,7 +43,7 @@ def historical1_responder():
 

	
 
def build_config(
 
        responder,
 
        date=None,
 
        date,
 
        amount=None,
 
        from_currency=None,
 
        to_currency=None,
...
 
@@ -53,7 +53,7 @@ def build_config(
 
        base='USD',
 
):
 
    return FakeConfig(responder, {
 
        'date': any_date() if date is None else date,
 
        'date': date,
 
        'base': base,
 
        'amount': None if amount is None else decimal.Decimal(amount),
 
        'from_currency': from_currency,
...
 
@@ -68,8 +68,8 @@ def lines_from_run(config, output):
 
    output.seek(0)
 
    return iter(output)
 

	
 
def test_rate_list(historical1_responder, output):
 
    config = build_config(historical1_responder)
 
def test_rate_list(historical1_responder, output, any_date):
 
    config = build_config(historical1_responder, any_date)
 
    lines = lines_from_run(config, output)
 
    assert next(lines).startswith('1 AED = 0.27229')
 
    assert next(lines) == '1 USD = 3.67246 AED\n'
...
 
@@ -78,78 +78,80 @@ def test_rate_list(historical1_responder, output):
 
    assert next(lines).startswith('1 ANG = 0.55865')
 
    assert next(lines) == '1 USD = 1.79 ANG\n'
 

	
 
def test_one_rate(historical1_responder, output):
 
    config = build_config(historical1_responder, from_currency='ANG')
 
def test_one_rate(historical1_responder, output, any_date):
 
    config = build_config(historical1_responder, any_date, from_currency='ANG')
 
    lines = lines_from_run(config, output)
 
    assert next(lines).startswith('1 ANG = 0.55865')
 
    assert next(lines) == '1 USD = 1.79 ANG\n'
 
    assert next(lines, None) is None
 

	
 
def test_conversion(historical1_responder, output):
 
    config = build_config(historical1_responder, amount=10, from_currency='AED')
 
def test_conversion(historical1_responder, output, any_date):
 
    config = build_config(historical1_responder, any_date, amount=10, from_currency='AED')
 
    lines = lines_from_run(config, output)
 
    assert next(lines) == '10.00 AED = 2.72 USD\n'
 
    assert next(lines, None) is None
 

	
 
def test_back_conversion(historical1_responder, output):
 
    config = build_config(historical1_responder,
 
def test_back_conversion(historical1_responder, output, any_date):
 
    config = build_config(historical1_responder, any_date,
 
                          amount=2, from_currency='USD', to_currency='ALL')
 
    lines = lines_from_run(config, output)
 
    assert next(lines) == '2.00 USD = 289 ALL\n'
 
    assert next(lines, None) is None
 

	
 
def test_ledger_rate(historical1_responder, output):
 
    config = build_config(historical1_responder, from_currency='ANG', ledger=True)
 
def test_ledger_rate(historical1_responder, output, any_date):
 
    config = build_config(historical1_responder, any_date,
 
                          from_currency='ANG', ledger=True)
 
    lines = lines_from_run(config, output)
 
    assert next(lines) == '1 ANG {=$0.55866} @ $0.55866\n'
 
    assert next(lines) == '1 USD {=1.79 ANG} @ 1.79 ANG\n'
 
    assert next(lines, None) is None
 

	
 
def test_ledger_conversion(historical1_responder, output):
 
    config = build_config(historical1_responder, from_currency='ALL', amount=300, ledger=True)
 
def test_ledger_conversion(historical1_responder, output, any_date):
 
    config = build_config(historical1_responder, any_date,
 
                          from_currency='ALL', amount=300, ledger=True)
 
    lines = lines_from_run(config, output)
 
    assert next(lines) == '300 ALL {=$0.006919} @ $0.006919\n'
 
    assert next(lines) == '$2.08\n'
 
    assert next(lines, None) is None
 

	
 
def test_signed_currencies(historical1_responder, output):
 
    config = build_config(historical1_responder, from_currency='AED',
 
                          ledger=True, signed_currencies=['EUR'])
 
def test_signed_currencies(historical1_responder, output, any_date):
 
    config = build_config(historical1_responder, any_date,
 
                          from_currency='AED', ledger=True, signed_currencies=['EUR'])
 
    lines = lines_from_run(config, output)
 
    assert next(lines) == '1 AED {=0.2723 USD} @ 0.2723 USD\n'
 
    assert next(lines) == '1 USD {=3.67246 AED} @ 3.67246 AED\n'
 
    assert next(lines, None) is None
 

	
 
def test_denomination(historical1_responder, output):
 
    config = build_config(historical1_responder, from_currency='ANG',
 
                          to_currency='AED', amount=10,
 
def test_denomination(historical1_responder, output, any_date):
 
    config = build_config(historical1_responder, any_date,
 
                          from_currency='ANG', to_currency='AED', amount=10,
 
                          ledger=True, denomination='USD')
 
    lines = lines_from_run(config, output)
 
    assert next(lines) == '10.00 ANG {=$0.55866} @ $0.55866\n'
 
    assert next(lines) == '20.52 AED {=$0.2723} @ $0.2723\n'
 
    assert next(lines, None) is None
 

	
 
def test_redundant_denomination(historical1_responder, output):
 
    config = build_config(historical1_responder, from_currency='ANG',
 
                          to_currency='USD', amount=10,
 
def test_redundant_denomination(historical1_responder, output, any_date):
 
    config = build_config(historical1_responder, any_date,
 
                          from_currency='ANG', to_currency='USD', amount=10,
 
                          ledger=True, denomination='USD')
 
    lines = lines_from_run(config, output)
 
    assert next(lines) == '10.00 ANG {=$0.55866} @ $0.55866\n'
 
    assert next(lines) == '$5.59\n'
 
    assert next(lines, None) is None
 

	
 
def test_from_denomination(historical1_responder, output):
 
    config = build_config(historical1_responder, from_currency='USD',
 
                          to_currency='ALL', amount=10,
 
def test_from_denomination(historical1_responder, output, any_date):
 
    config = build_config(historical1_responder, any_date,
 
                          from_currency='USD', to_currency='ALL', amount=10,
 
                          ledger=True, denomination='USD')
 
    lines = lines_from_run(config, output)
 
    assert next(lines) == '$10.00\n'
 
    assert next(lines) == '1,445 ALL {=$0.006919} @ $0.006919\n'
 
    assert next(lines, None) is None
 

	
 
def test_rate_precision_added_as_needed(historical1_responder, output):
 
    config = build_config(historical1_responder, from_currency='RUB',
 
                          to_currency='USD', amount=63805,
 
def test_rate_precision_added_as_needed(historical1_responder, output, any_date):
 
    config = build_config(historical1_responder, any_date,
 
                          from_currency='RUB', to_currency='USD', amount=63805,
 
                          ledger=True, denomination='USD')
 
    lines = lines_from_run(config, output)
 
    # 63,805 / 57.0763 (the RUB rate) == $1,117.89
0 comments (0 inline, 0 general)