From 2080bf09525847129e97d573ce4ffaa4476ea60f Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 4 Dec 2021 14:40:05 +0100 Subject: [PATCH] Fix some formatting errors, add test for strategy version --- freqtrade/rpc/telegram.py | 9 +++++---- freqtrade/strategy/interface.py | 2 +- freqtrade/worker.py | 6 +++--- tests/rpc/test_rpc_telegram.py | 10 +++++++++- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 7fa4cf0f9..e6af85267 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -1305,10 +1305,11 @@ class Telegram(RPCHandler): :return: None """ strategy_version = self._rpc._freqtrade.strategy.version() - if strategy_version is None: - self._send_msg('*Version:* `{}`'.format(__version__)) - else: - self._send_msg('*Freqtrade version:* `{}`, *Strategy version:* `{}`'.format(__version__, strategy_version)) + version_string = f'*Version:* `{__version__}`' + if strategy_version is not None: + version_string += f', *Strategy version: * `{strategy_version}`' + + self._send_msg(version_string) @authorized_only def _show_config(self, update: Update, context: CallbackContext) -> None: diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index 38be19384..088777654 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -393,7 +393,7 @@ class IStrategy(ABC, HyperStrategyMixin): ] """ return [] - + def version(self) -> str: """ Returns version of the strategy. diff --git a/freqtrade/worker.py b/freqtrade/worker.py index c3822d2fc..2fe2de9e1 100755 --- a/freqtrade/worker.py +++ b/freqtrade/worker.py @@ -115,14 +115,14 @@ class Worker: if (now - self._heartbeat_msg) > self._heartbeat_interval: version = __version__ strategy_version = self.freqtrade.strategy.version() - if (strategy_version != None): - version += ', strategy_version: ' + strategy_version + if (strategy_version is not None): + version += ', strategy_version: ' + strategy_version logger.info(f"Bot heartbeat. PID={getpid()}, " f"version='{version}', state='{state.name}'") self._heartbeat_msg = now return state - + def _throttle(self, func: Callable[..., Any], throttle_secs: float, *args, **kwargs) -> Any: """ Throttles the given callable that it diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py index 1247affae..c1677320e 100644 --- a/tests/rpc/test_rpc_telegram.py +++ b/tests/rpc/test_rpc_telegram.py @@ -1559,12 +1559,20 @@ def test_help_handle(default_conf, update, mocker) -> None: def test_version_handle(default_conf, update, mocker) -> None: - telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf) + telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) telegram._version(update=update, context=MagicMock()) assert msg_mock.call_count == 1 assert '*Version:* `{}`'.format(__version__) in msg_mock.call_args_list[0][0][0] + msg_mock.reset_mock() + freqtradebot.strategy.version = lambda: '1.1.1' + + telegram._version(update=update, context=MagicMock()) + assert msg_mock.call_count == 1 + assert '*Version:* `{}`'.format(__version__) in msg_mock.call_args_list[0][0][0] + assert '*Strategy version: * `1.1.1`' in msg_mock.call_args_list[0][0][0] + def test_show_config_handle(default_conf, update, mocker) -> None: