use pytest.approx in favor of "prec_satoshi" ...

This commit is contained in:
Matthias 2023-02-28 18:17:29 +01:00
parent 0707e70183
commit 3706d28125

View File

@ -19,15 +19,6 @@ from tests.conftest import (create_mock_trades, create_mock_trades_usdt, get_pat
patch_get_signal)
# Functions for recurrent object patching
def prec_satoshi(a, b) -> float:
"""
:return: True if A and B differs less than one satoshi.
"""
return abs(a - b) < 0.00000001
# Unit tests
def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
gen_response = {
'trade_id': 1,
@ -544,8 +535,8 @@ def test_rpc_balance_handle(default_conf, mocker, tickers):
rpc._fiat_converter = CryptoToFiatConverter()
result = rpc._rpc_balance(default_conf['stake_currency'], default_conf['fiat_display_currency'])
assert prec_satoshi(result['total'], 30.30909624)
assert prec_satoshi(result['value'], 454636.44360691)
assert pytest.approx(result['total']) == 30.30909624
assert pytest.approx(result['value']) == 454636.44360691
assert tickers.call_count == 1
assert tickers.call_args_list[0][1]['cached'] is True
assert 'USD' == result['symbol']
@ -866,17 +857,17 @@ def test_enter_tag_performance_handle_2(mocker, default_conf, markets, fee):
assert len(res) == 2
assert res[0]['enter_tag'] == 'TEST1'
assert res[0]['count'] == 1
assert prec_satoshi(res[0]['profit_pct'], 0.5)
assert pytest.approx(res[0]['profit_pct']) == 0.5
assert res[1]['enter_tag'] == 'Other'
assert res[1]['count'] == 1
assert prec_satoshi(res[1]['profit_pct'], 1.0)
assert pytest.approx(res[1]['profit_pct']) == 1.0
# Test for a specific pair
res = rpc._rpc_enter_tag_performance('ETC/BTC')
assert len(res) == 1
assert res[0]['count'] == 1
assert res[0]['enter_tag'] == 'TEST1'
assert prec_satoshi(res[0]['profit_pct'], 0.5)
assert pytest.approx(res[0]['profit_pct']) == 0.5
def test_exit_reason_performance_handle(default_conf_usdt, ticker, fee, mocker) -> None:
@ -922,17 +913,17 @@ def test_exit_reason_performance_handle_2(mocker, default_conf, markets, fee):
assert len(res) == 2
assert res[0]['exit_reason'] == 'sell_signal'
assert res[0]['count'] == 1
assert prec_satoshi(res[0]['profit_pct'], 0.5)
assert pytest.approx(res[0]['profit_pct']) == 0.5
assert res[1]['exit_reason'] == 'roi'
assert res[1]['count'] == 1
assert prec_satoshi(res[1]['profit_pct'], 1.0)
assert pytest.approx(res[1]['profit_pct']) == 1.0
# Test for a specific pair
res = rpc._rpc_exit_reason_performance('ETC/BTC')
assert len(res) == 1
assert res[0]['count'] == 1
assert res[0]['exit_reason'] == 'sell_signal'
assert prec_satoshi(res[0]['profit_pct'], 0.5)
assert pytest.approx(res[0]['profit_pct']) == 0.5
def test_mix_tag_performance_handle(default_conf, ticker, fee, mocker) -> None:
@ -975,10 +966,10 @@ def test_mix_tag_performance_handle_2(mocker, default_conf, markets, fee):
assert len(res) == 2
assert res[0]['mix_tag'] == 'TEST1 sell_signal'
assert res[0]['count'] == 1
assert prec_satoshi(res[0]['profit_pct'], 0.5)
assert pytest.approx(res[0]['profit_pct']) == 0.5
assert res[1]['mix_tag'] == 'Other roi'
assert res[1]['count'] == 1
assert prec_satoshi(res[1]['profit_pct'], 1.0)
assert pytest.approx(res[1]['profit_pct']) == 1.0
# Test for a specific pair
res = rpc._rpc_mix_tag_performance('ETC/BTC')
@ -986,7 +977,7 @@ def test_mix_tag_performance_handle_2(mocker, default_conf, markets, fee):
assert len(res) == 1
assert res[0]['count'] == 1
assert res[0]['mix_tag'] == 'TEST1 sell_signal'
assert prec_satoshi(res[0]['profit_pct'], 0.5)
assert pytest.approx(res[0]['profit_pct']) == 0.5
def test_rpc_count(mocker, default_conf, ticker, fee) -> None: