Add safe_value_fallback function

This commit is contained in:
Matthias
2020-04-09 19:34:48 +02:00
parent 346e09fed1
commit cbf5bf6735
2 changed files with 29 additions and 1 deletions

View File

@@ -9,7 +9,7 @@ import pytest
from freqtrade.data.converter import ohlcv_to_dataframe
from freqtrade.misc import (datesarray_to_datetimearray, file_dump_json,
file_load_json, format_ms_time, pair_to_filename,
plural, shorten_date)
plural, safe_value_fallback, shorten_date)
def test_shorten_date() -> None:
@@ -93,6 +93,19 @@ def test_format_ms_time() -> None:
assert format_ms_time(date_in_epoch_ms) == res.astimezone(None).strftime('%Y-%m-%dT%H:%M:%S')
def test_safe_value_fallback():
dict1 = {'keya': None, 'keyb': 2, 'keyc': 5}
dict2 = {'keya': 20, 'keyb': None, 'keyc': 6}
assert safe_value_fallback(dict1, dict2, 'keya', 'keya') == 20
assert safe_value_fallback(dict2, dict1, 'keya', 'keya') == 20
assert safe_value_fallback(dict1, dict2, 'keyb', 'keyb') == 2
assert safe_value_fallback(dict2, dict1, 'keyb', 'keyb') == 2
assert safe_value_fallback(dict1, dict2, 'keyc', 'keyc') == 5
assert safe_value_fallback(dict2, dict1, 'keyc', 'keyc') == 6
def test_plural() -> None:
assert plural(0, "page") == "pages"
assert plural(0.0, "page") == "pages"