From e914959fcf362b94b3c6a0097fa2732f06a40845 Mon Sep 17 00:00:00 2001 From: JKB Date: Tue, 26 Nov 2024 14:07:19 +0100 Subject: [PATCH 01/11] bugfix get_dataset_filename_from_metadata --- sigmf/sigmffile.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sigmf/sigmffile.py b/sigmf/sigmffile.py index 1b6f28c..f937016 100644 --- a/sigmf/sigmffile.py +++ b/sigmf/sigmffile.py @@ -932,12 +932,15 @@ def get_dataset_filename_from_metadata(meta_fn, metadata=None): Parse provided metadata and return the expected data filename. In the case of a metadata only distribution, or if the file does not exist, this will return 'None'. The priority for conflicting: - 1. The file named .sigmf-meta if it exists + 1. The file named .sigmf-data if it exists 2. The file in the `core:dataset` field (Non-Compliant Dataset) if it exists 3. None (may be a metadata only distribution) """ compliant_data_fn = get_sigmf_filenames(meta_fn)["data_fn"] noncompliant_data_fn = metadata["global"].get("core:dataset", None) + dir_path = path.split(meta_fn)[0] + if not dir_path: + dir_path = "." # sets the correct path in the case meta_fn is only a filename if path.isfile(compliant_data_fn): if noncompliant_data_fn: @@ -948,13 +951,14 @@ def get_dataset_filename_from_metadata(meta_fn, metadata=None): return compliant_data_fn elif noncompliant_data_fn: - if path.isfile(noncompliant_data_fn): + noncompliant_data_file_path = f"{dir_path}/{noncompliant_data_fn}" + if path.isfile(noncompliant_data_file_path): if metadata["global"].get("core:metadata_only", False): warnings.warn( - 'Schema defines "core:dataset" but "core:meatadata_only" ' + 'Schema defines "core:dataset" but "core:metadata_only" ' f"also exists; using `{noncompliant_data_fn}`" ) - return noncompliant_data_fn + return noncompliant_data_file_path else: warnings.warn( f"Non-Compliant Dataset `{noncompliant_data_fn}` is specified " 'in "core:dataset" but does not exist!' From 9989efa8d0213568cafe19423493e9993c23f978 Mon Sep 17 00:00:00 2001 From: JKB Date: Tue, 26 Nov 2024 15:11:12 +0100 Subject: [PATCH 02/11] unit test --- tests/test_load_ncd.py | 62 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 tests/test_load_ncd.py diff --git a/tests/test_load_ncd.py b/tests/test_load_ncd.py new file mode 100644 index 0000000..7786ce8 --- /dev/null +++ b/tests/test_load_ncd.py @@ -0,0 +1,62 @@ +# Copyright: Multiple Authors +# +# This file is part of sigmf-python. https://github.com/sigmf/sigmf-python +# +# SPDX-License-Identifier: LGPL-3.0-or-later + +"""Tests for loading non-conforming datasets""" + +import os +import numpy as np +import pytest +from sigmf.sigmffile import SigMFFile, fromfile + + +@pytest.mark.parametrize( + ["file_path"], + [ + ["b1.bin"], + ["./b2.bin"], + ["test_subdir/b3.bin"], # fails in the 1.2.3 version + ["./test_subdir/b4.bin"], # fails in the 1.2.3 version + ], +) +def test_load_ncd(file_path: str) -> None: + dir_path, file_name = os.path.split(file_path) + file_name_base, file_name_ext = os.path.splitext(file_name) + if not dir_path: + dir_path = "." # sets the correct path in the case file is only a filename + meta_file_path = f"{dir_path}/{file_name_base}.sigmf-meta" + + # create dir + try: + os.makedirs(dir_path) + except FileExistsError: + pass + + # create dataset + np.arange(10, dtype=np.int16).tofile(file_path) + + # create metadata file + metadata = { + SigMFFile.GLOBAL_KEY: { + SigMFFile.DATATYPE_KEY: "ri16_le", + SigMFFile.DATASET_KEY: file_name, + }, + SigMFFile.CAPTURE_KEY: [ + { + SigMFFile.START_INDEX_KEY: 0, + } + ], + SigMFFile.ANNOTATION_KEY: [], + } + meta_file = SigMFFile(metadata=metadata, data_file=file_path) + meta_file.tofile(meta_file_path) + + # load dataset + data = fromfile(meta_file_path) + + assert np.array_equal( + np.arange(10, dtype=np.int16), + data.read_samples(autoscale=False), + ) From b4645e14564ee418870e63e74d5e679c0531c9d6 Mon Sep 17 00:00:00 2001 From: JKB Date: Wed, 11 Dec 2024 14:23:42 +0100 Subject: [PATCH 03/11] unit test clean-up --- tests/test_load_ncd.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/tests/test_load_ncd.py b/tests/test_load_ncd.py index 7786ce8..91188c4 100644 --- a/tests/test_load_ncd.py +++ b/tests/test_load_ncd.py @@ -6,6 +6,7 @@ """Tests for loading non-conforming datasets""" +from typing import cast import os import numpy as np import pytest @@ -13,17 +14,18 @@ @pytest.mark.parametrize( - ["file_path"], + "file_path", [ - ["b1.bin"], - ["./b2.bin"], - ["test_subdir/b3.bin"], # fails in the 1.2.3 version - ["./test_subdir/b4.bin"], # fails in the 1.2.3 version + "b1.bin", + "./b2.bin", + "test_subdir/b3.bin", # fails in the 1.2.3 version + "./test_subdir/b4.bin", # fails in the 1.2.3 version ], ) def test_load_ncd(file_path: str) -> None: + """Unit test - loading non-conforming dataset.""" dir_path, file_name = os.path.split(file_path) - file_name_base, file_name_ext = os.path.splitext(file_name) + file_name_base = os.path.splitext(file_name)[0] if not dir_path: dir_path = "." # sets the correct path in the case file is only a filename meta_file_path = f"{dir_path}/{file_name_base}.sigmf-meta" @@ -35,7 +37,8 @@ def test_load_ncd(file_path: str) -> None: pass # create dataset - np.arange(10, dtype=np.int16).tofile(file_path) + data_in = np.arange(10, dtype=np.int16) + data_in.tofile(file_path) # create metadata file metadata = { @@ -45,7 +48,7 @@ def test_load_ncd(file_path: str) -> None: }, SigMFFile.CAPTURE_KEY: [ { - SigMFFile.START_INDEX_KEY: 0, + SigMFFile.START_INDEX_KEY: 0, } ], SigMFFile.ANNOTATION_KEY: [], @@ -54,9 +57,7 @@ def test_load_ncd(file_path: str) -> None: meta_file.tofile(meta_file_path) # load dataset - data = fromfile(meta_file_path) + dataset = cast(SigMFFile, fromfile(meta_file_path)) + data_out = dataset.read_samples(autoscale=False) - assert np.array_equal( - np.arange(10, dtype=np.int16), - data.read_samples(autoscale=False), - ) + assert np.array_equal(data_in, data_out) From 47ddf994f612da5f5024e20f8a5db98a43fe7f95 Mon Sep 17 00:00:00 2001 From: JKB Date: Wed, 11 Dec 2024 14:30:28 +0100 Subject: [PATCH 04/11] fix docstring --- tests/test_load_ncd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_load_ncd.py b/tests/test_load_ncd.py index 91188c4..c492a22 100644 --- a/tests/test_load_ncd.py +++ b/tests/test_load_ncd.py @@ -4,7 +4,7 @@ # # SPDX-License-Identifier: LGPL-3.0-or-later -"""Tests for loading non-conforming datasets""" +"""Tests for loading non-conforming datasets.""" from typing import cast import os From 90c81de4f1461303f69996e3f3317530609a0352 Mon Sep 17 00:00:00 2001 From: JKB Date: Thu, 12 Dec 2024 09:54:12 +0100 Subject: [PATCH 05/11] use os.path.join, clean-up unit test --- sigmf/sigmffile.py | 6 ++---- tests/test_load_ncd.py | 40 +++++++++++++++++++++------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/sigmf/sigmffile.py b/sigmf/sigmffile.py index f937016..1e83cca 100644 --- a/sigmf/sigmffile.py +++ b/sigmf/sigmffile.py @@ -938,9 +938,6 @@ def get_dataset_filename_from_metadata(meta_fn, metadata=None): """ compliant_data_fn = get_sigmf_filenames(meta_fn)["data_fn"] noncompliant_data_fn = metadata["global"].get("core:dataset", None) - dir_path = path.split(meta_fn)[0] - if not dir_path: - dir_path = "." # sets the correct path in the case meta_fn is only a filename if path.isfile(compliant_data_fn): if noncompliant_data_fn: @@ -951,7 +948,8 @@ def get_dataset_filename_from_metadata(meta_fn, metadata=None): return compliant_data_fn elif noncompliant_data_fn: - noncompliant_data_file_path = f"{dir_path}/{noncompliant_data_fn}" + dir_path = path.split(meta_fn)[0] + noncompliant_data_file_path = path.join(dir_path, noncompliant_data_fn) if path.isfile(noncompliant_data_file_path): if metadata["global"].get("core:metadata_only", False): warnings.warn( diff --git a/tests/test_load_ncd.py b/tests/test_load_ncd.py index c492a22..1a96f5b 100644 --- a/tests/test_load_ncd.py +++ b/tests/test_load_ncd.py @@ -14,37 +14,39 @@ @pytest.mark.parametrize( - "file_path", - [ - "b1.bin", - "./b2.bin", - "test_subdir/b3.bin", # fails in the 1.2.3 version - "./test_subdir/b4.bin", # fails in the 1.2.3 version - ], + ["index", "dir_path"], + enumerate( + [ + "", + "./", + "test_subdir/", + "./test_subdir/", + ] + ), ) -def test_load_ncd(file_path: str) -> None: +def test_load_ncd(index: int, dir_path: str) -> None: """Unit test - loading non-conforming dataset.""" - dir_path, file_name = os.path.split(file_path) - file_name_base = os.path.splitext(file_name)[0] - if not dir_path: - dir_path = "." # sets the correct path in the case file is only a filename - meta_file_path = f"{dir_path}/{file_name_base}.sigmf-meta" + data_file_name = f"data{index}.bin" + meta_file_name = f"data{index}.sigmf-meta" + data_file_path = f"{dir_path}{data_file_name}" + meta_file_path = f"{dir_path}{meta_file_name}" - # create dir + # create dir if necessary try: - os.makedirs(dir_path) + if dir_path: + os.makedirs(dir_path) except FileExistsError: pass - # create dataset + # create data file data_in = np.arange(10, dtype=np.int16) - data_in.tofile(file_path) + data_in.tofile(data_file_path) # create metadata file metadata = { SigMFFile.GLOBAL_KEY: { SigMFFile.DATATYPE_KEY: "ri16_le", - SigMFFile.DATASET_KEY: file_name, + SigMFFile.DATASET_KEY: data_file_name, }, SigMFFile.CAPTURE_KEY: [ { @@ -53,7 +55,7 @@ def test_load_ncd(file_path: str) -> None: ], SigMFFile.ANNOTATION_KEY: [], } - meta_file = SigMFFile(metadata=metadata, data_file=file_path) + meta_file = SigMFFile(metadata=metadata, data_file=data_file_path) meta_file.tofile(meta_file_path) # load dataset From 21595725f2b55df48812aba3871956aa5b8ee9a4 Mon Sep 17 00:00:00 2001 From: JKB Date: Thu, 12 Dec 2024 10:12:10 +0100 Subject: [PATCH 06/11] fix coding style --- tests/test_load_ncd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_load_ncd.py b/tests/test_load_ncd.py index 1a96f5b..562bdd5 100644 --- a/tests/test_load_ncd.py +++ b/tests/test_load_ncd.py @@ -34,7 +34,7 @@ def test_load_ncd(index: int, dir_path: str) -> None: # create dir if necessary try: if dir_path: - os.makedirs(dir_path) + os.makedirs(dir_path) except FileExistsError: pass From b6161e8f93e3dc7f0005fc14c16de99407185776 Mon Sep 17 00:00:00 2001 From: Teque5 Date: Sat, 14 Dec 2024 13:35:21 -0800 Subject: [PATCH 07/11] SigMFFileError for ncd problems; improve ncd testing --- .gitignore | 5 ++-- sigmf/sigmffile.py | 38 ++++++++++++------------ tests/test_load_ncd.py | 65 ------------------------------------------ tests/test_ncd.py | 63 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 86 deletions(-) delete mode 100644 tests/test_load_ncd.py create mode 100644 tests/test_ncd.py diff --git a/.gitignore b/.gitignore index 756579b..5c9c73d 100644 --- a/.gitignore +++ b/.gitignore @@ -11,7 +11,8 @@ SigMF.egg-info/* # test related .coverage -pytest.xml -coverage.xml +.hypothesis/ .tox/ +coverage.xml +pytest.xml htmlcov/* diff --git a/sigmf/sigmffile.py b/sigmf/sigmffile.py index 1e83cca..5780e3c 100644 --- a/sigmf/sigmffile.py +++ b/sigmf/sigmffile.py @@ -932,36 +932,36 @@ def get_dataset_filename_from_metadata(meta_fn, metadata=None): Parse provided metadata and return the expected data filename. In the case of a metadata only distribution, or if the file does not exist, this will return 'None'. The priority for conflicting: - 1. The file named .sigmf-data if it exists - 2. The file in the `core:dataset` field (Non-Compliant Dataset) if it exists - 3. None (may be a metadata only distribution) + 1. The file named .sigmf-data if it exists + 2. The file in the `core:dataset` field (Non-Compliant Dataset) if it exists + 3. None (may be a metadata only distribution) """ - compliant_data_fn = get_sigmf_filenames(meta_fn)["data_fn"] - noncompliant_data_fn = metadata["global"].get("core:dataset", None) + compliant_filename = get_sigmf_filenames(meta_fn)["data_fn"] + noncompliant_filename = metadata["global"].get("core:dataset", None) - if path.isfile(compliant_data_fn): - if noncompliant_data_fn: + if path.isfile(compliant_filename): + if noncompliant_filename: warnings.warn( - f"Compliant Dataset `{compliant_data_fn}` exists but " - f'"core:dataset" is also defined; using `{compliant_data_fn}`' + f"Compliant Dataset `{compliant_filename}` exists but " + f"{SigMFFile.DATASET_KEY} is also defined; using `{compliant_filename}`" ) - return compliant_data_fn + return compliant_filename - elif noncompliant_data_fn: + elif noncompliant_filename: dir_path = path.split(meta_fn)[0] - noncompliant_data_file_path = path.join(dir_path, noncompliant_data_fn) + noncompliant_data_file_path = path.join(dir_path, noncompliant_filename) if path.isfile(noncompliant_data_file_path): - if metadata["global"].get("core:metadata_only", False): - warnings.warn( - 'Schema defines "core:dataset" but "core:metadata_only" ' - f"also exists; using `{noncompliant_data_fn}`" + if metadata["global"].get(SigMFFile.METADATA_ONLY_KEY, False): + raise SigMFFileError( + f"Schema defines {SigMFFile.DATASET_KEY} " + f"but {SigMFFile.METADATA_ONLY_KEY} also exists; using `{noncompliant_filename}`" ) return noncompliant_data_file_path else: - warnings.warn( - f"Non-Compliant Dataset `{noncompliant_data_fn}` is specified " 'in "core:dataset" but does not exist!' + raise SigMFFileError( + f"Non-Compliant Dataset `{noncompliant_filename}` is specified in {SigMFFile.DATASET_KEY} " + "but does not exist!" ) - return None diff --git a/tests/test_load_ncd.py b/tests/test_load_ncd.py deleted file mode 100644 index 562bdd5..0000000 --- a/tests/test_load_ncd.py +++ /dev/null @@ -1,65 +0,0 @@ -# Copyright: Multiple Authors -# -# This file is part of sigmf-python. https://github.com/sigmf/sigmf-python -# -# SPDX-License-Identifier: LGPL-3.0-or-later - -"""Tests for loading non-conforming datasets.""" - -from typing import cast -import os -import numpy as np -import pytest -from sigmf.sigmffile import SigMFFile, fromfile - - -@pytest.mark.parametrize( - ["index", "dir_path"], - enumerate( - [ - "", - "./", - "test_subdir/", - "./test_subdir/", - ] - ), -) -def test_load_ncd(index: int, dir_path: str) -> None: - """Unit test - loading non-conforming dataset.""" - data_file_name = f"data{index}.bin" - meta_file_name = f"data{index}.sigmf-meta" - data_file_path = f"{dir_path}{data_file_name}" - meta_file_path = f"{dir_path}{meta_file_name}" - - # create dir if necessary - try: - if dir_path: - os.makedirs(dir_path) - except FileExistsError: - pass - - # create data file - data_in = np.arange(10, dtype=np.int16) - data_in.tofile(data_file_path) - - # create metadata file - metadata = { - SigMFFile.GLOBAL_KEY: { - SigMFFile.DATATYPE_KEY: "ri16_le", - SigMFFile.DATASET_KEY: data_file_name, - }, - SigMFFile.CAPTURE_KEY: [ - { - SigMFFile.START_INDEX_KEY: 0, - } - ], - SigMFFile.ANNOTATION_KEY: [], - } - meta_file = SigMFFile(metadata=metadata, data_file=data_file_path) - meta_file.tofile(meta_file_path) - - # load dataset - dataset = cast(SigMFFile, fromfile(meta_file_path)) - data_out = dataset.read_samples(autoscale=False) - - assert np.array_equal(data_in, data_out) diff --git a/tests/test_ncd.py b/tests/test_ncd.py new file mode 100644 index 0000000..ce6680c --- /dev/null +++ b/tests/test_ncd.py @@ -0,0 +1,63 @@ +# Copyright: Multiple Authors +# +# This file is part of sigmf-python. https://github.com/sigmf/sigmf-python +# +# SPDX-License-Identifier: LGPL-3.0-or-later + +"""Tests for Non-Conforming Datasets""" + +import copy +import os +import shutil +import tempfile +import unittest +from pathlib import Path + +import numpy as np +from hypothesis import given +from hypothesis import strategies as st + +from sigmf.error import SigMFFileError +from sigmf.sigmffile import SigMFFile, fromfile + +from .testdata import TEST_FLOAT32_DATA, TEST_METADATA + + +class TestNonConformingDataset(unittest.TestCase): + """unit tests for NCD""" + + def setUp(self): + """create temporary path""" + self.temp_dir = Path(tempfile.mkdtemp()) + + def tearDown(self): + """remove temporary path""" + shutil.rmtree(self.temp_dir) + + @given(st.sampled_from([".", "subdir/", "sub0/sub1/sub2/"])) + def test_load_ncd(self, subdir: str) -> None: + """test loading non-conforming dataset""" + data_path = self.temp_dir / subdir / "dat.bin" + meta_path = self.temp_dir / subdir / "dat.sigmf-meta" + os.makedirs(data_path.parent, exist_ok=True) + + # create data file + TEST_FLOAT32_DATA.tofile(data_path) + + # create metadata file + ncd_metadata = copy.deepcopy(TEST_METADATA) + meta = SigMFFile(metadata=ncd_metadata, data_file=data_path) + # tell SigMF that the data is noncompliant + meta.set_global_field(SigMFFile.DATASET_KEY, data_path.name) + meta.validate() + meta.tofile(meta_path) + + # load dataset & validate we can read all the data + meta_loopback = fromfile(meta_path) + self.assertTrue(np.array_equal(TEST_FLOAT32_DATA, meta_loopback.read_samples())) + self.assertTrue(np.array_equal(TEST_FLOAT32_DATA, meta_loopback[:])) + + # delete the non-conforming dataset and ensure error is raised due to missing dataset + os.remove(data_path) + with self.assertRaises(SigMFFileError): + _ = fromfile(meta_path) From f8be2af8b6c16f14136c2566872cbe469fcf11ee Mon Sep 17 00:00:00 2001 From: JKB Date: Thu, 19 Dec 2024 14:22:28 +0100 Subject: [PATCH 08/11] implement NCD detection; fix file deletion on Windows --- sigmf/sigmffile.py | 8 +++++++- tests/test_ncd.py | 8 +++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/sigmf/sigmffile.py b/sigmf/sigmffile.py index 5780e3c..2902f50 100644 --- a/sigmf/sigmffile.py +++ b/sigmf/sigmffile.py @@ -558,6 +558,12 @@ def set_data_file(self, data_file=None, data_buffer=None, skip_checksum=False, o self._memmap = raveled.reshape(mapped_reshape) self.shape = self._memmap.shape if (self._return_type is None) else self._memmap.shape[:-1] + if self.data_file is not None: + file_name = path.split(self.data_file)[1] + ext = path.splitext(file_name)[1] + if ext.lower() != SIGMF_DATASET_EXT: + self.set_global_field(SigMFFile.DATASET_KEY, file_name) + if skip_checksum: return None return self.calculate_hash() @@ -937,7 +943,7 @@ def get_dataset_filename_from_metadata(meta_fn, metadata=None): 3. None (may be a metadata only distribution) """ compliant_filename = get_sigmf_filenames(meta_fn)["data_fn"] - noncompliant_filename = metadata["global"].get("core:dataset", None) + noncompliant_filename = metadata["global"].get(SigMFFile.DATASET_KEY, None) if path.isfile(compliant_filename): if noncompliant_filename: diff --git a/tests/test_ncd.py b/tests/test_ncd.py index ce6680c..4bb5745 100644 --- a/tests/test_ncd.py +++ b/tests/test_ncd.py @@ -47,8 +47,6 @@ def test_load_ncd(self, subdir: str) -> None: # create metadata file ncd_metadata = copy.deepcopy(TEST_METADATA) meta = SigMFFile(metadata=ncd_metadata, data_file=data_path) - # tell SigMF that the data is noncompliant - meta.set_global_field(SigMFFile.DATASET_KEY, data_path.name) meta.validate() meta.tofile(meta_path) @@ -57,7 +55,11 @@ def test_load_ncd(self, subdir: str) -> None: self.assertTrue(np.array_equal(TEST_FLOAT32_DATA, meta_loopback.read_samples())) self.assertTrue(np.array_equal(TEST_FLOAT32_DATA, meta_loopback[:])) - # delete the non-conforming dataset and ensure error is raised due to missing dataset + # delete the non-conforming dataset and ensure error is raised due to missing dataset; + # in Windows the SigMFFile instances need to be garbage collected first, + # otherwise the np.memmap instances (stored in self._memmap) block the deletion + meta = None + meta_loopback = None os.remove(data_path) with self.assertRaises(SigMFFileError): _ = fromfile(meta_path) From 871f3bc08683759f843f99d10d56a2b41b119545 Mon Sep 17 00:00:00 2001 From: Kyle A Logue Date: Thu, 19 Dec 2024 09:18:09 -0800 Subject: [PATCH 09/11] fix test failures where temporary dataset suffix was incorrect --- sigmf/sigmffile.py | 4 ++-- tests/conftest.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/sigmf/sigmffile.py b/sigmf/sigmffile.py index 2902f50..15a6051 100644 --- a/sigmf/sigmffile.py +++ b/sigmf/sigmffile.py @@ -938,8 +938,8 @@ def get_dataset_filename_from_metadata(meta_fn, metadata=None): Parse provided metadata and return the expected data filename. In the case of a metadata only distribution, or if the file does not exist, this will return 'None'. The priority for conflicting: - 1. The file named .sigmf-data if it exists - 2. The file in the `core:dataset` field (Non-Compliant Dataset) if it exists + 1. The file named .SIGMF_DATASET_EXT if it exists + 2. The file in the DATASET_KEY field (Non-Compliant Dataset) if it exists 3. None (may be a metadata only distribution) """ compliant_filename = get_sigmf_filenames(meta_fn)["data_fn"] diff --git a/tests/conftest.py b/tests/conftest.py index 0e46aaf..a5379ef 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -11,6 +11,7 @@ import pytest from sigmf import __specification__ +from sigmf.archive import SIGMF_DATASET_EXT from sigmf.sigmffile import SigMFFile from .testdata import TEST_FLOAT32_DATA, TEST_METADATA @@ -18,8 +19,8 @@ @pytest.fixture def test_data_file(): - """when called, yields temporary file""" - with tempfile.NamedTemporaryFile() as temp: + """when called, yields temporary dataset""" + with tempfile.NamedTemporaryFile(suffix=f".{SIGMF_DATASET_EXT}") as temp: TEST_FLOAT32_DATA.tofile(temp.name) yield temp From 9809de0974401f78d9629a79a636c8f6a518155c Mon Sep 17 00:00:00 2001 From: Kyle A Logue Date: Thu, 19 Dec 2024 10:52:39 -0800 Subject: [PATCH 10/11] removed unnecessary validate; automatic on tofile() --- tests/test_ncd.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_ncd.py b/tests/test_ncd.py index 4bb5745..5978cbf 100644 --- a/tests/test_ncd.py +++ b/tests/test_ncd.py @@ -47,7 +47,6 @@ def test_load_ncd(self, subdir: str) -> None: # create metadata file ncd_metadata = copy.deepcopy(TEST_METADATA) meta = SigMFFile(metadata=ncd_metadata, data_file=data_path) - meta.validate() meta.tofile(meta_path) # load dataset & validate we can read all the data From f358e30d25914d87357845ecd49c56ecb6e7b5c8 Mon Sep 17 00:00:00 2001 From: GreenK173 Date: Thu, 19 Dec 2024 21:08:12 +0100 Subject: [PATCH 11/11] Add specification version to the metadata in SigMFCollection (#83) * add version for collections --------- Co-authored-by: JKB Co-authored-by: Kyle A Logue --- sigmf/sigmffile.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sigmf/sigmffile.py b/sigmf/sigmffile.py index 15a6051..683cdf8 100644 --- a/sigmf/sigmffile.py +++ b/sigmf/sigmffile.py @@ -282,7 +282,7 @@ def set_metadata(self, metadata): if self.get_global_field(self.NUM_CHANNELS_KEY) is None: self.set_global_field(self.NUM_CHANNELS_KEY, 1) - # set specification version to current implemented version + # set version to current implementation self.set_global_field(self.VERSION_KEY, __specification__) def set_global_info(self, new_global): @@ -758,6 +758,9 @@ def __init__(self, metafiles=None, metadata=None, skip_checksums=False): else: self.set_streams(metafiles) + # set version to current implementation + self.set_collection_field(self.VERSION_KEY, __specification__) + if not self.skip_checksums: self.verify_stream_hashes()