1
0
mirror of https://github.com/Rikj000/MoniGoMani.git synced 2022-03-06 00:08:05 +03:00

♻ Refactored IDE warnings out of unit tests

This commit is contained in:
Rik Helsen
2021-09-05 10:07:41 +02:00
parent d7bca992f6
commit da24c60a55
5 changed files with 136 additions and 164 deletions

View File

@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
import sys
from unittest.mock import MagicMock
sys.path.append('.')
@@ -9,137 +8,130 @@ sys.path.append('..')
from user_data.mgm_tools.mgm_hurry.FreqtradeCli import FreqtradeCli # noqa: E402
# --- ↓
# --- ↓ Unit Testing "initialisation"
# --- ↓
def test_initialisation():
"""
↓ Unit Testing "initialisation"
"""
fc = __get_instance('.')
assert isinstance(fc, FreqtradeCli)
# --- ↑
# --- ↓
# --- ↓ Unit Testing "basedir attr"
# --- ↓
def test_default_basedir_is_cwd():
"""
↓ Unit Testing "basedir attr"
"""
fc = __get_instance('.')
assert fc.basedir == '.'
# --- ↑
# --- ↓
# --- ↓ Unit Testing "install_type"
# --- ↓
def test_set_install_type_to_source():
"""
↓ Unit Testing "install_type"
"""
fc = __get_instance('.')
fc.install_type = 'source'
assert fc.install_type == 'source'
def test_set_incorrect_install_type_should_not_return_none():
"""
↓ Unit Testing incorrect "install_type" should not return none
"""
fc = __get_instance('.')
fc.install_type = 'foobar'
assert fc.install_type is not None
def test_set_incorrect_install_type_should_return_source():
"""
↓ Unit Testing incorrect "install_type" should return source
"""
fc = __get_instance('.')
fc.install_type = 'pytest'
assert fc.install_type == 'source'
def test_get_freqtrade_binary_path_unknown_install_type_should_return_docker_path():
'''
"""
Case:
- install_type = foobar
Expected:
- path is a string
- path contains 'docker-compose' because foobar
is an unknown install type
'''
"""
fc = __get_instance('.')
cmd = fc._get_freqtrade_binary_path('.', 'foobar')
assert isinstance(cmd, str) and \
cmd.find('docker-compose') > -1
# --- ↑
# --- ↓
# --- ↓ Unit Testing "_get_freqtrade_binary_path"
# --- ↓
def test_get_freqtrade_binary_path_docker():
'''
"""
↓ Unit Testing "_get_freqtrade_binary_path"
Case:
- install_type = docker
Expected:
- path is a string
- path contains 'docker-compose'
'''
"""
fc = __get_instance('.')
cmd = fc._get_freqtrade_binary_path('.', 'docker')
assert isinstance(cmd, str) \
and cmd.find('docker-compose') > -1
def test_get_freqtrade_binary_path_source():
'''
"""
↓ Unit Testing "_get_freqtrade_binary_path"
Case:
- install_type = source
Expected:
- path is a string
- path contains 'freqtrade'
- path contains '.env'
'''
"""
fc = __get_instance('.')
cmd = fc._get_freqtrade_binary_path('.', 'source')
assert isinstance(cmd, str) \
and cmd.find('freqtrade') > -1 \
and cmd.find('.env') > -1
assert isinstance(cmd, str) and (cmd.find('freqtrade') > -1) and (cmd.find('.env') > -1)
# --- ↑
# --- ↓
# --- ↓ Unit Testing "installation_exists"
# --- ↓
def test_installation_exists_should_return_bool():
'''
"""
↓ Unit Testing "installation_exists"
Case:
- without installation type
'''
"""
fc = __get_instance('.')
assert isinstance(fc.installation_exists(), bool)
def test_installation_exists_faulty_install_type():
fc = __get_instance('.')
fc.install_type = 'foobar'
assert fc.install_type != 'foobar'
def test_installation_exists_faulty_freqtrade_binary():
fc = __get_instance('.')
fc.install_type = 'source'
fc.freqtrade_binary = 'unknown'
assert fc.installation_exists() is False
def test_installation_exists_install_type_docker():
fc = __get_instance('.')
fc.install_type = 'docker'
fc.freqtrade_binary = 'unknown'
assert fc.installation_exists() is True
# --- ↑
# --- ↓
# --- ↓ Helper methods
# --- ↓
def __get_instance(directory: str):
"""Create instance of freqtradecli."""
"""
↓ Helper method: Create and get instance of FreqtradeCli
:return FreqtradeCli:
"""
fc = FreqtradeCli(directory)
fc.cli_logger = MagicMock()
return fc

View File

@@ -1,27 +1,28 @@
# -*- coding: utf-8 -*-
# import pytest
# This unit test file helps testing modular mgm-hurry code.
#
# 1. Create unit test for specific functionality
# - Verify unit test succeeds
# 2. Split and modularize code. The interface should remain unchanged.
# 3. Run unit test
# - Verify unit test still succeeds
#
# Also be aware to unit test on code and cli level if differences could occur.
#
# Interface mgm-hurry:
# MGMHurry.
# up
# install_freqtrade
# install_mgm
# setup
# cleanup
# download_candle_data
# hyperopt
# hyperopt_show_results
# hyperopt_show_epoch
# hyperopt_apply_epoch
# backtest
# start_trader
"""
This unit test file helps testing modular mgm-hurry code.
1. Create unit test for specific functionality
- Verify unit test succeeds
2. Split and modularize code. The interface should remain unchanged.
3. Run unit test
- Verify unit test still succeeds
Also be aware to unit test on code and cli level if differences could occur.
Interface mgm-hurry:
MGMHurry.
up
install_freqtrade
install_mgm
setup
cleanup
download_candle_data
hyperopt
hyperopt_show_results
hyperopt_show_epoch
backtest
start_trader
"""

View File

@@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
import os
import sys
from logging import Logger
from unittest.mock import MagicMock
import pytest
import sys
sys.path.append('.')
sys.path.append('..')
@@ -16,79 +17,77 @@ def test_initialisation():
assert isinstance(cli, MoniGoManiCli)
# --- ↓
# --- ↓ Unit Testing .installation_exists(self) -> bool
# --- ↓
def test_installation_exists_without_installation():
"""
↓ Unit Testing .installation_exists(self) -> bool
"""
os.path.exists = MagicMock(return_value=False)
mgm_cli = __get_instance()
assert mgm_cli.installation_exists() == False
assert mgm_cli.installation_exists() is False
def test_installation_exists_with_config_without_strategy():
"""
↓ Unit Testing .installation_exists(self) -> bool
"""
mgm_cli = __get_instance()
mgm_cli._mgm_config_json_exists = MagicMock(return_value=True)
mgm_cli._mgm_hyperstrategy_file_exists = MagicMock(return_value=False)
assert mgm_cli.installation_exists() == False
assert mgm_cli.installation_exists() is False
def test_installation_exists_without_config_with_strategy():
mgm_cli = __get_instance()
mgm_cli._mgm_hyperstrategy_file_exists = MagicMock(return_value=True)
mgm_cli._mgm_config_json_exists = MagicMock(return_value=False)
assert mgm_cli.installation_exists() == False
assert mgm_cli.installation_exists() is False
def test_installation_exists_with_valid_installation():
mgm_cli = __get_instance()
mgm_cli._mgm_hyperstrategy_file_exists = MagicMock(return_value=True)
mgm_cli._mgm_config_json_exists = MagicMock(return_value=True)
assert mgm_cli.installation_exists() == True
assert mgm_cli.installation_exists() is True
# --- ↑
# --- ↓
# --- ↓ Unit Testing .download_setup_mgm(branch:str = 'develop', target_dir:str = None)
# --- ↓
@pytest.mark.skip(reason='Test not implemented.')
def test_download_setup_mgm():
"""
↓ Unit Testing .download_setup_mgm(branch:str = 'develop', target_dir:str = None)
"""
assert NotImplemented
# --- ↑
# --- ↓
# --- ↓ Unit Testing .apply_best_results(self, strategy: str) -> bool
# --- ↓
@pytest.mark.skip(reason='Test not implemented.')
def test_apply_best_results():
"""
↓ Unit Testing .apply_best_results(self, strategy: str) -> bool
"""
assert NotImplemented
def test_apply_best_results_should_return_false_without_ho_json():
mgm_cli = __get_instance()
assert mgm_cli.apply_mgm_results('foobar-non-existing-strat') is False
# --- ↑
# --- ↓
# --- ↓ Unit Testing .run_command(self, command: str, output_file_name: str = None)
# --- ↓
@pytest.mark.skip(reason='Test not implemented.')
def test_run_command():
"""
↓ Unit Testing .run_command(self, command: str, output_file_name: str = None)
"""
assert NotImplemented
# --- ↑
# --- ↓
# --- ↓ Helper methods
# --- ↓
def __get_instance(basedir='.'):
"""
↓ Helper method: Create and get instance of MoniGoManiCli
:return MoniGoManiCli:
"""
cli = MoniGoManiCli(basedir)
cli.cli_logger = MagicMock()
return cli
def __get_logger(basedir='.') -> Logger:
return MagicMock()

View File

@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import sys
import pytest
sys.path.append('.')
@@ -12,101 +13,86 @@ def test_initialisation():
cfg = __get_instance()
assert isinstance(cfg, MoniGoManiConfig)
# --- ↓
# --- ↓ Unit Testing .reload(self) -> bool
# --- ↓
@pytest.mark.skip(reason='Test not implemented.')
def test_reload_with_valid_config_file():
"""
↓ Unit Testing .reload(self) -> bool
"""
assert NotImplemented
# --- ↑
# --- ↓
# --- ↓ Unit Testing .valid_hurry_dotfile_present(self) -> bool
# --- ↓
def test_valid_hurry_dotfile_present_should_return_true():
"""
↓ Unit Testing .valid_hurry_dotfile_present(self) -> bool
"""
obj = __get_instance()
assert obj.valid_hurry_dotfile_present() is True
# --- ↑
# --- ↓
# --- ↓ Unit Testing .create_config_files(self) -> bool
# --- ↓
@pytest.mark.skip(reason='Test not implemented.')
def test_create_config_files_faulty_target_dir():
"""
↓ Unit Testing .create_config_files(self) -> bool
"""
assert NotImplemented
@pytest.mark.skip(reason='Test not implemented.')
def test_create_config_files_faulty_example_file():
"""
↓ Unit Testing .create_config_files(self) faulty example file
"""
assert NotImplemented
# --- ↑
# --- ↓
# --- ↓ Unit Testing .load_config_files() -> dict
# --- ↓
@pytest.mark.skip(reason='Test not implemented.')
def test_load_config_files():
"""
↓ Unit Testing .load_config_files() -> dict
"""
assert NotImplemented
# --- ↑
# --- ↓
# --- ↓ Unit Testing .read_hurry_config() -> dict
# --- ↓
@pytest.mark.skip(reason='Test not implemented.')
def test_read_hurry_config():
"""
↓ Unit Testing .read_hurry_config() -> dict:
"""
assert NotImplemented
# --- ↑
# --- ↓
# --- ↓ Unit Testing "get_config_filename"
# --- ↓
@pytest.mark.skip(reason='Test not implemented.')
def test_get_config_filename():
assert NotImplemented
"""
↓ Unit Testing "get_config_filename"
"""
assert NotImplemented
# --- ↑
# --- ↓
# --- ↓ Unit Testing "load_config_file"
# --- ↓
@pytest.mark.skip(reason='Test not implemented.')
def test_load_config_file():
assert NotImplemented
"""
↓ Unit Testing "load_config_file"
"""
assert NotImplemented
# --- ↑
# --- ↓
# --- ↓ Unit Testing "write"
# --- ↓
@pytest.mark.skip(reason='Test not implemented.')
def test_write():
assert NotImplemented
# --- ↑
"""
↓ Unit Testing "write"
"""
assert NotImplemented
# ---
# --- ↓ Helper methods
# ---
# --- ↓
def __get_instance():
"""
↓ Helper method: Create and get instance of MoniGoManiConfig
:return MoniGoManiConfig:
"""
basedir = '.'
obj = MoniGoManiConfig(basedir)
return obj

View File

@@ -7,23 +7,17 @@ sys.path.append('..')
from user_data.mgm_tools.mgm_hurry.MoniGoManiLogger import MoniGoManiLogger # noqa: E402
# --- ↓
# --- ↓ Unit Testing "__init__"
# --- ↓
def test_initialisation_logger():
"""
↓ Unit Testing "__init__":
"""
logger = MoniGoManiLogger('.', print_output=True)
assert logger is not None
# --- ↑
# --- ↓
# --- ↓ Unit Testing "get_logger"
# --- ↓
def test_get_logger():
"""
↓ Unit Testing "get_logger"
"""
logger = MoniGoManiLogger('.', print_output=True).get_logger()
assert logger is not None
# --- ↑