Remove queue import

Improve tests
This commit is contained in:
Matthias 2020-08-14 20:12:59 +02:00
parent c4f78203ab
commit 9659e516c8
3 changed files with 27 additions and 5 deletions

View File

@ -1,5 +1,4 @@
import logging import logging
import queue
import sys import sys
from logging import Formatter from logging import Formatter
from logging.handlers import (BufferingHandler, RotatingFileHandler, from logging.handlers import (BufferingHandler, RotatingFileHandler,
@ -9,7 +8,6 @@ from typing import Any, Dict
from freqtrade.exceptions import OperationalException from freqtrade.exceptions import OperationalException
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
log_queue = queue.Queue(-1)
LOGFORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' LOGFORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
# Initialize bufferhandler - will be used for /log endpoints # Initialize bufferhandler - will be used for /log endpoints
@ -41,9 +39,10 @@ def _set_loggers(verbosity: int = 0, api_verbosity: str = 'info') -> None:
def setup_logging_pre() -> None: def setup_logging_pre() -> None:
""" """
Setup early logging. Early setup for logging.
This uses a queuehandler, which delays logging. Uses INFO loglevel and only the Streamhandler.
# TODO: How does QueueHandler work if no listenerhandler is attached?? Early messages (before proper logging setup) will therefore only be available
after the proper logging setup.
""" """
logging.basicConfig( logging.basicConfig(
level=logging.INFO, level=logging.INFO,

View File

@ -447,6 +447,14 @@ def test_api_logs(botclient):
assert isinstance(rc.json['logs'][0][3], str) assert isinstance(rc.json['logs'][0][3], str)
assert isinstance(rc.json['logs'][0][4], str) assert isinstance(rc.json['logs'][0][4], str)
rc = client_get(client, f"{BASE_URI}/logs?limit=5")
assert_response(rc)
assert len(rc.json) == 2
assert 'logs' in rc.json
# Using a fixed comparison here would make this test fail!
assert rc.json['log_count'] == 5
assert len(rc.json['logs']) == rc.json['log_count']
def test_api_edge_disabled(botclient, mocker, ticker, fee, markets): def test_api_edge_disabled(botclient, mocker, ticker, fee, markets):
ftbot, client = botclient ftbot, client = botclient

View File

@ -1127,6 +1127,21 @@ def test_telegram_logs(default_conf, update, mocker) -> None:
assert "freqtrade.rpc.telegram" in msg_mock.call_args_list[0][0][0] assert "freqtrade.rpc.telegram" in msg_mock.call_args_list[0][0][0]
assert "freqtrade.resolvers.iresolver" in msg_mock.call_args_list[0][0][0] assert "freqtrade.resolvers.iresolver" in msg_mock.call_args_list[0][0][0]
msg_mock.reset_mock()
context.args = ["1"]
telegram._logs(update=update, context=context)
assert msg_mock.call_count == 1
msg_mock.reset_mock()
# Test with changed MaxMessageLength
mocker.patch('freqtrade.rpc.telegram.MAX_TELEGRAM_MESSAGE_LENGTH', 200)
context = MagicMock()
context.args = []
telegram._logs(update=update, context=context)
# Called at least 3 times. Exact times will change with unrelated changes to setup messages
# Therefore we don't test for this explicitly.
assert msg_mock.call_count > 3
def test_edge_disabled(default_conf, update, mocker) -> None: def test_edge_disabled(default_conf, update, mocker) -> None:
msg_mock = MagicMock() msg_mock = MagicMock()