Add tests for timerange modifications

This commit is contained in:
Matthias 2019-10-23 19:41:10 +02:00
parent bd4a23beeb
commit 5cdae17d19

View File

@ -1,10 +1,11 @@
# pragma pylint: disable=missing-docstring, C0103 # pragma pylint: disable=missing-docstring, C0103
import arrow
import pytest import pytest
from freqtrade.configuration import TimeRange from freqtrade.configuration import TimeRange
def test_parse_timerange_incorrect() -> None: def test_parse_timerange_incorrect():
assert TimeRange('date', None, 1274486400, 0) == TimeRange.parse_timerange('20100522-') assert TimeRange('date', None, 1274486400, 0) == TimeRange.parse_timerange('20100522-')
assert TimeRange(None, 'date', 0, 1274486400) == TimeRange.parse_timerange('-20100522') assert TimeRange(None, 'date', 0, 1274486400) == TimeRange.parse_timerange('-20100522')
@ -28,3 +29,37 @@ def test_parse_timerange_incorrect() -> None:
with pytest.raises(Exception, match=r'Incorrect syntax.*'): with pytest.raises(Exception, match=r'Incorrect syntax.*'):
TimeRange.parse_timerange('-') TimeRange.parse_timerange('-')
def test_subtract_start():
x = TimeRange('date', 'date', 1274486400, 1438214400)
x.subtract_start(300)
assert x.startts == 1274486400 - 300
# Do nothing if no startdate exists
x = TimeRange(None, 'date', 0, 1438214400)
x.subtract_start(300)
assert not x.startts
x = TimeRange('date', None, 1274486400, 0)
x.subtract_start(300)
assert x.startts == 1274486400 - 300
def test_adjust_start_if_necessary():
min_date = arrow.Arrow(2017, 11, 14, 21, 15, 00)
x = TimeRange('date', 'date', 1510694100, 1510780500)
# Adjust by 20 candles - min_date == startts
x.adjust_start_if_necessary(300, 20, min_date)
assert x.startts == 1510694100 + (20 * 300)
x = TimeRange('date', 'date', 1510700100, 1510780500)
# Do nothing, startupe is set and different min_date
x.adjust_start_if_necessary(300, 20, min_date)
assert x.startts == 1510694100 + (20 * 300)
x = TimeRange(None, 'date', 0, 1510780500)
# Adjust by 20 candles = 20 * 5m
x.adjust_start_if_necessary(300, 20, min_date)
assert x.startts == 1510694100 + (20 * 300)