-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_basic_functionality.py
More file actions
184 lines (157 loc) Β· 5.37 KB
/
test_basic_functionality.py
File metadata and controls
184 lines (157 loc) Β· 5.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env python3
"""
Basic functionality test for MLES platform.
This script tests the core components without complex imports.
"""
import sys
import os
import pandas as pd
import numpy as np
from pathlib import Path
# Add src to path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
def test_config():
"""Test configuration loading."""
print("π§ Testing configuration...")
try:
from config import get_config
config = get_config()
print(f"β
Configuration loaded: {config.environment}")
return True
except Exception as e:
print(f"β Configuration failed: {e}")
return False
def test_data_loader():
"""Test data loader functionality."""
print("π Testing data loader...")
try:
from preprocessing.data_loader import DataLoader
loader = DataLoader()
# Generate test data
data = {
'feature_1': np.random.randn(100),
'feature_2': np.random.randn(100),
'target': np.random.randint(0, 2, 100)
}
df = pd.DataFrame(data)
# Test data splitting
splits = loader.split_data(df, target_column='target', test_size=0.2)
print(f"β
Data splitting works: {len(splits['train'])} train, {len(splits['test'])} test")
return True
except Exception as e:
print(f"β Data loader failed: {e}")
return False
def test_data_validator():
"""Test data validator functionality."""
print("π Testing data validator...")
try:
from preprocessing.data_validator import DataValidator
validator = DataValidator()
# Generate test data
data = {
'feature_1': np.random.randn(100),
'feature_2': np.random.randn(100),
'target': np.random.randint(0, 2, 100)
}
df = pd.DataFrame(data)
# Test validation
result = validator.validate_data(df)
print(f"β
Data validation works: {result}")
return True
except Exception as e:
print(f"β Data validator failed: {e}")
return False
def test_feature_engineering():
"""Test feature engineering functionality."""
print("βοΈ Testing feature engineering...")
try:
from preprocessing.feature_engineering import FeatureEngineer
engineer = FeatureEngineer()
# Generate test data
data = {
'feature_1': np.random.randn(100),
'feature_2': np.random.randn(100),
'target': np.random.randint(0, 2, 100)
}
df = pd.DataFrame(data)
# Test feature engineering
processed_df = engineer.engineer_features(df)
print(f"β
Feature engineering works: {processed_df.shape}")
return True
except Exception as e:
print(f"β Feature engineering failed: {e}")
return False
def test_sklearn_model():
"""Test sklearn model functionality."""
print("π― Testing sklearn model...")
try:
from models.sklearn_models import SklearnModel
model = SklearnModel()
# Generate test data
X = np.random.randn(100, 3)
y = np.random.randint(0, 2, 100)
# Test training
model.train(X, y)
print("β
Model training works")
# Test prediction
predictions = model.predict(X[:10])
print(f"β
Model prediction works: {len(predictions)} predictions")
return True
except Exception as e:
print(f"β Sklearn model failed: {e}")
return False
def test_metrics():
"""Test metrics functionality."""
print("π Testing metrics...")
try:
from monitoring.metrics import MetricsCollector
metrics = MetricsCollector()
# Generate test data
y_true = np.random.randint(0, 2, 100)
y_pred = np.random.randint(0, 2, 100)
# Test metrics calculation
results = metrics.calculate_metrics(y_true, y_pred)
print(f"β
Metrics calculation works: {list(results.keys())}")
return True
except Exception as e:
print(f"β Metrics failed: {e}")
return False
def main():
"""Run all tests."""
print("π Starting MLES Basic Functionality Tests")
print("=" * 50)
tests = [
test_config,
test_data_loader,
test_data_validator,
test_feature_engineering,
test_sklearn_model,
test_metrics
]
results = []
for test in tests:
try:
result = test()
results.append(result)
except Exception as e:
print(f"β Test {test.__name__} crashed: {e}")
results.append(False)
print()
# Summary
print("=" * 50)
print("π Test Results Summary:")
passed = sum(results)
total = len(results)
for i, (test, result) in enumerate(zip(tests, results)):
status = "β
PASS" if result else "β FAIL"
print(f" {i+1}. {test.__name__}: {status}")
print(f"\nπ― Overall: {passed}/{total} tests passed")
if passed == total:
print("π All tests passed! Basic functionality is working.")
return True
else:
print("β οΈ Some tests failed. Check the implementation.")
return False
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)