Skip to content

Commit

Permalink
fix sigmffile contructor calls without names, test data names
Browse files Browse the repository at this point in the history
  • Loading branch information
jhazentia committed Jan 23, 2024
1 parent 1c51c05 commit b7f7e72
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion sigmf/gui.py
Expand Up @@ -401,7 +401,7 @@ def main():
capture_data_input = CaptureData()
capture_text_blocks = {}
window_text_blocks = {}
f = SigMFFile()
f = SigMFFile("generic_name")
capture_selector_dict = {}

layout = [[Text('This is the SigMF tool to archive RF datasets', size=(80, 1))],
Expand Down
4 changes: 3 additions & 1 deletion sigmf/tools/wav2sigmf.py
Expand Up @@ -41,7 +41,9 @@ def writeSigMFArchiveFromWave(input_wav_filename, archive_filename=None, start_d
sigmf_data_path = os.path.join(tmpdir, sigmf_data_filename)
wav_data.tofile(sigmf_data_path)

meta = sigmf.SigMFFile(data_file=sigmf_data_path, global_info=global_info)
meta = sigmf.SigMFFile(name=os.path.basename(input_wav_filename),
data_file=sigmf_data_path,
global_info=global_info)
meta.add_capture(0, metadata=capture_info)

if archive_filename is None:
Expand Down
12 changes: 6 additions & 6 deletions tests/test_sigmffile.py
Expand Up @@ -68,7 +68,7 @@ class TestAnnotationHandling(unittest.TestCase):

def test_get_annotations_with_index(self):
"""Test that only annotations containing index are returned from get_annotations()"""
smf = SigMFFile(copy.deepcopy(TEST_METADATA))
smf = SigMFFile("test", copy.deepcopy(TEST_METADATA_1))
smf.add_annotation(start_index=1)
smf.add_annotation(start_index=4, length=4)
annotations_idx10 = smf.get_annotations(index=10)
Expand All @@ -82,7 +82,7 @@ def test_get_annotations_with_index(self):

def test__count_samples_from_annotation(self):
"""Make sure sample count from annotations use correct end index"""
smf = SigMFFile(copy.deepcopy(TEST_METADATA))
smf = SigMFFile("test", copy.deepcopy(TEST_METADATA_1))
smf.add_annotation(start_index=0, length=32)
smf.add_annotation(start_index=4, length=4)
sample_count = smf._count_samples()
Expand All @@ -93,11 +93,11 @@ def test_set_data_file_without_annotations(self):
Make sure setting data_file with no annotations registered does not
raise any errors
"""
smf = SigMFFile(copy.deepcopy(TEST_METADATA))
smf = SigMFFile("test", copy.deepcopy(TEST_METADATA_1))
smf._metadata[SigMFFile.ANNOTATION_KEY].clear()
with tempfile.TemporaryDirectory() as tmpdir:
temp_path_data = os.path.join(tmpdir, "datafile")
TEST_FLOAT32_DATA.tofile(temp_path_data)
TEST_FLOAT32_DATA_1.tofile(temp_path_data)
smf.set_data_file(temp_path_data)
samples = smf.read_samples()
self.assertTrue(len(samples)==16)
Expand All @@ -108,11 +108,11 @@ def test_set_data_file_with_annotations(self):
count from data_file and issue a warning if annotations have end
indices bigger than file end index
"""
smf = SigMFFile(copy.deepcopy(TEST_METADATA))
smf = SigMFFile("test", copy.deepcopy(TEST_METADATA_1))
smf.add_annotation(start_index=0, length=32)
with tempfile.TemporaryDirectory() as tmpdir:
temp_path_data = os.path.join(tmpdir, "datafile")
TEST_FLOAT32_DATA.tofile(temp_path_data)
TEST_FLOAT32_DATA_1.tofile(temp_path_data)
with self.assertWarns(Warning):
# Issues warning since file ends before the final annotatio
smf.set_data_file(temp_path_data)
Expand Down
12 changes: 6 additions & 6 deletions tests/test_validation.py
Expand Up @@ -44,19 +44,19 @@ def test_extra_top_level_key(self):
'''no extra keys allowed on the top level'''
self.metadata['extra'] = 0
with self.assertRaises(ValidationError):
SigMFFile(self.metadata).validate()
SigMFFile("test", self.metadata).validate()

def test_invalid_label(self):
'''label must be less than 20 chars'''
self.metadata[SigMFFile.ANNOTATION_KEY][0][SigMFFile.LABEL_KEY] = 'a' * 21
with self.assertRaises(ValidationError):
SigMFFile(self.metadata).validate()
SigMFFile("test", self.metadata).validate()

def test_invalid_type(self):
'''license key must be string'''
self.metadata[SigMFFile.GLOBAL_KEY][SigMFFile.LICENSE_KEY] = 1
with self.assertRaises(ValidationError):
SigMFFile(self.metadata).validate()
SigMFFile("test", self.metadata).validate()

def test_invalid_capture_order(self):
'''metadata must have captures in order'''
Expand All @@ -65,7 +65,7 @@ def test_invalid_capture_order(self):
{SigMFFile.START_INDEX_KEY: 9}
]
with self.assertRaises(ValidationError):
SigMFFile(self.metadata).validate()
SigMFFile("test", self.metadata).validate()

def test_invalid_annotation_order(self):
'''metadata must have annotations in order'''
Expand All @@ -80,7 +80,7 @@ def test_invalid_annotation_order(self):
}
]
with self.assertRaises(ValidationError):
SigMFFile(self.metadata).validate()
SigMFFile("test", self.metadata).validate()

def test_annotation_without_sample_count(self):
'''annotation without length should be accepted'''
Expand All @@ -89,7 +89,7 @@ def test_annotation_without_sample_count(self):
SigMFFile.START_INDEX_KEY: 2
}
]
SigMFFile(self.metadata).validate()
SigMFFile("test", self.metadata).validate()


def test_invalid_hash(self):
Expand Down

0 comments on commit b7f7e72

Please sign in to comment.