mBA-Terminal / tests /test_interactive_chart.py
algorembrant's picture
Upload 29 files
c99df4c verified
import sys
import os
import numpy as np
import pandas as pd
from PyQt6.QtWidgets import QApplication
from PyQt6.QtCore import QTimer
import pyqtgraph as pg
# Add project root to path
sys.path.append(os.getcwd())
from src.ui.chart_widget import ChartWidget
def verify_chart_render():
app = QApplication(sys.argv)
widget = ChartWidget()
widget.resize(800, 600)
widget.show()
print("Widget shown. Generating dummy data...")
# 1. Simulate Tick Data
now = pd.Timestamp.now()
dates = pd.date_range(start=now, periods=100, freq='1s')
bids = np.linspace(100, 105, 100) + np.random.normal(0, 0.1, 100)
asks = bids + 0.2
df = pd.DataFrame({
'datetime': dates,
'bid': bids,
'ask': asks
})
# Update ticks
widget.update_ticks(df)
print("Ticks updated.")
# Check if curves have data
x, y = widget.bid_curve.getData()
if x is not None and len(x) == 100:
print("PASS: Bid curve has data.")
else:
print(f"FAIL: Bid curve data mismatch. Len: {len(x) if x is not None else 0}")
# 2. Simulate Levels
# timestamps for 10 min
level_times = [dates[i].timestamp() for i in range(0, 100, 10)]
level_vah = np.linspace(101, 104, 10)
level_val = np.linspace(99, 102, 10)
level_poc = np.linspace(100, 103, 10)
widget.update_levels(level_times, level_vah, level_val, level_poc)
print("Levels updated.")
x_vah, y_vah = widget.curve_vah.getData()
if x_vah is not None and len(x_vah) == 10:
print("PASS: VAH curve has data.")
else:
print(f"FAIL: VAH curve data mismatch. Len: {len(x_vah) if x_vah is not None else 0}")
# Set a timer to close the app automatically after a few seconds if running in automation
# QTimer.singleShot(2000, app.quit)
# For now, just quit immediately to verify logic
app.quit()
print("Test finished.")
if __name__ == "__main__":
verify_chart_render()