-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_data_sources_validation.py
More file actions
118 lines (94 loc) · 3.15 KB
/
test_data_sources_validation.py
File metadata and controls
118 lines (94 loc) · 3.15 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
"""Basic validation test for data sources implementation."""
import sys
from decimal import Decimal
from datetime import datetime
def test_basic_imports():
"""Test that all modules can be imported without errors."""
try:
from personal_finance.data_sources import (
create_mock_service,
PricePoint,
HistoricalSeries,
)
print("✓ All imports successful")
return True
except ImportError as e:
print(f"✗ Import error: {e}")
return False
def test_mock_service_basic_functionality():
"""Test basic functionality with mock service."""
try:
from personal_finance.data_sources import create_mock_service
service = create_mock_service()
print("✓ Mock service created")
# Test current price
price = service.get_current_price("AAPL")
if price and price.symbol == "AAPL":
print(f"✓ Current price: {price.symbol} = ${price.price}")
else:
print("✗ Current price failed")
return False
# Test historical data
historical = service.fetch_historical("AAPL")
if (
historical
and historical.symbol == "AAPL"
and len(historical.data_points) > 0
):
print(
f"✓ Historical data: {len(historical.data_points)} data points"
)
else:
print("✗ Historical data failed")
return False
# Test bulk request
bulk_results = service.bulk_get_current(["AAPL", "MSFT"])
if bulk_results and "AAPL" in bulk_results and "MSFT" in bulk_results:
print(f"✓ Bulk request: {len(bulk_results)} symbols")
else:
print("✗ Bulk request failed")
return False
return True
except Exception as e:
print(f"✗ Mock service test failed: {e}")
return False
def test_data_types():
"""Test data type creation and validation."""
try:
from personal_finance.data_sources.types import PricePoint
# Test PricePoint creation
price_point = PricePoint(
symbol="TEST", price=Decimal("100.50"), timestamp=datetime.now()
)
if price_point.symbol == "TEST" and price_point.price == Decimal(
"100.50"
):
print("✓ PricePoint creation successful")
return True
else:
print("✗ PricePoint creation failed")
return False
except Exception as e:
print(f"✗ Data types test failed: {e}")
return False
def main():
"""Run all validation tests."""
print(
"Running basic validation tests for data sources implementation...\n"
)
tests = [
test_basic_imports,
test_data_types,
test_mock_service_basic_functionality,
]
passed = 0
for test in tests:
print(f"Running {test.__name__}...")
if test():
passed += 1
print()
print(f"Results: {passed}/{len(tests)} tests passed")
return passed == len(tests)
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)