massive clenup
This commit is contained in:
115
tests/test_essential.py
Normal file
115
tests/test_essential.py
Normal file
@ -0,0 +1,115 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Essential Test Suite - Core functionality tests
|
||||
|
||||
This file contains the most important tests to verify core functionality:
|
||||
- Data loading and processing
|
||||
- Basic model operations
|
||||
- Trading signal generation
|
||||
- Critical utility functions
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import unittest
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
# Add project root to path
|
||||
project_root = Path(__file__).parent.parent
|
||||
sys.path.insert(0, str(project_root))
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class TestEssentialFunctionality(unittest.TestCase):
|
||||
"""Essential tests for core trading system functionality"""
|
||||
|
||||
def test_imports(self):
|
||||
"""Test that all critical modules can be imported"""
|
||||
try:
|
||||
from core.config import get_config
|
||||
from core.data_provider import DataProvider
|
||||
from utils.model_utils import robust_save, robust_load
|
||||
logger.info("✅ All critical imports successful")
|
||||
except ImportError as e:
|
||||
self.fail(f"Critical import failed: {e}")
|
||||
|
||||
def test_config_loading(self):
|
||||
"""Test configuration loading"""
|
||||
try:
|
||||
from core.config import get_config
|
||||
config = get_config()
|
||||
self.assertIsNotNone(config, "Config should be loaded")
|
||||
logger.info("✅ Configuration loading successful")
|
||||
except Exception as e:
|
||||
self.fail(f"Config loading failed: {e}")
|
||||
|
||||
def test_data_provider_initialization(self):
|
||||
"""Test DataProvider can be initialized"""
|
||||
try:
|
||||
from core.data_provider import DataProvider
|
||||
data_provider = DataProvider(['ETH/USDT'], ['1m'])
|
||||
self.assertIsNotNone(data_provider, "DataProvider should initialize")
|
||||
logger.info("✅ DataProvider initialization successful")
|
||||
except Exception as e:
|
||||
self.fail(f"DataProvider initialization failed: {e}")
|
||||
|
||||
def test_model_utils(self):
|
||||
"""Test model utility functions"""
|
||||
try:
|
||||
from utils.model_utils import get_model_info
|
||||
import tempfile
|
||||
|
||||
# Test with non-existent file
|
||||
info = get_model_info("non_existent_file.pt")
|
||||
self.assertFalse(info['exists'], "Should report file doesn't exist")
|
||||
|
||||
logger.info("✅ Model utils test successful")
|
||||
except Exception as e:
|
||||
self.fail(f"Model utils test failed: {e}")
|
||||
|
||||
def test_signal_generation_logic(self):
|
||||
"""Test basic signal generation logic"""
|
||||
import numpy as np
|
||||
|
||||
# Test signal distribution calculation
|
||||
predictions = np.array([0, 1, 2, 1, 0, 2, 1, 1, 2, 0]) # SELL, HOLD, BUY
|
||||
|
||||
buy_count = np.sum(predictions == 2)
|
||||
sell_count = np.sum(predictions == 0)
|
||||
hold_count = np.sum(predictions == 1)
|
||||
total = len(predictions)
|
||||
|
||||
distribution = {
|
||||
"BUY": buy_count / total,
|
||||
"SELL": sell_count / total,
|
||||
"HOLD": hold_count / total
|
||||
}
|
||||
|
||||
# Verify calculations
|
||||
self.assertAlmostEqual(distribution["BUY"], 0.3, places=1)
|
||||
self.assertAlmostEqual(distribution["SELL"], 0.3, places=1)
|
||||
self.assertAlmostEqual(distribution["HOLD"], 0.4, places=1)
|
||||
self.assertAlmostEqual(sum(distribution.values()), 1.0, places=1)
|
||||
|
||||
logger.info("✅ Signal generation logic test successful")
|
||||
|
||||
def run_essential_tests():
|
||||
"""Run essential tests only"""
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestEssentialFunctionality)
|
||||
runner = unittest.TextTestRunner(verbosity=2)
|
||||
result = runner.run(suite)
|
||||
return result.wasSuccessful()
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger.info("Running essential functionality tests...")
|
||||
|
||||
success = run_essential_tests()
|
||||
|
||||
if success:
|
||||
logger.info("✅ All essential tests passed!")
|
||||
sys.exit(0)
|
||||
else:
|
||||
logger.error("❌ Essential tests failed!")
|
||||
sys.exit(1)
|
Reference in New Issue
Block a user