66
77"""Tests for loading non-conforming datasets"""
88
9+ from typing import cast
910import os
1011import numpy as np
1112import pytest
1213from sigmf .sigmffile import SigMFFile , fromfile
1314
1415
1516@pytest .mark .parametrize (
16- [ "file_path" ] ,
17+ "file_path" ,
1718 [
18- [ "b1.bin" ] ,
19- [ "./b2.bin" ] ,
20- [ "test_subdir/b3.bin" ] , # fails in the 1.2.3 version
21- [ "./test_subdir/b4.bin" ] , # fails in the 1.2.3 version
19+ "b1.bin" ,
20+ "./b2.bin" ,
21+ "test_subdir/b3.bin" , # fails in the 1.2.3 version
22+ "./test_subdir/b4.bin" , # fails in the 1.2.3 version
2223 ],
2324)
2425def test_load_ncd (file_path : str ) -> None :
26+ """Unit test - loading non-conforming dataset."""
2527 dir_path , file_name = os .path .split (file_path )
26- file_name_base , file_name_ext = os .path .splitext (file_name )
28+ file_name_base = os .path .splitext (file_name )[ 0 ]
2729 if not dir_path :
2830 dir_path = "." # sets the correct path in the case file is only a filename
2931 meta_file_path = f"{ dir_path } /{ file_name_base } .sigmf-meta"
@@ -35,7 +37,8 @@ def test_load_ncd(file_path: str) -> None:
3537 pass
3638
3739 # create dataset
38- np .arange (10 , dtype = np .int16 ).tofile (file_path )
40+ data_in = np .arange (10 , dtype = np .int16 )
41+ data_in .tofile (file_path )
3942
4043 # create metadata file
4144 metadata = {
@@ -45,7 +48,7 @@ def test_load_ncd(file_path: str) -> None:
4548 },
4649 SigMFFile .CAPTURE_KEY : [
4750 {
48- SigMFFile .START_INDEX_KEY : 0 ,
51+ SigMFFile .START_INDEX_KEY : 0 ,
4952 }
5053 ],
5154 SigMFFile .ANNOTATION_KEY : [],
@@ -54,9 +57,7 @@ def test_load_ncd(file_path: str) -> None:
5457 meta_file .tofile (meta_file_path )
5558
5659 # load dataset
57- data = fromfile (meta_file_path )
60+ dataset = cast (SigMFFile , fromfile (meta_file_path ))
61+ data_out = dataset .read_samples (autoscale = False )
5862
59- assert np .array_equal (
60- np .arange (10 , dtype = np .int16 ),
61- data .read_samples (autoscale = False ),
62- )
63+ assert np .array_equal (data_in , data_out )
0 commit comments