66
77"""Tests for SigMFArchiveReader"""
88
9- import tempfile
109import unittest
10+ from tempfile import NamedTemporaryFile
1111
1212import numpy as np
1313
@@ -33,29 +33,28 @@ def setUp(self):
3333
3434 def test_access_data_without_untar (self ):
3535 """iterate through datatypes and verify IO is correct"""
36- _ , temp_path = tempfile . mkstemp ()
37- _ , temp_archive = tempfile . mkstemp (suffix = ".sigmf" )
36+ temp_data = NamedTemporaryFile ()
37+ temp_archive = NamedTemporaryFile (suffix = ".sigmf" )
3838
3939 for key , dtype in self .lut .items ():
4040 # for each type of storage
4141 temp_samples = np .arange (self .raw_count , dtype = dtype )
42- temp_samples .tofile (temp_path )
42+ temp_samples .tofile (temp_data . name )
4343 for num_channels in [1 , 4 , 8 ]:
4444 # for single or 8 channel
4545 for complex_prefix in ["r" , "c" ]:
4646 # for real or complex
4747 target_count = self .raw_count
4848 temp_meta = SigMFFile (
49- data_file = temp_path ,
49+ data_file = temp_data . name ,
5050 global_info = {
5151 SigMFFile .DATATYPE_KEY : f"{ complex_prefix } { key } _le" ,
5252 SigMFFile .NUM_CHANNELS_KEY : num_channels ,
53- SigMFFile .VERSION_KEY : __specification__ ,
5453 },
5554 )
56- temp_meta .tofile (temp_archive , toarchive = True )
55+ temp_meta .tofile (temp_archive . name , toarchive = True )
5756
58- readback = SigMFArchiveReader (temp_archive )
57+ readback = SigMFArchiveReader (temp_archive . name )
5958 readback_samples = readback [:]
6059
6160 if complex_prefix == "c" :
@@ -84,10 +83,10 @@ def test_access_data_without_untar(self):
8483
8584
8685def test_archiveread_data_file_unchanged (test_sigmffile ):
87- with tempfile . NamedTemporaryFile (suffix = ".sigmf" ) as temp :
86+ with NamedTemporaryFile (suffix = ".sigmf" ) as temp_file :
8887 input_samples = test_sigmffile .read_samples ()
89- test_sigmffile .archive (temp .name )
90- arc = sigmf .sigmffile .fromfile (temp .name )
88+ test_sigmffile .archive (temp_file .name )
89+ arc = sigmf .sigmffile .fromfile (temp_file .name )
9190 output_samples = arc .read_samples ()
9291
9392 assert np .array_equal (input_samples , output_samples )
0 commit comments