Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions test/test_mdf4.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,35 @@ def test_channel_with_boolean_array(self) -> None:

self.assertTrue((record == signal.samples).all())

def test_vlsd_channel_after_structure_composition(self) -> None:
"""A VLSD channel that sits after a structure (composed) channel in the
same group must still find its signal data.

``Group.signal_data`` is indexed by channel index, so an extra entry
pushed for a composed channel shifts every following channel's VLSD
block info and makes the payload unreadable.
"""
count = 20
timestamps = np.arange(count, dtype="<f8")

record = np.rec.fromarrays(
[np.arange(count, dtype="<u2"), np.arange(count, dtype="<u1") % 5],
dtype=np.dtype([("a", "<u2"), ("b", "<u1")]),
)
structure = Signal(record, timestamps=timestamps, name="Structure")
texts = np.array([("x" * (i % 5 + 1)).encode("latin-1") for i in range(count)], dtype="S8")
text = Signal(texts, timestamps=timestamps, name="Text", encoding="latin-1")

path = Path(TestMDF4.tempdir.name) / "vlsd_after_structure.mf4"
with MDF(version="4.10") as mdf:
mdf.append([structure, text])
mdf.save(path, overwrite=True)

with MDF(path) as mdf:
group = mdf.groups[0]
self.assertEqual(len(group.signal_data), len(group.channels))
self.assertTrue(np.array_equal(mdf.get("Text", group=0).samples, texts))


if __name__ == "__main__":
unittest.main()
Loading