Skip to content

Commit 5a05f7a

Browse files
author
Benjamin Moody
committed
test_physical_conversion: make tests more stringent.
- Test that Record.adc works when n_sig is not set. (Previously, this didn't work with expanded=True.) - Test that Record.adc handles NaN by mapping it to the correct invalid-sample value. (Previously, this didn't work with expanded=False and inplace=True.) Use multiple formats to test that this takes the format into account. Furthermore, the previous code relied on implementation-defined behavior to handle NaN, which normally results in a RuntimeWarning. Within the test suite, we set the numpy error handling mode to "raise", so such implementation-defined conversions actually result in a FloatingPointError.
1 parent a901163 commit 5a05f7a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

tests/test_record.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,19 +1053,20 @@ def test_physical_conversion(self):
10531053
adc_gain = [1.0, 1234.567, 765.4321]
10541054
baseline = [10, 20, -30]
10551055
d_signal = np.repeat(np.arange(-100, 100), 3).reshape(-1, 3)
1056+
d_signal[5:10, :] = [-32768, -2048, -128]
10561057
e_d_signal = list(d_signal.transpose())
1057-
fmt = ["16", "16", "16"]
1058+
fmt = ["16", "212", "80"]
10581059

10591060
# Test adding or subtracting a small offset (0.01 ADU) to check
10601061
# that we correctly round to the nearest integer
10611062
for offset in (0, -0.01, 0.01):
10621063
p_signal = (d_signal + offset - baseline) / adc_gain
1064+
p_signal[5:10, :] = np.nan
10631065
e_p_signal = list(p_signal.transpose())
10641066

10651067
# Test converting p_signal to d_signal
10661068

10671069
record = wfdb.Record(
1068-
n_sig=n_sig,
10691070
p_signal=p_signal.copy(),
10701071
adc_gain=adc_gain,
10711072
baseline=baseline,
@@ -1081,7 +1082,6 @@ def test_physical_conversion(self):
10811082
# Test converting e_p_signal to e_d_signal
10821083

10831084
record = wfdb.Record(
1084-
n_sig=n_sig,
10851085
e_p_signal=[s.copy() for s in e_p_signal],
10861086
adc_gain=adc_gain,
10871087
baseline=baseline,
@@ -1108,7 +1108,7 @@ def test_physical_conversion(self):
11081108
p_signal=p_signal,
11091109
adc_gain=adc_gain,
11101110
baseline=baseline,
1111-
fmt=["16", "16", "16"],
1111+
fmt=fmt,
11121112
write_dir=self.temp_path,
11131113
)
11141114
record = wfdb.rdrecord(

0 commit comments

Comments
 (0)