Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate that global core:version is present. #55

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 1 addition & 4 deletions sigmf/sigmffile.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def __init__(self, metadata=None, data_file=None, global_info=None, skip_checksu
if metadata is None:
self._metadata = {self.GLOBAL_KEY:{}, self.CAPTURE_KEY:[], self.ANNOTATION_KEY:[]}
self._metadata[self.GLOBAL_KEY][self.NUM_CHANNELS_KEY] = 1
self._metadata[self.GLOBAL_KEY][self.VERSION_KEY] = "1.0.0"
elif isinstance(metadata, dict):
self._metadata = metadata
else:
Expand All @@ -183,8 +184,6 @@ def __init__(self, metadata=None, data_file=None, global_info=None, skip_checksu
if data_file is not None:
self.set_data_file(data_file, skip_checksum=skip_checksum, map_readonly=map_readonly)

self._metadata[self.GLOBAL_KEY][self.VERSION_KEY] = '1.0.0'

def __len__(self):
return self._memmap.shape[0]

Expand Down Expand Up @@ -724,8 +723,6 @@ def __init__(self, metafiles=None, metadata=None, skip_checksums=False):
if not self.skip_checksums:
self.verify_stream_hashes()

self._metadata[self.COLLECTION_KEY][self.VERSION_KEY] = '1.0.0'

def __len__(self):
'''
the length of a collection is the number of streams
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def test_sigmffile(test_data_file):
"""If pytest uses this signature, will return valid SigMF file."""
sigf = SigMFFile()
sigf.set_global_field("core:datatype", "rf32_le")
sigf.set_global_field("core:version", "1.0.0")
sigf.add_annotation(start_index=0, length=len(TEST_FLOAT32_DATA))
sigf.add_capture(start_index=0)
sigf.set_data_file(test_data_file.name)
Expand Down
1 change: 1 addition & 0 deletions tests/test_archivereader.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def test_access_data_without_untar(self):
global_info={
SigMFFile.DATATYPE_KEY: f"{complex_prefix}{key}_le",
SigMFFile.NUM_CHANNELS_KEY: num_channels,
SigMFFile.VERSION_KEY: "1.0.0",
},
)
temp_meta.tofile(temp_archive, toarchive=True)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ class FailingCases(unittest.TestCase):
def setUp(self):
self.metadata = dict(TEST_METADATA)

def test_no_version(self):
'''core:version must be present'''
del self.metadata[SigMFFile.GLOBAL_KEY][SigMFFile.VERSION_KEY]
with self.assertRaises(ValidationError):
SigMFFile(self.metadata).validate()

def test_extra_top_level_key(self):
'''no extra keys allowed on the top level'''
self.metadata['extra'] = 0
Expand Down
Loading