fixing tests for namedtuple
This commit is contained in:
@@ -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,
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user