giga fix
This commit is contained in:
@ -2,6 +2,8 @@ from __future__ import annotations
|
||||
|
||||
import numpy as np
|
||||
import unittest
|
||||
import warnings
|
||||
from unittest.mock import patch
|
||||
|
||||
from rfg_adc_plotter.processing.fft import compute_fft_mag_row
|
||||
from rfg_adc_plotter.state.ring_buffer import RingBuffer
|
||||
@ -116,6 +118,45 @@ class RingBufferTests(unittest.TestCase):
|
||||
self.assertEqual(ring.width, 0)
|
||||
self.assertEqual(ring.head, 0)
|
||||
|
||||
def test_ring_buffer_push_ignores_all_nan_fft_without_runtime_warning(self):
|
||||
ring = RingBuffer(max_sweeps=2)
|
||||
freqs = np.linspace(3.3, 14.3, 64, dtype=np.float64)
|
||||
ring.push(np.linspace(0.0, 1.0, 64, dtype=np.float32), freqs)
|
||||
fft_before = ring.last_fft_db.copy()
|
||||
y_min_before = ring.y_min_fft
|
||||
y_max_before = ring.y_max_fft
|
||||
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error", RuntimeWarning)
|
||||
with patch(
|
||||
"rfg_adc_plotter.state.ring_buffer.compute_fft_mag_row",
|
||||
return_value=np.full((ring.fft_bins,), np.nan, dtype=np.float32),
|
||||
):
|
||||
ring.push(np.linspace(1.0, 2.0, 64, dtype=np.float32), freqs)
|
||||
|
||||
self.assertFalse(ring.last_push_fft_valid)
|
||||
self.assertTrue(np.allclose(ring.last_fft_db, fft_before))
|
||||
self.assertEqual(ring.y_min_fft, y_min_before)
|
||||
self.assertEqual(ring.y_max_fft, y_max_before)
|
||||
|
||||
def test_ring_buffer_set_fft_mode_ignores_all_nan_rebuild_without_runtime_warning(self):
|
||||
ring = RingBuffer(max_sweeps=2)
|
||||
freqs = np.linspace(3.3, 14.3, 64, dtype=np.float64)
|
||||
ring.push(np.linspace(0.0, 1.0, 64, dtype=np.float32), freqs)
|
||||
fft_before = ring.last_fft_db.copy()
|
||||
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error", RuntimeWarning)
|
||||
with patch(
|
||||
"rfg_adc_plotter.state.ring_buffer.compute_fft_mag_row",
|
||||
return_value=np.full((ring.fft_bins,), np.nan, dtype=np.float32),
|
||||
):
|
||||
ring.set_fft_mode("direct")
|
||||
|
||||
self.assertFalse(ring.last_push_fft_valid)
|
||||
self.assertTrue(np.allclose(ring.last_fft_db, fft_before))
|
||||
self.assertEqual(ring.fft_mode, "direct")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user