diff --git a/freqtrade/tests/optimize/test_optimize.py b/freqtrade/tests/optimize/test_optimize.py index a8d118176..40fe07c87 100644 --- a/freqtrade/tests/optimize/test_optimize.py +++ b/freqtrade/tests/optimize/test_optimize.py @@ -3,11 +3,12 @@ import os import json import logging +import uuid from shutil import copyfile from freqtrade import exchange, optimize from freqtrade.exchange import Bittrex from freqtrade.optimize.__init__ import make_testdata_path, download_pairs,\ - download_backtesting_testdata, load_tickerdata_file, trim_tickerlist + download_backtesting_testdata, load_tickerdata_file, trim_tickerlist, file_dump_json # Change this if modifying BTC_UNITEST testdatafile _BTC_UNITTEST_LENGTH = 13681 @@ -258,3 +259,28 @@ def test_trim_tickerlist(): assert ticker_list[0] is not ticker[0] # The first element should be different assert ticker_list[5] is ticker[0] # The list starts at the index 5 assert ticker_list[9] is ticker[-1] # The list ends at the index 9 (5 elements) + + +def test_file_dump_json(): + + file = 'freqtrade/tests/testdata/test_{id}.json'.format(id=str(uuid.uuid4())) + data = { 'bar': 'foo'} + + # check the file we will create does not exist + assert os.path.isfile(file) is False + + # Create the Json file + file_dump_json(file, data) + + # Check the file was create + assert os.path.isfile(file) is True + + # Open the Json file created and test the data is in it + with open(file) as data_file: + json_from_file = json.load(data_file) + + assert 'bar' in json_from_file + assert json_from_file['bar'] == 'foo' + + # Remove the file + _clean_test_file(file)