2017-11-18 07:45:01 +00:00
|
|
|
# pragma pylint: disable=missing-docstring,C0103
|
2017-12-11 07:56:03 +00:00
|
|
|
|
2018-02-04 07:33:54 +00:00
|
|
|
import datetime
|
|
|
|
from unittest.mock import MagicMock
|
2018-03-17 21:44:47 +00:00
|
|
|
|
2018-12-12 19:16:03 +00:00
|
|
|
from freqtrade.data.converter import parse_ticker_dataframe
|
2018-07-04 07:31:35 +00:00
|
|
|
from freqtrade.misc import (common_datearray, datesarray_to_datetimearray,
|
|
|
|
file_dump_json, format_ms_time, shorten_date)
|
2018-12-13 05:35:28 +00:00
|
|
|
from freqtrade.data.history import load_tickerdata_file
|
2018-07-09 16:27:36 +00:00
|
|
|
from freqtrade.strategy.default_strategy import DefaultStrategy
|
2017-11-20 18:37:25 +00:00
|
|
|
|
|
|
|
|
2018-02-04 07:33:54 +00:00
|
|
|
def test_shorten_date() -> None:
|
|
|
|
str_data = '1 day, 2 hours, 3 minutes, 4 seconds ago'
|
|
|
|
str_shorten_data = '1 d, 2 h, 3 min, 4 sec ago'
|
|
|
|
assert shorten_date(str_data) == str_shorten_data
|
2018-01-29 00:25:15 +00:00
|
|
|
|
|
|
|
|
2018-12-11 19:07:14 +00:00
|
|
|
def test_datesarray_to_datetimearray(ticker_history_list):
|
|
|
|
dataframes = parse_ticker_dataframe(ticker_history_list)
|
2018-01-29 00:25:15 +00:00
|
|
|
dates = datesarray_to_datetimearray(dataframes['date'])
|
|
|
|
|
|
|
|
assert isinstance(dates[0], datetime.datetime)
|
|
|
|
assert dates[0].year == 2017
|
|
|
|
assert dates[0].month == 11
|
|
|
|
assert dates[0].day == 26
|
|
|
|
assert dates[0].hour == 8
|
|
|
|
assert dates[0].minute == 50
|
|
|
|
|
|
|
|
date_len = len(dates)
|
2018-06-07 09:56:39 +00:00
|
|
|
assert date_len == 2
|
2018-02-04 07:33:54 +00:00
|
|
|
|
|
|
|
|
2018-05-02 20:49:55 +00:00
|
|
|
def test_common_datearray(default_conf) -> None:
|
2018-07-16 05:11:17 +00:00
|
|
|
strategy = DefaultStrategy(default_conf)
|
2018-03-24 09:21:59 +00:00
|
|
|
tick = load_tickerdata_file(None, 'UNITTEST/BTC', '1m')
|
2018-12-15 13:42:21 +00:00
|
|
|
tickerlist = {'UNITTEST/BTC': parse_ticker_dataframe(tick)}
|
2018-07-16 05:11:17 +00:00
|
|
|
dataframes = strategy.tickerdata_to_dataframe(tickerlist)
|
2018-03-05 07:05:44 +00:00
|
|
|
|
|
|
|
dates = common_datearray(dataframes)
|
|
|
|
|
2018-02-03 16:15:40 +00:00
|
|
|
assert dates.size == dataframes['UNITTEST/BTC']['date'].size
|
|
|
|
assert dates[0] == dataframes['UNITTEST/BTC']['date'][0]
|
|
|
|
assert dates[-1] == dataframes['UNITTEST/BTC']['date'][-1]
|
2018-03-05 07:05:44 +00:00
|
|
|
|
|
|
|
|
2018-02-04 09:21:16 +00:00
|
|
|
def test_file_dump_json(mocker) -> None:
|
2018-02-04 07:33:54 +00:00
|
|
|
file_open = mocker.patch('freqtrade.misc.open', MagicMock())
|
2018-12-28 09:01:16 +00:00
|
|
|
json_dump = mocker.patch('rapidjson.dump', MagicMock())
|
2018-02-04 07:33:54 +00:00
|
|
|
file_dump_json('somefile', [1, 2, 3])
|
|
|
|
assert file_open.call_count == 1
|
|
|
|
assert json_dump.call_count == 1
|
2018-03-30 21:30:23 +00:00
|
|
|
file_open = mocker.patch('freqtrade.misc.gzip.open', MagicMock())
|
2018-12-28 09:01:16 +00:00
|
|
|
json_dump = mocker.patch('rapidjson.dump', MagicMock())
|
2018-03-30 21:30:23 +00:00
|
|
|
file_dump_json('somefile', [1, 2, 3], True)
|
|
|
|
assert file_open.call_count == 1
|
|
|
|
assert json_dump.call_count == 1
|
2018-04-10 18:09:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_format_ms_time() -> None:
|
2018-04-12 17:32:14 +00:00
|
|
|
# Date 2018-04-10 18:02:01
|
|
|
|
date_in_epoch_ms = 1523383321000
|
|
|
|
date = format_ms_time(date_in_epoch_ms)
|
2018-04-10 18:09:14 +00:00
|
|
|
assert type(date) is str
|
2018-04-11 18:19:13 +00:00
|
|
|
res = datetime.datetime(2018, 4, 10, 18, 2, 1, tzinfo=datetime.timezone.utc)
|
|
|
|
assert date == res.astimezone(None).strftime('%Y-%m-%dT%H:%M:%S')
|
|
|
|
res = datetime.datetime(2017, 12, 13, 8, 2, 1, tzinfo=datetime.timezone.utc)
|
2018-04-12 17:32:14 +00:00
|
|
|
# Date 2017-12-13 08:02:01
|
|
|
|
date_in_epoch_ms = 1513152121000
|
|
|
|
assert format_ms_time(date_in_epoch_ms) == res.astimezone(None).strftime('%Y-%m-%dT%H:%M:%S')
|