@@ -101,52 +101,43 @@ def write_minimal(self, format: bytes = b"CF") -> None:
101101 handle .seek (512 )
102102 handle .write (iq_converted .tobytes ()) # write IQ data
103103
104+ def check_data_and_metadata (self , meta , form , atol ):
105+ """ensure blue is sample perfect and metadata is equivalent"""
106+ self .assertEqual (meta .sample_rate , self .samp_rate )
107+ self .assertEqual (meta .get_capture_info (0 )["core:datetime" ], self .datetime )
108+ if form [0 ] == "S" :
109+ np .testing .assert_allclose (self .iq_data .real , meta [:], atol = atol )
110+ else :
111+ np .testing .assert_allclose (self .iq_data , meta [:], atol = atol )
112+
104113 def test_blue_to_sigmf_pair (self ) -> None :
105114 """test standard blue to sigmf conversion with file pairs"""
106- for format , atol in self .format_tolerance :
115+ for form , atol in self .format_tolerance :
107116 sigmf_path = self .tmp_path / f"bar{ format } "
108- self .write_minimal (format .encode ())
117+ self .write_minimal (form .encode ())
109118 meta = blue_to_sigmf (blue_path = self .blue_path , out_path = sigmf_path )
110119 filenames = sigmf .sigmffile .get_sigmf_filenames (sigmf_path )
111120 self .assertTrue (filenames ["data_fn" ].exists (), "dataset path missing" )
112121 self .assertTrue (filenames ["meta_fn" ].exists (), "metadata path missing" )
113- self .assertEqual (meta .sample_rate , self .samp_rate )
114- self .assertEqual (meta .get_capture_info (0 )["core:datetime" ], self .datetime )
115- # verify data
116- if format [0 ] == "S" :
117- np .testing .assert_allclose (self .iq_data .real , meta [:], atol = atol )
118- else :
119- np .testing .assert_allclose (self .iq_data , meta [:], atol = atol )
122+ self .check_data_and_metadata (meta , form , atol )
120123
121124 def test_blue_to_sigmf_archive (self ) -> None :
122125 """test blue to sigmf conversion with archive output"""
123- for format , atol in self .format_tolerance :
124- self .write_minimal (format .encode ())
126+ for form , atol in self .format_tolerance :
127+ self .write_minimal (form .encode ())
125128 sigmf_path = self .tmp_path / f"baz{ format } "
126129 meta = blue_to_sigmf (blue_path = self .blue_path , out_path = sigmf_path , create_archive = True )
127130 filenames = sigmf .sigmffile .get_sigmf_filenames (sigmf_path )
128131 self .assertTrue (filenames ["archive_fn" ].exists (), "archive path missing" )
129- self .assertEqual (meta .sample_rate , self .samp_rate )
130- self .assertEqual (meta .get_capture_info (0 )["core:datetime" ], self .datetime )
131- # verify data
132- if format [0 ] == "S" :
133- np .testing .assert_allclose (self .iq_data .real , meta [:], atol = atol )
134- else :
135- np .testing .assert_allclose (self .iq_data , meta [:], atol = atol )
132+ self .check_data_and_metadata (meta , form , atol )
136133
137134 def test_blue_to_sigmf_ncd (self ) -> None :
138135 """test automatic NCD conversion with fromfile()"""
139- for format , atol in self .format_tolerance :
140- self .write_minimal (format .encode ())
136+ for form , atol in self .format_tolerance :
137+ self .write_minimal (form .encode ())
141138 meta = blue_to_sigmf (self .blue_path )
142139 _validate_ncd (self , meta , self .blue_path )
143- self .assertEqual (meta .sample_rate , self .samp_rate )
144- self .assertEqual (meta .get_capture_info (0 )["core:datetime" ], self .datetime )
145- # verify data
146- if format [0 ] == "S" :
147- np .testing .assert_allclose (self .iq_data .real , meta [:], atol = atol )
148- else :
149- np .testing .assert_allclose (self .iq_data , meta [:], atol = atol )
140+ self .check_data_and_metadata (meta , form , atol )
150141
151142
152143class TestBlueWithNonSigMFRepo (unittest .TestCase ):
0 commit comments