-
Notifications
You must be signed in to change notification settings - Fork 19
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
Fix path handling for non-conforming datasets #81
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ed130b2
bugfix get_dataset_filename_from_metadata
bf2d570
unit test
e16e1f8
unit test clean-up
5e53948
fix docstring
927a73f
use os.path.join, clean-up unit test
4bd3336
fix coding style
db44859
SigMFFileError for ncd problems; improve ncd testing
Teque5 612c77c
implement NCD detection; fix file deletion on Windows
5b1aa1a
Merge branch 'sigmf:main' into ncd-path
GreenK173 6b8301b
fix test failures where temporary dataset suffix was incorrect
6405e6a
removed unnecessary validate; automatic on tofile()
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# 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) | ||
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; | ||
# 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) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't love path handling like this, but I opened #90 and we can address it in the future.