fixing tests for namedtuple
This commit is contained in:
		| @@ -149,7 +149,7 @@ class Edge(): | |||||||
|             if info.expectancy > float(self.edge_config.get('minimum_expectancy', 0.2)) and \ |             if info.expectancy > float(self.edge_config.get('minimum_expectancy', 0.2)) and \ | ||||||
|                 info.winrate > float(self.edge_config.get('minimum_winrate', 0.60)) and \ |                 info.winrate > float(self.edge_config.get('minimum_winrate', 0.60)) and \ | ||||||
|                     pair in pairs: |                     pair in pairs: | ||||||
|                         final.append(pair) |                 final.append(pair) | ||||||
|  |  | ||||||
|         if final: |         if final: | ||||||
|             logger.info( |             logger.info( | ||||||
| @@ -279,12 +279,14 @@ class Edge(): | |||||||
|  |  | ||||||
|         final = {} |         final = {} | ||||||
|         for x in df.itertuples(): |         for x in df.itertuples(): | ||||||
|             final[x.pair] = self._pair_info( |             info = { | ||||||
|                 x.stoploss, |                 'stoploss': x.stoploss, | ||||||
|                 x.winrate, |                 'winrate': x.winrate, | ||||||
|                 x.risk_reward_ratio, |                 'risk_reward_ratio': x.risk_reward_ratio, | ||||||
|                 x.required_risk_reward, |                 'required_risk_reward': x.required_risk_reward, | ||||||
|                 x.expectancy) |                 'expectancy': x.expectancy | ||||||
|  |             } | ||||||
|  |             final[x.pair] = self._pair_info(**info) | ||||||
|  |  | ||||||
|         # Returning a list of pairs in order of "expectancy" |         # Returning a list of pairs in order of "expectancy" | ||||||
|         return final |         return final | ||||||
|   | |||||||
| @@ -4,6 +4,7 @@ import logging | |||||||
| from datetime import datetime | from datetime import datetime | ||||||
| from functools import reduce | from functools import reduce | ||||||
| from typing import Dict, Optional | from typing import Dict, Optional | ||||||
|  | from collections import namedtuple | ||||||
| from unittest.mock import MagicMock, PropertyMock | from unittest.mock import MagicMock, PropertyMock | ||||||
|  |  | ||||||
| import arrow | import arrow | ||||||
| @@ -48,19 +49,20 @@ def patch_edge(mocker) -> None: | |||||||
|     # "LTC/BTC", |     # "LTC/BTC", | ||||||
|     # "XRP/BTC", |     # "XRP/BTC", | ||||||
|     # "NEO/BTC" |     # "NEO/BTC" | ||||||
|  |     pair_info = namedtuple('pair_info', 'stoploss, winrate, risk_reward_ratio, required_risk_reward, expectancy') | ||||||
|     mocker.patch('freqtrade.edge.Edge._cached_pairs', mocker.PropertyMock( |     mocker.patch('freqtrade.edge.Edge._cached_pairs', mocker.PropertyMock( | ||||||
|         return_value=[ |         return_value={ | ||||||
|             ['NEO/BTC', -0.20, 0.66, 3.71, 0.50, 1.71], |             'NEO/BTC': pair_info(-0.20, 0.66, 3.71, 0.50, 1.71), | ||||||
|             ['LTC/BTC', -0.21, 0.66, 3.71, 0.50, 1.71], |             'LTC/BTC': pair_info(-0.21, 0.66, 3.71, 0.50, 1.71), | ||||||
|         ] |         } | ||||||
|     )) |     )) | ||||||
|     mocker.patch('freqtrade.edge.Edge.stoploss', MagicMock(return_value=-0.20)) |     mocker.patch('freqtrade.edge.Edge.stoploss', MagicMock(return_value = -0.20)) | ||||||
|     mocker.patch('freqtrade.edge.Edge.calculate', MagicMock(return_value=True)) |     mocker.patch('freqtrade.edge.Edge.calculate', MagicMock(return_value = True)) | ||||||
|  |  | ||||||
|  |  | ||||||
| def get_patched_edge(mocker, config) -> Edge: | def get_patched_edge(mocker, config) -> Edge: | ||||||
|     patch_edge(mocker) |     patch_edge(mocker) | ||||||
|     edge = Edge(config) |     edge=Edge(config) | ||||||
|     return edge |     return edge | ||||||
|  |  | ||||||
| # Functions for recurrent object patching | # Functions for recurrent object patching | ||||||
| @@ -84,15 +86,15 @@ def get_patched_freqtradebot(mocker, config) -> FreqtradeBot: | |||||||
|     return FreqtradeBot(config) |     return FreqtradeBot(config) | ||||||
|  |  | ||||||
|  |  | ||||||
| def patch_coinmarketcap(mocker, value: Optional[Dict[str, float]] = None) -> None: | def patch_coinmarketcap(mocker, value: Optional[Dict[str, float]]=None) -> None: | ||||||
|     """ |     """ | ||||||
|     Mocker to coinmarketcap to speed up tests |     Mocker to coinmarketcap to speed up tests | ||||||
|     :param mocker: mocker to patch coinmarketcap class |     :param mocker: mocker to patch coinmarketcap class | ||||||
|     :return: None |     :return: None | ||||||
|     """ |     """ | ||||||
|  |  | ||||||
|     tickermock = MagicMock(return_value={'price_usd': 12345.0}) |     tickermock=MagicMock(return_value={'price_usd': 12345.0}) | ||||||
|     listmock = MagicMock(return_value={'data': [{'id': 1, 'name': 'Bitcoin', 'symbol': 'BTC', |     listmock=MagicMock(return_value={'data': [{'id': 1, 'name': 'Bitcoin', 'symbol': 'BTC', | ||||||
|                                                  'website_slug': 'bitcoin'}, |                                                  'website_slug': 'bitcoin'}, | ||||||
|                                                 {'id': 1027, 'name': 'Ethereum', 'symbol': 'ETH', |                                                 {'id': 1027, 'name': 'Ethereum', 'symbol': 'ETH', | ||||||
|                                                  'website_slug': 'ethereum'} |                                                  'website_slug': 'ethereum'} | ||||||
| @@ -108,7 +110,7 @@ def patch_coinmarketcap(mocker, value: Optional[Dict[str, float]] = None) -> Non | |||||||
| @pytest.fixture(scope="function") | @pytest.fixture(scope="function") | ||||||
| def default_conf(): | def default_conf(): | ||||||
|     """ Returns validated configuration suitable for most tests """ |     """ Returns validated configuration suitable for most tests """ | ||||||
|     configuration = { |     configuration={ | ||||||
|         "max_open_trades": 1, |         "max_open_trades": 1, | ||||||
|         "stake_currency": "BTC", |         "stake_currency": "BTC", | ||||||
|         "stake_amount": 0.001, |         "stake_amount": 0.001, | ||||||
|   | |||||||
| @@ -256,7 +256,7 @@ def test_edge_overrides_stake_amount(mocker, default_conf) -> None: | |||||||
|     # strategy stoploss should be ignored |     # strategy stoploss should be ignored | ||||||
|     freqtrade.strategy.stoploss = -0.05 |     freqtrade.strategy.stoploss = -0.05 | ||||||
|  |  | ||||||
|     with pytest.raises(IndexError): |     with pytest.raises(KeyError): | ||||||
|         freqtrade._get_trade_stake_amount('ETH/BTC') |         freqtrade._get_trade_stake_amount('ETH/BTC') | ||||||
|  |  | ||||||
|     assert freqtrade._get_trade_stake_amount('NEO/BTC') == 0.025 |     assert freqtrade._get_trade_stake_amount('NEO/BTC') == 0.025 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user