Skip to content

Commit

Permalink
Use tempfile for temp files instead of manual paths
Browse files Browse the repository at this point in the history
  • Loading branch information
bebau authored and Teque5 committed Oct 25, 2023
1 parent 6ee4909 commit 6c90458
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions tests/test_sigmffile.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,21 +249,23 @@ def test_captures_checking():

def test_slicing():
'''Test __getitem___ builtin for sigmffile, make sure slicing and indexing works as expected.'''
np.array(TEST_U8_DATA0, dtype=np.uint8).tofile('/tmp/d5.sigmf-data')
with open('/tmp/d5.sigmf-meta','w') as f0: json.dump(TEST_U8_META0, f0)
sigmf0 = sigmffile.fromfile('/tmp/d5.sigmf-meta')
_, temp_data0 = tempfile.mkstemp()
np.array(TEST_U8_DATA0, dtype=np.uint8).tofile(temp_data0)
sigmf0 = SigMFFile(metadata=TEST_U8_META0, data_file=temp_data0)
assert np.array_equal(TEST_U8_DATA0, sigmf0[:])
assert TEST_U8_DATA0[6] == sigmf0[6]

np.array(TEST_FLOAT32_DATA, dtype=np.float32).tofile('/tmp/d6.sigmf-data')
with open('/tmp/d6.sigmf-meta','w') as f1: json.dump(TEST_METADATA, f1)
sigmf1 = sigmffile.fromfile('/tmp/d6.sigmf-meta')
# test float32
_, temp_data1 = tempfile.mkstemp()
np.array(TEST_FLOAT32_DATA, dtype=np.float32).tofile(temp_data1)
sigmf1 = SigMFFile(metadata=TEST_METADATA, data_file=temp_data1)
assert np.array_equal(TEST_FLOAT32_DATA, sigmf1[:])
assert sigmf1[10] == TEST_FLOAT32_DATA[10]

np.array(TEST_U8_DATA4, dtype=np.uint8).tofile('/tmp/d7.sigmf-data')
with open('/tmp/d7.sigmf-meta','w') as f4: json.dump(TEST_U8_META4, f4)
sigmf2 = sigmffile.fromfile('/tmp/d7.sigmf-meta')
# test multiple channels
_, temp_data2 = tempfile.mkstemp()
np.array(TEST_U8_DATA4, dtype=np.uint8).tofile(temp_data2)
sigmf2 = SigMFFile(TEST_U8_META4, data_file=temp_data2)
channelized = np.array(TEST_U8_DATA4).reshape((128,2))
assert np.array_equal(channelized, sigmf2[:][:])
assert np.array_equal(sigmf2[10:20, 91:112], sigmf2.read_samples(autoscale=False)[10:20, 91:112])
Expand Down

0 comments on commit 6c90458

Please sign in to comment.