fixing tests for namedtuple

This commit is contained in:
misagh 2018-11-04 18:43:57 +01:00
parent 14bfd4b7ee
commit 120655d262
3 changed files with 23 additions and 19 deletions

View File

@ -279,12 +279,14 @@ class Edge():
final = {}
for x in df.itertuples():
final[x.pair] = self._pair_info(
x.stoploss,
x.winrate,
x.risk_reward_ratio,
x.required_risk_reward,
x.expectancy)
info = {
'stoploss': x.stoploss,
'winrate': x.winrate,
'risk_reward_ratio': x.risk_reward_ratio,
'required_risk_reward': x.required_risk_reward,
'expectancy': x.expectancy
}
final[x.pair] = self._pair_info(**info)
# Returning a list of pairs in order of "expectancy"
return final

View File

@ -4,6 +4,7 @@ import logging
from datetime import datetime
from functools import reduce
from typing import Dict, Optional
from collections import namedtuple
from unittest.mock import MagicMock, PropertyMock
import arrow
@ -48,19 +49,20 @@ def patch_edge(mocker) -> None:
# "LTC/BTC",
# "XRP/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(
return_value=[
['NEO/BTC', -0.20, 0.66, 3.71, 0.50, 1.71],
['LTC/BTC', -0.21, 0.66, 3.71, 0.50, 1.71],
]
return_value={
'NEO/BTC': pair_info(-0.20, 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.calculate', MagicMock(return_value=True))
mocker.patch('freqtrade.edge.Edge.stoploss', MagicMock(return_value = -0.20))
mocker.patch('freqtrade.edge.Edge.calculate', MagicMock(return_value = True))
def get_patched_edge(mocker, config) -> Edge:
patch_edge(mocker)
edge = Edge(config)
edge=Edge(config)
return edge
# Functions for recurrent object patching
@ -84,15 +86,15 @@ def get_patched_freqtradebot(mocker, config) -> FreqtradeBot:
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
:param mocker: mocker to patch coinmarketcap class
:return: None
"""
tickermock = MagicMock(return_value={'price_usd': 12345.0})
listmock = MagicMock(return_value={'data': [{'id': 1, 'name': 'Bitcoin', 'symbol': 'BTC',
tickermock=MagicMock(return_value={'price_usd': 12345.0})
listmock=MagicMock(return_value={'data': [{'id': 1, 'name': 'Bitcoin', 'symbol': 'BTC',
'website_slug': 'bitcoin'},
{'id': 1027, 'name': 'Ethereum', 'symbol': 'ETH',
'website_slug': 'ethereum'}
@ -108,7 +110,7 @@ def patch_coinmarketcap(mocker, value: Optional[Dict[str, float]] = None) -> Non
@pytest.fixture(scope="function")
def default_conf():
""" Returns validated configuration suitable for most tests """
configuration = {
configuration={
"max_open_trades": 1,
"stake_currency": "BTC",
"stake_amount": 0.001,

View File

@ -256,7 +256,7 @@ def test_edge_overrides_stake_amount(mocker, default_conf) -> None:
# strategy stoploss should be ignored
freqtrade.strategy.stoploss = -0.05
with pytest.raises(IndexError):
with pytest.raises(KeyError):
freqtrade._get_trade_stake_amount('ETH/BTC')
assert freqtrade._get_trade_stake_amount('NEO/BTC') == 0.025