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,11 +49,12 @@ 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))

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