fixed inconsistencies in returned objects: missing channels, is_clipped
Build Debian Packages / build (bookworm, debian12) (push) Failing after 8s
Build Debian Packages / build (trixie, debian13) (push) Canceled after 8s

This commit is contained in:
markusro committed 2026-10-01 21:10:49 +02:00
1 parent b6ca2cbba3
commit ddb3f00abb
5 files changed
+67 -5

No files matched your search

+28
View File
@@ -64,6 +64,7 @@ class TestADCResult(unittest.TestCase):
self.assertTrue(np.array_equal(adc.x, np.zeros(3, dtype="float32")))
self.assertTrue(np.array_equal(adc.y[0], np.zeros(3, dtype="int16")))
self.assertEqual(adc.index, [(0, 2)])
self.assertEqual(adc.nChannels, 2)
def test_add_sample_space(self):
"""Test adding sample space."""
@@ -90,6 +91,33 @@ class TestADCResult(unittest.TestCase):
self.assertEqual(sub_result.description, {"key": "value"})
self.assertEqual(sub_result.job_id, 42)
def test_get_result_by_index_copies_nChannels_and_is_clipped(self):
"""Test that get_result_by_index properly copies nChannels and is_clipped."""
adc = self.create_adc_result()
adc.index = [(0, 1), (1, 2)]
adc.set_nChannels(2)
adc.is_clipped = True
sub_result = adc.get_result_by_index(1)
self.assertEqual(sub_result.nChannels, 2)
self.assertEqual(sub_result.is_clipped, True)
def test_get_result_by_index_data_independence(self):
"""Test that get_result_by_index returns independent data (not shared views)."""
adc = self.create_adc_result()
adc.index = [(0, 1), (1, 2)]
original_x = adc.x.copy()
original_data = adc.y[0].copy()
sub_result = adc.get_result_by_index(1)
sub_result.y[0][0] = 9999
sub_result.x[0] = 999.0
self.assertEqual(sub_result.y[0][0], 9999)
self.assertTrue(np.array_equal(adc.y[0], original_data))
self.assertTrue(np.array_equal(adc.x, original_x))
def test_set_sampling_rate(self):
"""Test updating the sampling rate."""
adc = ADC_Result()
+29
View File
@@ -107,6 +107,35 @@ class TestAccumulation(unittest.TestCase):
self.assertEqual(sub_result.index, [(0, 1)])
self.assertEqual(sub_result.common_descriptions, {"key": "value"})
def test_get_accu_by_index_copies_is_clipped(self):
"""Test that get_accu_by_index properly copies is_clipped."""
adc = self.create_adc_result()
adc.index = [(0, 1), (1, 2)]
accu = Accumulation()
accu += adc
accu.is_clipped = True
sub_result = accu.get_accu_by_index(1)
self.assertEqual(sub_result.is_clipped, True)
def test_get_accu_by_index_data_independence(self):
"""Test that get_accu_by_index returns independent data (not shared views)."""
adc = self.create_adc_result()
adc.index = [(0, 1), (1, 2)]
accu = Accumulation()
accu += adc
original_y0 = accu.y[0].copy()
sub_result = accu.get_accu_by_index(1)
sub_result.y[0][0] = 9999
sub_result.x[0] = 999.0
self.assertEqual(sub_result.y[0][0], 9999)
self.assertTrue(np.array_equal(accu.y[0], original_y0))
# x array should also be independent
self.assertEqual(accu.x[1], 1.0)
def test_write_to_csv_without_error(self):
"""Test the functionality of writing to CSV."""
from io import StringIO