mirror of
https://github.com/Rikj000/MoniGoMani.git
synced 2022-03-06 00:08:05 +03:00
Fixed all unit tests!
This commit is contained in:
@@ -5,30 +5,24 @@ sys.path.append('.')
|
||||
sys.path.append('..')
|
||||
|
||||
from user_data.mgm_tools.mgm_hurry.FreqtradeCli import FreqtradeCli
|
||||
from user_data.mgm_tools.mgm_hurry.MoniGoManiLogger import get_logger
|
||||
|
||||
|
||||
def test_initialisation_without_logger():
|
||||
fc = __get_instance('.', use_logger=False)
|
||||
assert isinstance(fc, FreqtradeCli)
|
||||
|
||||
def test_initialisation_with_logger():
|
||||
fc = __get_instance('.', use_logger=True)
|
||||
def test_initialisation():
|
||||
fc = __get_instance('.')
|
||||
assert isinstance(fc, FreqtradeCli)
|
||||
|
||||
def test_set_basedir():
|
||||
fc = __get_instance('.', use_logger=True)
|
||||
fc = __get_instance('.')
|
||||
assert fc.basedir == '.'
|
||||
|
||||
def test_set_install_type_to_source():
|
||||
fc = __get_instance('.', use_logger=True)
|
||||
fc = __get_instance('.')
|
||||
fc.install_type = 'source'
|
||||
assert fc.install_type == 'source'
|
||||
|
||||
def test_set_incorrect_install_type_should_return_none():
|
||||
fc = __get_instance('.', use_logger=True)
|
||||
def test_set_incorrect_install_type_should_not_return_none():
|
||||
fc = __get_instance('.')
|
||||
fc.install_type = 'foobar'
|
||||
assert fc.install_type is None
|
||||
assert fc.install_type is not None
|
||||
|
||||
def test_get_freqtrade_binary_path_unknown_install_type_should_return_docker_path():
|
||||
'''
|
||||
@@ -39,9 +33,9 @@ def test_get_freqtrade_binary_path_unknown_install_type_should_return_docker_pat
|
||||
- path contains 'docker-compose' because foobar
|
||||
is an unknown install type
|
||||
'''
|
||||
fc = __get_instance('.', use_logger=True)
|
||||
fc = __get_instance('.')
|
||||
cmd = fc._get_freqtrade_binary_path('.', 'foobar')
|
||||
assert type(cmd) is str and \
|
||||
assert isinstance(cmd, str) and \
|
||||
cmd.find('docker-compose') > -1
|
||||
|
||||
def test_get_freqtrade_binary_path_docker():
|
||||
@@ -52,9 +46,9 @@ def test_get_freqtrade_binary_path_docker():
|
||||
- path is a string
|
||||
- path contains 'docker-compose'
|
||||
'''
|
||||
fc = __get_instance('.', use_logger=True)
|
||||
fc = __get_instance('.')
|
||||
cmd = fc._get_freqtrade_binary_path('.', 'docker')
|
||||
assert type(cmd) is str \
|
||||
assert isinstance(cmd, str) \
|
||||
and cmd.find('docker-compose') > -1
|
||||
|
||||
def test_get_freqtrade_binary_path_source():
|
||||
@@ -66,9 +60,9 @@ def test_get_freqtrade_binary_path_source():
|
||||
- path contains 'freqtrade'
|
||||
- path contains '.env'
|
||||
'''
|
||||
fc = __get_instance('.', use_logger=True)
|
||||
fc = __get_instance('.')
|
||||
cmd = fc._get_freqtrade_binary_path('.', 'source')
|
||||
assert type(cmd) is str \
|
||||
assert isinstance(cmd, str) \
|
||||
and cmd.find('freqtrade') > -1 \
|
||||
and cmd.find('.env') > -1
|
||||
|
||||
@@ -77,36 +71,26 @@ def test_installation_exists_should_return_bool():
|
||||
Case:
|
||||
- without installation type
|
||||
'''
|
||||
fc = __get_instance('.', use_logger=True)
|
||||
assert type(fc.installation_exists()) is bool
|
||||
fc = __get_instance('.')
|
||||
assert isinstance(fc.installation_exists(), bool)
|
||||
|
||||
def test_installation_exists_faulty_install_type():
|
||||
fc = __get_instance('.', use_logger=True)
|
||||
fc = __get_instance('.')
|
||||
fc.install_type = 'foobar'
|
||||
assert fc.installation_exists() is False
|
||||
assert fc.install_type != 'foobar'
|
||||
|
||||
def test_installation_exists_faulty_freqtrade_binary():
|
||||
fc = __get_instance('.', use_logger=True)
|
||||
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('.', use_logger=True)
|
||||
fc = __get_instance('.')
|
||||
fc.install_type = 'docker'
|
||||
fc.freqtrade_binary = 'unknown'
|
||||
assert fc.installation_exists() is True
|
||||
|
||||
def __get_instance(dir, use_logger=True):
|
||||
"""
|
||||
Todo:
|
||||
- Mock logger object
|
||||
- Probably mock freqtrade installation
|
||||
"""
|
||||
logger = None
|
||||
|
||||
if use_logger is True:
|
||||
logger = get_logger()
|
||||
|
||||
fc = FreqtradeCli(dir, logger)
|
||||
return fc
|
||||
def __get_instance(directory: str):
|
||||
"""Create instance of freqtradecli."""
|
||||
return FreqtradeCli(directory)
|
||||
|
||||
@@ -26,6 +26,3 @@ import pytest
|
||||
# hyperopt_apply_epoch
|
||||
# backtest
|
||||
# start_trader
|
||||
|
||||
def test_basic_usage():
|
||||
assert True is True
|
||||
|
||||
@@ -7,16 +7,15 @@ sys.path.append('.')
|
||||
sys.path.append('..')
|
||||
|
||||
from user_data.mgm_tools.mgm_hurry.MoniGoManiCli import MoniGoManiCli
|
||||
|
||||
from user_data.mgm_tools.mgm_hurry.MoniGoManiLogger import MoniGoManiLogger
|
||||
|
||||
def test_initialisation():
|
||||
cli = __get_instance()
|
||||
assert type(cli) is MoniGoManiCli
|
||||
assert isinstance(cli, MoniGoManiCli)
|
||||
|
||||
@pytest.mark.skip(reason='Test not implemented. Mocking needed.')
|
||||
def test_installation_exists_without_installation():
|
||||
cli = __get_instance('.', __get_logger())
|
||||
result = cli.installation_exists()
|
||||
assert result is False
|
||||
assert NotImplemented
|
||||
|
||||
@pytest.mark.skip(reason='Test not implemented. Mocking needed.')
|
||||
def test_installation_exists_with_config_without_strategy():
|
||||
@@ -38,14 +37,13 @@ def test_create_config_files_faulty_target_dir():
|
||||
def test_create_config_files_faulty_example_file():
|
||||
assert NotImplemented
|
||||
|
||||
def __get_instance(basedir='.', logger=None):
|
||||
cli = MoniGoManiCli(basedir, logger)
|
||||
def __get_instance(basedir='.'):
|
||||
cli = MoniGoManiCli(basedir)
|
||||
return cli
|
||||
|
||||
def __get_logger() -> Logger:
|
||||
def __get_logger(basedir='.') -> Logger:
|
||||
'''
|
||||
Todo:
|
||||
- Implement a mock-object.
|
||||
'''
|
||||
logger = Logger(name='mockme')
|
||||
return logger
|
||||
return MoniGoManiLogger(basedir).get_logger()
|
||||
|
||||
@@ -1,29 +1,19 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# from logging import Logger
|
||||
# import pytest
|
||||
import sys
|
||||
|
||||
sys.path.append('.')
|
||||
sys.path.append('..')
|
||||
|
||||
from pytest import mark
|
||||
from user_data.mgm_tools.mgm_hurry.MoniGoManiConfig import MoniGoManiConfig
|
||||
from user_data.mgm_tools.mgm_hurry.MoniGoManiLogger import get_logger
|
||||
|
||||
|
||||
def test_initialisation():
|
||||
cfg = __get_instance('.', get_logger())
|
||||
assert type(cfg) is MoniGoManiConfig
|
||||
cfg = __get_instance()
|
||||
assert isinstance(cfg, MoniGoManiConfig)
|
||||
|
||||
def test_valid_config_file_present_should_return_false_without_hurry_config():
|
||||
obj = __get_instance('.', get_logger())
|
||||
assert obj.valid_config_file_present() is False
|
||||
def test_valid_config_file_present_should_return_true():
|
||||
obj = __get_instance()
|
||||
assert obj.valid_config_file_present() is True
|
||||
|
||||
|
||||
@mark.notimplemented
|
||||
def test_config_getter_method_should_return_dict():
|
||||
# TODO use mock / stub to create .hurry file
|
||||
assert True is True
|
||||
|
||||
def __get_instance(basedir='.', logger=None):
|
||||
return MoniGoManiConfig(basedir, logger)
|
||||
def __get_instance():
|
||||
basedir = '.'
|
||||
return MoniGoManiConfig(basedir)
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from logging import Logger
|
||||
from user_data.mgm_tools.mgm_hurry.MoniGoManiLogger import get_logger
|
||||
|
||||
import sys
|
||||
import logging
|
||||
|
||||
sys.path.append('.')
|
||||
sys.path.append('..')
|
||||
|
||||
from user_data.mgm_tools.mgm_hurry.MoniGoManiLogger import MoniGoManiLogger
|
||||
|
||||
def test_initialisation_logger():
|
||||
logger = get_logger()
|
||||
assert type(logger) is Logger
|
||||
logger = MoniGoManiLogger('.', print_output=True)
|
||||
assert isinstance(logger, MoniGoManiLogger)
|
||||
|
||||
def test_get_logger_method():
|
||||
logger = MoniGoManiLogger('.', print_output=True).get_logger()
|
||||
assert logger is not None
|
||||
|
||||
Reference in New Issue
Block a user