Skip to content

Commit f349e3b

Browse files
committed
fix bug on merging captures
1 parent c06863d commit f349e3b

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

sigmf/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# SPDX-License-Identifier: LGPL-3.0-or-later
66

77
# version of this python module
8-
__version__ = "1.7.0"
8+
__version__ = "1.7.1"
99
# matching version of the SigMF specification
1010
__specification__ = "1.2.6"
1111

sigmf/sigmffile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,9 @@ def add_capture(self, start_index, metadata=None):
507507
new_capture[self.START_INDEX_KEY] = start_index
508508
# merge if capture exists
509509
merged = False
510-
for existing_capture in self._metadata[self.CAPTURE_KEY]:
510+
for idx, existing_capture in enumerate(self._metadata[self.CAPTURE_KEY]):
511511
if existing_capture[self.START_INDEX_KEY] == start_index:
512-
existing_capture = dict_merge(existing_capture, new_capture)
512+
self._metadata[self.CAPTURE_KEY][idx] = dict_merge(existing_capture, new_capture)
513513
merged = True
514514
if not merged:
515515
capture_list += [new_capture]

tests/test_sigmffile.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,31 @@ def test_add_capture():
366366
sigf.add_capture(start_index=0, metadata={})
367367

368368

369+
def test_add_capture_metadata_merge():
370+
'''test that adding capture with existing start_index properly merges metadata'''
371+
sigf = SigMFFile()
372+
373+
# add initial capture with some metadata
374+
initial_meta = {"core:frequency": 915e6, "core:sample_rate": 1e6}
375+
sigf.add_capture(start_index=0, metadata=initial_meta)
376+
377+
# add capture with same start_index but additional metadata
378+
additional_meta = {"core:datetime": "2026-03-17T10:00:00Z", "custom:gain": 30}
379+
sigf.add_capture(start_index=0, metadata=additional_meta)
380+
381+
# verify metadata was merged properly
382+
captures = sigf.get_captures()
383+
assert len(captures) == 1, "should have exactly one capture"
384+
385+
merged_capture = captures[0]
386+
# original metadata should be preserved
387+
assert merged_capture["core:frequency"] == 915e6
388+
assert merged_capture["core:sample_rate"] == 1e6
389+
# new metadata should be added
390+
assert merged_capture["core:datetime"] == "2026-03-17T10:00:00Z"
391+
assert merged_capture["custom:gain"] == 30
392+
393+
369394
def test_add_annotation():
370395
sigf = SigMFFile()
371396
sigf.add_capture(start_index=0)

0 commit comments

Comments
 (0)