Public Access
fix return-value/deprecated API bugs, accumulation lock leaks, code cleanup
- raise instead of silent None for unsupported operands and empty negation - validate before acquiring lock in Accumulation operators (no RLock leak) - Accumulation._copy_provenance helper, ADC_Result._copy_metadata for all result paths - shared _sandbox_stdout_redirect contextmanager for sandboxed scripts - TemperatureMonitor dead code removal (gtk helper, traceback, unused properties) - new unit tests incl. lock-freedom regression test - gitignore sphinx generated doc/_autosummary/ and doc/damaris/
This commit is contained in:
1 parent
91ade4376c
commit
f9d8de7697
26 files changed
+590
-236
No files matched your search
+38
-11
@@ -195,14 +195,14 @@ class TestADCResult(unittest.TestCase):
|
||||
np.testing.assert_array_equal(adc.y[i]+10, y[i] + 10, strict=True)
|
||||
adc += 10
|
||||
for i in range(adc.get_nChannels()):
|
||||
np.testing.assert_array_equal(adc.y[i], y[i] + 10, strict=True)
|
||||
np.testing.assert_array_equal(adc.y[i], (y[i] + 10).astype("float32"), strict=True)
|
||||
|
||||
# test float addition
|
||||
for i in range(adc.get_nChannels()):
|
||||
np.testing.assert_array_equal(adc.y[i] + 10., y[i] + 10., strict=True)
|
||||
np.testing.assert_array_equal(adc.y[i] + 10., (y[i] + 10 + 10.).astype("float32"), strict=True)
|
||||
adc += 10.
|
||||
for i in range(adc.get_nChannels()):
|
||||
np.testing.assert_array_equal(adc.y[i], y[i] + 10 + 10., strict=True)
|
||||
np.testing.assert_array_equal(adc.y[i], (y[i] + 10 + 10.).astype("float32"), strict=True)
|
||||
|
||||
def test_operator_sub_scalar(self):
|
||||
"""
|
||||
@@ -215,14 +215,14 @@ class TestADCResult(unittest.TestCase):
|
||||
np.testing.assert_array_equal(adc.y[i] - 10, y[i] - 10, strict=True)
|
||||
adc -= 10
|
||||
for i in range(adc.get_nChannels()):
|
||||
np.testing.assert_array_equal(adc.y[i], y[i] - 10, strict=True)
|
||||
np.testing.assert_array_equal(adc.y[i], (y[i] - 10).astype("float32"), strict=True)
|
||||
|
||||
# test float subtraction
|
||||
for i in range(adc.get_nChannels()):
|
||||
np.testing.assert_array_equal(adc.y[i] - 10., y[i] - 10., strict=True)
|
||||
np.testing.assert_array_equal(adc.y[i] - 10., (y[i] - 10 - 10.).astype("float32"), strict=True)
|
||||
adc -= 10.
|
||||
for i in range(adc.get_nChannels()):
|
||||
np.testing.assert_array_equal(adc.y[i], y[i] - 10 - 10., strict=True)
|
||||
np.testing.assert_array_equal(adc.y[i], (y[i] - 10 - 10.).astype("float32"), strict=True)
|
||||
|
||||
def test_operator_mul_scalar(self):
|
||||
"""
|
||||
@@ -236,14 +236,14 @@ class TestADCResult(unittest.TestCase):
|
||||
np.testing.assert_array_equal(adc.y[i] * 10, y[i] * 10, strict=True)
|
||||
adc *= 10
|
||||
for i in range(adc.get_nChannels()):
|
||||
np.testing.assert_array_equal(adc.y[i], y[i] * 10, strict=True)
|
||||
np.testing.assert_array_equal(adc.y[i], (y[i] * 10).astype("float32"), strict=True)
|
||||
|
||||
# test float multiplication
|
||||
for i in range(adc.get_nChannels()):
|
||||
np.testing.assert_array_equal(adc.y[i] * 10.0, y[i] * 10.0, strict=True)
|
||||
np.testing.assert_array_equal(adc.y[i] * 10.0, (y[i] * 10 * 10.0).astype("float32"), strict=True)
|
||||
adc *= 10.0
|
||||
for i in range(adc.get_nChannels()):
|
||||
np.testing.assert_array_equal(adc.y[i], y[i] * 10 * 10.0, strict=True)
|
||||
np.testing.assert_array_equal(adc.y[i], (y[i] * 10 * 10.0).astype("float32"), strict=True)
|
||||
|
||||
def test_operator_truediv_scalar(self):
|
||||
"""
|
||||
@@ -255,7 +255,7 @@ class TestADCResult(unittest.TestCase):
|
||||
np.testing.assert_array_equal(adc.y[i]/10, y[i] / 10, strict=True)
|
||||
adc /= 10
|
||||
for i in range(adc.get_nChannels()):
|
||||
np.testing.assert_array_equal(adc.y[i], y[i] / 10, strict=True)
|
||||
np.testing.assert_array_equal(adc.y[i], (y[i] / 10).astype("float32"), strict=True)
|
||||
|
||||
def test_operator_floordiv_scalar(self):
|
||||
"""
|
||||
@@ -267,10 +267,37 @@ class TestADCResult(unittest.TestCase):
|
||||
np.testing.assert_array_equal(adc.y[i]//10, y[i] // 10, strict=True)
|
||||
adc //= 10
|
||||
for i in range(adc.get_nChannels()):
|
||||
np.testing.assert_array_equal(adc.y[i], y[i] // 10, strict=True)
|
||||
np.testing.assert_array_equal(adc.y[i], (y[i] // 10).astype("float32"), strict=True)
|
||||
self.assertRaises(ValueError, adc.__floordiv__, 1.0)
|
||||
self.assertRaises(ValueError, adc.__rfloordiv__, 1.0)
|
||||
|
||||
def test_operators_keep_channel_metadata(self):
|
||||
"""operator results keep nChannels/is_clipped identical to the operand"""
|
||||
adc = self.create_adc_result()
|
||||
adc.is_clipped = True
|
||||
results = [adc + 1, adc - 1, adc * 2, adc ** 2, adc / 2., adc // 2,
|
||||
10 + adc, 10 - adc, 2 * adc, 100. / adc, 100 // adc, -adc]
|
||||
for r in results:
|
||||
self.assertEqual(r.get_nChannels(), adc.get_nChannels())
|
||||
self.assertEqual(r.is_clipped, adc.is_clipped)
|
||||
|
||||
def test_hdf_roundtrip_keeps_nchannels(self):
|
||||
"""read_from_hdf must restore the number of channels"""
|
||||
import tempfile
|
||||
import tables
|
||||
from damaris.data.ADC_Result import read_from_hdf
|
||||
|
||||
adc = self.create_adc_result()
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
path = os.path.join(tmpdir, "adc.h5")
|
||||
with tables.open_file(path, "w") as h5:
|
||||
adc.write_to_hdf(h5, h5.root, "adc", "test")
|
||||
with tables.open_file(path, "r") as h5:
|
||||
adc2 = read_from_hdf(h5.root.adc)
|
||||
self.assertIsNotNone(adc2)
|
||||
self.assertTrue(adc2.contains_data())
|
||||
self.assertEqual(adc2.get_nChannels(), adc.get_nChannels())
|
||||
|
||||
def test_operator_overload_adc_result_exception(self):
|
||||
"""
|
||||
Test the ValueError raised when ADC_Result is used as an operand in an arithmetic operation
|
||||
|
||||
Reference in new issue
Block a user