更新脚本
This commit is contained in:
@@ -10,6 +10,8 @@ from cbpred.latest_predict import (
|
||||
OUTPUT_COLUMNS,
|
||||
REPO_ROOT,
|
||||
build_predictions,
|
||||
default_artifact,
|
||||
default_data_dir,
|
||||
default_output_dir,
|
||||
output_columns_for_timeframe,
|
||||
)
|
||||
@@ -40,6 +42,32 @@ class LatestPredictTests(unittest.TestCase):
|
||||
self.assertEqual(default_output_dir("8h"), REPO_ROOT / "predictions/latest_v1_8h")
|
||||
self.assertEqual(default_output_dir("1d"), REPO_ROOT / "predictions/latest_v1_1d")
|
||||
|
||||
def test_default_inputs_follow_timeframe(self):
|
||||
self.assertEqual(default_data_dir("8h"), REPO_ROOT / "data")
|
||||
self.assertEqual(default_data_dir("1d"), REPO_ROOT / "data_1d")
|
||||
self.assertEqual(default_artifact("8h"), REPO_ROOT / "artifacts/v1/model.joblib")
|
||||
self.assertEqual(default_artifact("1d"), REPO_ROOT / "artifacts_1d/best/model.joblib")
|
||||
|
||||
def test_batch_rejects_stale_prediction_data(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
(root / "item.csv").write_text("timestamp,quote,close\n0,1,1\n")
|
||||
(root / "manifest.json").write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"timeframe": "1d",
|
||||
"end_ms": 2 * 24 * 60 * 60 * 1000,
|
||||
"symbols": [{"symbol": "TRAIN/USDT:USDT", "path": "item.csv"}],
|
||||
}
|
||||
)
|
||||
)
|
||||
with patch(
|
||||
"cbpred.latest_predict.joblib.load",
|
||||
return_value={"timeframe": "1d", "asset_profiles": {"TRAIN/USDT:USDT": {}}},
|
||||
):
|
||||
with self.assertRaisesRegex(RuntimeError, "incomplete 1d data"):
|
||||
build_predictions(root, root / "model.joblib", root / "output")
|
||||
|
||||
def test_batch_skips_symbols_without_training_profiles(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user