From ed8d8057974ef897a32bb40bbb6d57f22d48bb91 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 18 Oct 2019 11:31:43 +0200 Subject: [PATCH 1/4] Make paths os independent to have tests pass on windows --- tests/test_configuration.py | 9 +++++---- tests/test_plotting.py | 5 +++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/test_configuration.py b/tests/test_configuration.py index b133c3609..2aa805fe6 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -399,7 +399,7 @@ def test_setup_configuration_with_arguments(mocker, default_conf, caplog) -> Non assert 'pair_whitelist' in config['exchange'] assert 'datadir' in config assert log_has('Using data directory: {} ...'.format("/foo/bar"), caplog) - assert log_has('Using user-data directory: {} ...'.format("/tmp/freqtrade"), caplog) + assert log_has('Using user-data directory: {} ...'.format(Path("/tmp/freqtrade")), caplog) assert 'user_data_dir' in config assert 'ticker_interval' in config @@ -652,9 +652,9 @@ def test_create_userdata_dir(mocker, default_conf, caplog) -> None: x = create_userdata_dir('/tmp/bar', create_dir=True) assert md.call_count == 7 assert md.call_args[1]['parents'] is False - assert log_has('Created user-data directory: /tmp/bar', caplog) + assert log_has(f'Created user-data directory: {Path("/tmp/bar")}', caplog) assert isinstance(x, Path) - assert str(x) == "/tmp/bar" + assert str(x) == str(Path("/tmp/bar")) def test_create_userdata_dir_exists(mocker, default_conf, caplog) -> None: @@ -669,7 +669,8 @@ def test_create_userdata_dir_exists_exception(mocker, default_conf, caplog) -> N mocker.patch.object(Path, "is_dir", MagicMock(return_value=False)) md = mocker.patch.object(Path, 'mkdir', MagicMock()) - with pytest.raises(OperationalException, match=r'Directory `/tmp/bar` does not exist.*'): + with pytest.raises(OperationalException, + match=r'Directory `.{1,2}tmp.{1,2}bar` does not exist.*'): create_userdata_dir('/tmp/bar', create_dir=False) assert md.call_count == 0 diff --git a/tests/test_plotting.py b/tests/test_plotting.py index 86f5610da..a39b2b76e 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -214,11 +214,12 @@ def test_generate_plot_file(mocker, caplog): store_plot_file(fig, filename="freqtrade-plot-UNITTEST_BTC-5m.html", directory=Path("user_data/plots")) + expected_fn = str(Path("user_data/plots/freqtrade-plot-UNITTEST_BTC-5m.html")) assert plot_mock.call_count == 1 assert plot_mock.call_args[0][0] == fig assert (plot_mock.call_args_list[0][1]['filename'] - == "user_data/plots/freqtrade-plot-UNITTEST_BTC-5m.html") - assert log_has("Stored plot as user_data/plots/freqtrade-plot-UNITTEST_BTC-5m.html", + == expected_fn) + assert log_has(f"Stored plot as {expected_fn}", caplog) From e55b2a1a1cfca5b53a0888cea65719ad74a69ca1 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 18 Oct 2019 12:21:05 +0200 Subject: [PATCH 2/4] Allow test to pass on fast computers by setting the offset to -1 --- tests/test_freqtradebot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index 7fb84f078..d4a1d990a 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -1449,8 +1449,8 @@ def test_tsl_on_exchange_compatible_with_edge(mocker, edge_conf, fee, caplog, # setting stoploss freqtrade.strategy.stoploss = -0.02 - # setting stoploss_on_exchange_interval to 0 second - freqtrade.strategy.order_types['stoploss_on_exchange_interval'] = 0 + # setting stoploss_on_exchange_interval to -1 second since this test runs fast + freqtrade.strategy.order_types['stoploss_on_exchange_interval'] = -1 patch_get_signal(freqtrade) From 3208f30c308a200d5a9c2a37c15efcf17624e567 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 18 Oct 2019 12:48:12 +0200 Subject: [PATCH 3/4] Fix base64 test on windows --- tests/strategy/test_strategy.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/strategy/test_strategy.py b/tests/strategy/test_strategy.py index 52216e0ef..12770f2c7 100644 --- a/tests/strategy/test_strategy.py +++ b/tests/strategy/test_strategy.py @@ -1,6 +1,5 @@ # pragma pylint: disable=missing-docstring, protected-access, C0103 import logging -import tempfile import warnings from base64 import urlsafe_b64encode from os import path @@ -51,7 +50,7 @@ def test_load_strategy_base64(result, caplog, default_conf): assert 'rsi' in resolver.strategy.advise_indicators(result, {'pair': 'ETH/BTC'}) # Make sure strategy was loaded from base64 (using temp directory)!! assert log_has_re(r"Using resolved strategy SampleStrategy from '" - + tempfile.gettempdir() + r"/.*/SampleStrategy\.py'\.\.\.", caplog) + r".*(/|\\).*(/|\\)SampleStrategy\.py'\.\.\.", caplog) def test_load_strategy_invalid_directory(result, caplog, default_conf): From c649f9844e8bbff07b01a831fc80927a368523e0 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 18 Oct 2019 19:36:04 +0200 Subject: [PATCH 4/4] Compare >= instead of = --- freqtrade/freqtradebot.py | 2 +- tests/test_freqtradebot.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index d62c6a912..e2d4454ef 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -705,7 +705,7 @@ class FreqtradeBot: if trade.stop_loss > float(order['info']['stopPrice']): # we check if the update is neccesary update_beat = self.strategy.order_types.get('stoploss_on_exchange_interval', 60) - if (datetime.utcnow() - trade.stoploss_last_update).total_seconds() > update_beat: + if (datetime.utcnow() - trade.stoploss_last_update).total_seconds() >= update_beat: # cancelling the current stoploss on exchange first logger.info('Trailing stoploss: cancelling current stoploss on exchange (id:{%s})' 'in order to add another one ...', order['id']) diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index d4a1d990a..b2268acc5 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -1449,8 +1449,8 @@ def test_tsl_on_exchange_compatible_with_edge(mocker, edge_conf, fee, caplog, # setting stoploss freqtrade.strategy.stoploss = -0.02 - # setting stoploss_on_exchange_interval to -1 second since this test runs fast - freqtrade.strategy.order_types['stoploss_on_exchange_interval'] = -1 + # setting stoploss_on_exchange_interval to 0 seconds + freqtrade.strategy.order_types['stoploss_on_exchange_interval'] = 0 patch_get_signal(freqtrade)