Tortoise/tests/test_strategy_a500.py
2026-06-23 10:57:20 +08:00

45 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""策略1中证 A500 收盘价图测试。"""
from datetime import date
from sidecar.models import KlineBar
from strategy.a500_close_chart import A500_START_DATE, ClosePoint, build_svg_line_chart, filter_close_points
def test_4_1_filter_a500_close_points() -> None:
"""
功能说明验证策略1会过滤成立日之前和空收盘价数据。
参数说明:无。
返回值说明:无返回值。
注意事项:用例编号 4-1。
"""
bars = [
KlineBar("sh000510", "day", date(2024, 9, 20), 1, 1, 1, 1, 1, 1, "fake"),
KlineBar("sh000510", "day", A500_START_DATE, 1, 1, 1, None, 1, 1, "fake"),
KlineBar("sh000510", "day", date(2024, 9, 24), 1, 1, 1, 1000.5, 1, 1, "fake"),
]
points = filter_close_points(bars, A500_START_DATE)
assert points == [ClosePoint(date(2024, 9, 24), 1000.5)]
def test_4_2_build_svg_line_chart() -> None:
"""
功能说明验证策略1可生成 SVG 折线图文本。
参数说明:无。
返回值说明:无返回值。
注意事项:用例编号 4-2。
"""
points = [
ClosePoint(date(2024, 9, 23), 1000.0),
ClosePoint(date(2024, 9, 24), 1010.0),
ClosePoint(date(2024, 9, 25), 990.0),
]
svg = build_svg_line_chart(points, "中证 A500 指数成立以来收盘价")
assert svg.startswith("<svg")
assert "中证 A500 指数成立以来收盘价" in svg
assert "2024-09-23" in svg
assert "<polyline" in svg