|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import unittest |
| 4 | + |
| 5 | +import pandas as pd |
| 6 | + |
| 7 | +from quant_platform_kit.common.history import normalize_history_frame |
| 8 | + |
| 9 | + |
| 10 | +class CommonHistoryTests(unittest.TestCase): |
| 11 | + def test_normalize_history_frame_accepts_dataframe_with_close_column(self) -> None: |
| 12 | + frame = pd.DataFrame([{"close": 1.0}, {"close": 2.0}]) |
| 13 | + |
| 14 | + normalized = normalize_history_frame(frame, label="benchmark_history") |
| 15 | + |
| 16 | + self.assertEqual(list(normalized["close"]), [1.0, 2.0]) |
| 17 | + |
| 18 | + def test_normalize_history_frame_accepts_dataframe_with_close_case_variant(self) -> None: |
| 19 | + frame = pd.DataFrame([{"Close": 1.0}, {"Close": 2.0}]) |
| 20 | + |
| 21 | + normalized = normalize_history_frame(frame, label="benchmark_history") |
| 22 | + |
| 23 | + self.assertEqual(list(normalized["close"]), [1.0, 2.0]) |
| 24 | + |
| 25 | + def test_normalize_history_frame_accepts_series(self) -> None: |
| 26 | + series = pd.Series([1.0, 2.0, 3.0], name="close") |
| 27 | + |
| 28 | + normalized = normalize_history_frame(series, label="benchmark_history") |
| 29 | + |
| 30 | + self.assertEqual(list(normalized["close"]), [1.0, 2.0, 3.0]) |
| 31 | + |
| 32 | + def test_normalize_history_frame_accepts_single_column_iterable(self) -> None: |
| 33 | + history = [1.0, 2.0, 3.0] |
| 34 | + |
| 35 | + normalized = normalize_history_frame(history, label="benchmark_history") |
| 36 | + |
| 37 | + self.assertEqual(list(normalized["close"]), [1.0, 2.0, 3.0]) |
| 38 | + |
| 39 | + def test_normalize_history_frame_rejects_missing_close_data(self) -> None: |
| 40 | + with self.assertRaisesRegex(ValueError, "benchmark_history must include a close column"): |
| 41 | + normalize_history_frame([{"open": 1.0, "high": 1.0}], label="benchmark_history") |
| 42 | + |
| 43 | + |
| 44 | +if __name__ == "__main__": |
| 45 | + unittest.main() |
0 commit comments