From 074a4ef65b73512b4589ed5700570578acbedb04 Mon Sep 17 00:00:00 2001 From: Gerald Lonlas Date: Sun, 21 Jan 2018 13:51:11 -0800 Subject: [PATCH] Change CryptoToFiatConverter._is_supported_fiat to Static method We do not need to load the whole object to know if a pair is in a static list. Unittest passed from 1.25s to 0.08s --- freqtrade/fiat_convert.py | 8 ++++---- freqtrade/tests/test_fiat_convert.py | 11 +++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/freqtrade/fiat_convert.py b/freqtrade/fiat_convert.py index 0132e531d..6c5383860 100644 --- a/freqtrade/fiat_convert.py +++ b/freqtrade/fiat_convert.py @@ -87,7 +87,7 @@ class CryptoToFiatConverter(): fiat_symbol = fiat_symbol.upper() # Check if the fiat convertion you want is supported - if not self._is_supported_fiat(fiat=fiat_symbol): + if not CryptoToFiatConverter.is_supported_fiat(fiat=fiat_symbol): raise ValueError('The fiat {} is not supported.'.format(fiat_symbol)) # Get the pair that interest us and return the price in fiat @@ -131,7 +131,7 @@ class CryptoToFiatConverter(): return price - def _is_supported_fiat(self, fiat: str) -> bool: + def is_supported_fiat(fiat: str) -> bool: """ Check if the FIAT your want to convert to is supported :param fiat: FIAT to check (e.g USD) @@ -140,7 +140,7 @@ class CryptoToFiatConverter(): fiat = fiat.upper() - return fiat in self.SUPPORTED_FIAT + return fiat in CryptoToFiatConverter.SUPPORTED_FIAT def _find_price(self, crypto_symbol: str, fiat_symbol: str) -> float: """ @@ -150,7 +150,7 @@ class CryptoToFiatConverter(): :return: float, price of the crypto-currency in Fiat """ # Check if the fiat convertion you want is supported - if not self._is_supported_fiat(fiat=fiat_symbol): + if not CryptoToFiatConverter.is_supported_fiat(fiat=fiat_symbol): raise ValueError('The fiat {} is not supported.'.format(fiat_symbol)) try: return float( diff --git a/freqtrade/tests/test_fiat_convert.py b/freqtrade/tests/test_fiat_convert.py index ddc1c8e29..48b305438 100644 --- a/freqtrade/tests/test_fiat_convert.py +++ b/freqtrade/tests/test_fiat_convert.py @@ -36,12 +36,11 @@ def test_pair_convertion_object(): assert pair_convertion.price == 30000.123 -def test_fiat_convert_is_supported(): - fiat_convert = CryptoToFiatConverter() - assert fiat_convert._is_supported_fiat(fiat='USD') is True - assert fiat_convert._is_supported_fiat(fiat='usd') is True - assert fiat_convert._is_supported_fiat(fiat='abc') is False - assert fiat_convert._is_supported_fiat(fiat='ABC') is False +def test_fiat_convert_is_supported(mocker): + assert CryptoToFiatConverter.is_supported_fiat(fiat='USD') is True + assert CryptoToFiatConverter.is_supported_fiat(fiat='usd') is True + assert CryptoToFiatConverter.is_supported_fiat(fiat='abc') is False + assert CryptoToFiatConverter.is_supported_fiat(fiat='ABC') is False def test_fiat_convert_add_pair():