更新脚本

This commit is contained in:
2026-09-17 22:02:51 +08:00
parent 9e1b5e251a
commit 79b02d1c7d
8 changed files with 213 additions and 55 deletions

View File

@@ -1,9 +1,11 @@
from __future__ import annotations
import json
import subprocess
import tempfile
import unittest
from pathlib import Path
from unittest.mock import patch
import numpy as np
import pandas as pd
@@ -21,6 +23,8 @@ from cbpred.pipeline import (
_window_feature_names,
_window_features,
run_training,
Symbol,
run_banbot_download,
)
@@ -40,6 +44,29 @@ def make_hour_rows(start_ms: int, hours: int, phase: float = 0.0):
class PipelineTests(unittest.TestCase):
def test_download_skips_invalid_current_symbol_and_retries_chunk(self):
valid = Symbol(1, "binance", "linear", "BTC/USDT:USDT", 1, 0)
stale = Symbol(2, "binance", "linear", "SXP/USDT:USDT", 1, 0)
calls = []
def run(command, **kwargs):
calls.append(command)
if len(calls) == 1:
raise subprocess.CalledProcessError(
1, command, stderr="Error: [InvalidSymbol] symbol SXP/USDT:USDT not found\n"
)
with patch("cbpred.pipeline.subprocess.run", side_effect=run):
downloaded, unavailable = run_banbot_download(
[valid, stale], Path("/banbot"), Path("/banbot/config.yml"), 1, 2
)
self.assertEqual(downloaded, [valid])
self.assertEqual(unavailable, [stale])
self.assertEqual(calls[0][calls[0].index("--pairs") + 1], "BTC/USDT:USDT,SXP/USDT:USDT")
self.assertEqual(calls[1][calls[1].index("--pairs") + 1], "BTC/USDT:USDT")
self.assertIn("market_type: linear", calls[0][calls[0].index("--config-data") + 1])
def test_aggregate_8h_drops_incomplete_buckets(self):
rows = make_hour_rows(0, 17)
frame = aggregate_8h(rows)