From 71239853258803e329bb5804a49af48036840647 Mon Sep 17 00:00:00 2001 From: Matthias Voppichler Date: Tue, 10 Apr 2018 20:09:14 +0200 Subject: [PATCH 1/3] Add test for format_ms_time --- freqtrade/tests/test_misc.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/freqtrade/tests/test_misc.py b/freqtrade/tests/test_misc.py index 91c34b620..dee683060 100644 --- a/freqtrade/tests/test_misc.py +++ b/freqtrade/tests/test_misc.py @@ -9,7 +9,7 @@ from unittest.mock import MagicMock from freqtrade.analyze import Analyze from freqtrade.misc import (shorten_date, datesarray_to_datetimearray, - common_datearray, file_dump_json) + common_datearray, file_dump_json, format_ms_time) from freqtrade.optimize.__init__ import load_tickerdata_file @@ -76,3 +76,14 @@ def test_file_dump_json(mocker) -> None: file_dump_json('somefile', [1, 2, 3], True) assert file_open.call_count == 1 assert json_dump.call_count == 1 + + +def test_format_ms_time() -> None: + """ + test format_ms_time() + :return: None + """ + date = format_ms_time(1523383321000) + assert type(date) is str + assert date == '2018-04-10T20:02:01' + assert format_ms_time(1513152121000) == '2017-12-13T09:02:01' From d03f58417b03c2196140b10a2415335ccaa3b746 Mon Sep 17 00:00:00 2001 From: Matthias Voppichler Date: Wed, 11 Apr 2018 20:19:13 +0200 Subject: [PATCH 2/3] Fix timezone dependency in test --- freqtrade/tests/test_misc.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/freqtrade/tests/test_misc.py b/freqtrade/tests/test_misc.py index dee683060..efea5d2f3 100644 --- a/freqtrade/tests/test_misc.py +++ b/freqtrade/tests/test_misc.py @@ -85,5 +85,7 @@ def test_format_ms_time() -> None: """ date = format_ms_time(1523383321000) assert type(date) is str - assert date == '2018-04-10T20:02:01' - assert format_ms_time(1513152121000) == '2017-12-13T09:02:01' + 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) + assert format_ms_time(1513152121000) == res.astimezone(None).strftime('%Y-%m-%dT%H:%M:%S') From 37dee02e1c62829c2e39746d406836350b74b44a Mon Sep 17 00:00:00 2001 From: Matthias Voppichler Date: Thu, 12 Apr 2018 19:32:14 +0200 Subject: [PATCH 3/3] Add comment and extract magic number to variable --- freqtrade/tests/test_misc.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/freqtrade/tests/test_misc.py b/freqtrade/tests/test_misc.py index efea5d2f3..fece16d98 100644 --- a/freqtrade/tests/test_misc.py +++ b/freqtrade/tests/test_misc.py @@ -83,9 +83,13 @@ def test_format_ms_time() -> None: test format_ms_time() :return: None """ - date = format_ms_time(1523383321000) + # Date 2018-04-10 18:02:01 + date_in_epoch_ms = 1523383321000 + date = format_ms_time(date_in_epoch_ms) assert type(date) is str 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) - assert format_ms_time(1513152121000) == res.astimezone(None).strftime('%Y-%m-%dT%H:%M:%S') + # 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')