Skip to content

Commit 34cba14

Browse files
committed
test: improved line-annotation test-case
1 parent 9ea2491 commit 34cba14

File tree

1 file changed

+39
-25
lines changed

1 file changed

+39
-25
lines changed

tests/rpc/test_rpc_apiserver.py

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import asyncio
66
import logging
77
import time
8+
from copy import deepcopy
89
from datetime import UTC, datetime, timedelta
910
from pathlib import Path
1011
from unittest.mock import ANY, MagicMock, PropertyMock
@@ -1860,7 +1861,42 @@ def test_api_forceexit(botclient, mocker, ticker, fee, markets):
18601861
assert trade.is_open is False
18611862

18621863

1863-
def test_api_pair_candles(botclient, ohlcv_history):
1864+
def gen_annotation_params():
1865+
area_annotation = {
1866+
"type": "area",
1867+
"start": "2024-01-01 15:00:00",
1868+
"end": "2024-01-01 16:00:00",
1869+
"y_start": 94000.2,
1870+
"y_end": 98000,
1871+
"color": "",
1872+
"label": "some label",
1873+
}
1874+
line_annotation = {
1875+
"type": "line",
1876+
"start": "2024-01-01 15:00:00",
1877+
"end": "2024-01-01 16:00:00",
1878+
"y_start": 99000.2,
1879+
"y_end": 98000,
1880+
"color": "",
1881+
"label": "some label",
1882+
"width": 2,
1883+
"line_style": "dashed",
1884+
}
1885+
1886+
line_wrong = deepcopy(line_annotation)
1887+
line_wrong["line_style"] = "dashed2222"
1888+
return [
1889+
([area_annotation], [area_annotation]), # Only area
1890+
([line_annotation], [line_annotation]), # Only line
1891+
([area_annotation, line_annotation], [area_annotation, line_annotation]), # Both together
1892+
([], []), # Empty
1893+
([line_wrong], []), # Invalid line
1894+
([area_annotation, line_wrong], [area_annotation]), # Invalid line
1895+
]
1896+
1897+
1898+
@pytest.mark.parametrize("annotations,expected", gen_annotation_params())
1899+
def test_api_pair_candles(botclient, ohlcv_history, annotations, expected):
18641900
ftbot, client = botclient
18651901
timeframe = "5m"
18661902
amount = 3
@@ -1892,29 +1928,7 @@ def test_api_pair_candles(botclient, ohlcv_history):
18921928
ohlcv_history["exit_short"] = 0
18931929

18941930
ftbot.dataprovider._set_cached_df("XRP/BTC", timeframe, ohlcv_history, CandleType.SPOT)
1895-
fake_plot_annotations = [
1896-
{
1897-
"type": "area",
1898-
"start": "2024-01-01 15:00:00",
1899-
"end": "2024-01-01 16:00:00",
1900-
"y_start": 94000.2,
1901-
"y_end": 98000,
1902-
"color": "",
1903-
"label": "some label",
1904-
},
1905-
{
1906-
"type": "line",
1907-
"start": "2024-01-01 15:00:00",
1908-
"end": "2024-01-01 16:00:00",
1909-
"y_start": 99000.2,
1910-
"y_end": 98000,
1911-
"color": "",
1912-
"label": "some label",
1913-
"width": 2,
1914-
"line_style": "dashed",
1915-
},
1916-
]
1917-
plot_annotations_mock = MagicMock(return_value=fake_plot_annotations)
1931+
plot_annotations_mock = MagicMock(return_value=annotations)
19181932
ftbot.strategy.plot_annotations = plot_annotations_mock
19191933
for call in ("get", "post"):
19201934
plot_annotations_mock.reset_mock()
@@ -1947,7 +1961,7 @@ def test_api_pair_candles(botclient, ohlcv_history):
19471961
assert resp["data_start_ts"] == 1511686200000
19481962
assert resp["data_stop"] == "2017-11-26 09:00:00+00:00"
19491963
assert resp["data_stop_ts"] == 1511686800000
1950-
assert resp["annotations"] == fake_plot_annotations
1964+
assert resp["annotations"] == expected
19511965
assert plot_annotations_mock.call_count == 1
19521966
assert isinstance(resp["columns"], list)
19531967
base_cols = {

0 commit comments

Comments
 (0)