Skip to content

Commit 3dc5c7c

Browse files
committed
add test to verify issue & increment patch
1 parent 1348797 commit 3dc5c7c

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

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.1"
8+
__version__ = "1.7.2"
99
# matching version of the SigMF specification
1010
__specification__ = "1.2.6"
1111

tests/test_ncd.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import shutil
1111
import tempfile
1212
import unittest
13+
import warnings
1314
from pathlib import Path
1415

1516
import numpy as np
@@ -61,3 +62,38 @@ def test_load_ncd(self, subdir: str) -> None:
6162
Path.unlink(data_path)
6263
with self.assertRaises(SigMFFileError):
6364
_ = fromfile(meta_path)
65+
66+
def test_ncd_priority_over_conforming_dataset(self) -> None:
67+
"""test that NCD file specified in core:dataset is prioritized over .sigmf-data file"""
68+
base_name = "conflicting_dataset"
69+
meta_path = self.temp_dir / f"{base_name}.sigmf-meta"
70+
ncd_path = self.temp_dir / f"{base_name}.fleeb"
71+
conforming_path = self.temp_dir / f"{base_name}.sigmf-data"
72+
73+
# create two different datasets with distinct data for verification
74+
ncd_data = np.array([100, 200, 300, 400], dtype=np.float32)
75+
conforming_data = np.array([1, 2, 3, 4], dtype=np.float32)
76+
77+
# write both data files
78+
ncd_data.tofile(ncd_path)
79+
conforming_data.tofile(conforming_path)
80+
81+
# create metadata that references the ncd file
82+
ncd_metadata = copy.deepcopy(TEST_METADATA)
83+
ncd_metadata[SigMFFile.GLOBAL_KEY][SigMFFile.DATASET_KEY] = f"{base_name}.fleeb"
84+
ncd_metadata[SigMFFile.GLOBAL_KEY][SigMFFile.NUM_CHANNELS_KEY] = 1
85+
ncd_metadata[SigMFFile.GLOBAL_KEY][SigMFFile.DATATYPE_KEY] = "rf32_le"
86+
ncd_metadata[SigMFFile.GLOBAL_KEY].pop(SigMFFile.HASH_KEY, None)
87+
ncd_metadata[SigMFFile.ANNOTATION_KEY] = [{SigMFFile.LENGTH_INDEX_KEY: 4, SigMFFile.START_INDEX_KEY: 0}]
88+
89+
# write metadata file
90+
meta = SigMFFile(metadata=ncd_metadata)
91+
meta.tofile(meta_path, overwrite=True)
92+
93+
# verify warning is generated about conflicting datasets
94+
with self.assertWarns(UserWarning):
95+
loaded_meta = fromfile(meta_path)
96+
97+
# verify that the ncd data is loaded, not the conforming data
98+
loaded_data = loaded_meta.read_samples()
99+
self.assertTrue(np.array_equal(ncd_data, loaded_data), "NCD file should be prioritized over .sigmf-data")

0 commit comments

Comments
 (0)