Convert tests/datadir to path object - better mirroring an initialized configuration

This commit is contained in:
Matthias 2023-01-20 07:58:56 +00:00
parent a5d87859dc
commit 58d48e79da
3 changed files with 5 additions and 3 deletions

View File

@ -510,7 +510,7 @@ def get_default_conf(testdatadir):
"chat_id": "0", "chat_id": "0",
"notification_settings": {}, "notification_settings": {},
}, },
"datadir": str(testdatadir), "datadir": Path(testdatadir),
"initial_state": "running", "initial_state": "running",
"db_url": "sqlite://", "db_url": "sqlite://",
"user_data_dir": Path("user_data"), "user_data_dir": Path("user_data"),

View File

@ -58,6 +58,7 @@ def test_load_config_incorrect_stake_amount(default_conf) -> None:
def test_load_config_file(default_conf, mocker, caplog) -> None: def test_load_config_file(default_conf, mocker, caplog) -> None:
del default_conf['user_data_dir'] del default_conf['user_data_dir']
default_conf['datadir'] = str(default_conf['datadir'])
file_mock = mocker.patch('freqtrade.configuration.load_config.open', mocker.mock_open( file_mock = mocker.patch('freqtrade.configuration.load_config.open', mocker.mock_open(
read_data=json.dumps(default_conf) read_data=json.dumps(default_conf)
)) ))
@ -69,6 +70,7 @@ def test_load_config_file(default_conf, mocker, caplog) -> None:
def test_load_config_file_error(default_conf, mocker, caplog) -> None: def test_load_config_file_error(default_conf, mocker, caplog) -> None:
del default_conf['user_data_dir'] del default_conf['user_data_dir']
default_conf['datadir'] = str(default_conf['datadir'])
filedata = json.dumps(default_conf).replace( filedata = json.dumps(default_conf).replace(
'"stake_amount": 0.001,', '"stake_amount": .001,') '"stake_amount": 0.001,', '"stake_amount": .001,')
mocker.patch('freqtrade.configuration.load_config.open', mocker.mock_open(read_data=filedata)) mocker.patch('freqtrade.configuration.load_config.open', mocker.mock_open(read_data=filedata))
@ -80,6 +82,7 @@ def test_load_config_file_error(default_conf, mocker, caplog) -> None:
def test_load_config_file_error_range(default_conf, mocker, caplog) -> None: def test_load_config_file_error_range(default_conf, mocker, caplog) -> None:
del default_conf['user_data_dir'] del default_conf['user_data_dir']
default_conf['datadir'] = str(default_conf['datadir'])
filedata = json.dumps(default_conf).replace( filedata = json.dumps(default_conf).replace(
'"stake_amount": 0.001,', '"stake_amount": .001,') '"stake_amount": 0.001,', '"stake_amount": .001,')
mocker.patch.object(Path, "read_text", MagicMock(return_value=filedata)) mocker.patch.object(Path, "read_text", MagicMock(return_value=filedata))
@ -238,6 +241,7 @@ def test_print_config(default_conf, mocker, caplog) -> None:
conf1 = deepcopy(default_conf) conf1 = deepcopy(default_conf)
# Delete non-json elements from default_conf # Delete non-json elements from default_conf
del conf1['user_data_dir'] del conf1['user_data_dir']
conf1['datadir'] = str(conf1['datadir'])
config_files = [conf1] config_files = [conf1]
configsmock = MagicMock(side_effect=config_files) configsmock = MagicMock(side_effect=config_files)

View File

@ -45,7 +45,6 @@ def test_init_plotscript(default_conf, mocker, testdatadir):
default_conf['timerange'] = "20180110-20180112" default_conf['timerange'] = "20180110-20180112"
default_conf['trade_source'] = "file" default_conf['trade_source'] = "file"
default_conf['timeframe'] = "5m" default_conf['timeframe'] = "5m"
default_conf["datadir"] = testdatadir
default_conf['exportfilename'] = testdatadir / "backtest-result.json" default_conf['exportfilename'] = testdatadir / "backtest-result.json"
supported_markets = ["TRX/BTC", "ADA/BTC"] supported_markets = ["TRX/BTC", "ADA/BTC"]
ret = init_plotscript(default_conf, supported_markets) ret = init_plotscript(default_conf, supported_markets)
@ -394,7 +393,6 @@ def test_load_and_plot_trades(default_conf, mocker, caplog, testdatadir):
patch_exchange(mocker) patch_exchange(mocker)
default_conf['trade_source'] = 'file' default_conf['trade_source'] = 'file'
default_conf["datadir"] = testdatadir
default_conf['exportfilename'] = testdatadir / "backtest-result.json" default_conf['exportfilename'] = testdatadir / "backtest-result.json"
default_conf['indicators1'] = ["sma5", "ema10"] default_conf['indicators1'] = ["sma5", "ema10"]
default_conf['indicators2'] = ["macd"] default_conf['indicators2'] = ["macd"]