From e971f043f42e96dbdc8b17204e02c9edcfe4c9ce Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 29 Mar 2024 13:12:01 +0100 Subject: [PATCH] Improve test cov --- ft_client/freqtrade_client/ft_client.py | 6 +++--- ft_client/test_client/test_rest_client.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ft_client/freqtrade_client/ft_client.py b/ft_client/freqtrade_client/ft_client.py index db34bce16..96a7510ff 100644 --- a/ft_client/freqtrade_client/ft_client.py +++ b/ft_client/freqtrade_client/ft_client.py @@ -19,7 +19,7 @@ logging.basicConfig( logger = logging.getLogger("ft_rest_client") -def add_arguments(): +def add_arguments(args: Any = None): parser = argparse.ArgumentParser() parser.add_argument("command", help="Positional argument defining the command to execute.", @@ -47,8 +47,8 @@ def add_arguments(): default=[] ) - args = parser.parse_args() - return vars(args) + pargs = parser.parse_args(args) + return vars(pargs) def load_config(configfile): diff --git a/ft_client/test_client/test_rest_client.py b/ft_client/test_client/test_rest_client.py index aab9e2bdd..24affd67c 100644 --- a/ft_client/test_client/test_rest_client.py +++ b/ft_client/test_client/test_rest_client.py @@ -2,6 +2,7 @@ from unittest.mock import MagicMock import pytest from freqtrade_client import FtRestClient +from freqtrade_client.ft_client import add_arguments, main_exec def get_rest_client(): @@ -92,3 +93,16 @@ def test_FtRestClient_call_explicit_methods(method, args): exec = getattr(client, method) exec(*args) assert mock.call_count == 1 + + +def test_ft_client(capsys): + with pytest.raises(SystemExit): + args = add_arguments(['-V']) + + args = add_arguments(['--show']) + assert isinstance(args, dict) + assert args['show'] is True + with pytest.raises(SystemExit): + main_exec(args) + captured = capsys.readouterr() + assert 'Possible commands' in captured.out