28 lines
910 B
Python
28 lines
910 B
Python
import unittest
|
|
import time
|
|
from performance_monitor import PerformanceMonitor
|
|
|
|
class TestPerformanceMonitor(unittest.TestCase):
|
|
def setUp(self):
|
|
self.monitor = PerformanceMonitor()
|
|
|
|
def test_frame_time_collection(self):
|
|
# Simulate frames for 1.1 seconds to trigger FPS calculation
|
|
start = time.time()
|
|
while time.time() - start < 1.1:
|
|
self.monitor.start_frame()
|
|
time.sleep(0.01) # ~100 FPS
|
|
self.monitor.end_frame()
|
|
|
|
metrics = self.monitor.get_metrics()
|
|
self.assertAlmostEqual(metrics['last_frame_time_ms'], 10, delta=10)
|
|
self.assertGreater(metrics['fps'], 0)
|
|
|
|
def test_cpu_usage_collection(self):
|
|
metrics = self.monitor.get_metrics()
|
|
self.assertIn('cpu_percent', metrics)
|
|
self.assertIsInstance(metrics['cpu_percent'], float)
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|