@@ -125,8 +125,20 @@ def test_iter_blocks_simple_file(dummy_file):
125125 assert block [:4 ] == b'RUNE'
126126 assert (np .frombuffer (block [4 :], np .float32 ) == data [1 :]).all ()
127127
128+ with pytest .raises (StopIteration ):
129+ next (block_it )
128130
129131
132+ def test_iter_blocks_all (dummy_file ):
133+ """Test for iterblocks for the case of no record markers"""
134+
135+ with dummy_file .open ('rb' ) as f :
136+ n_blocks_read = 0
137+ for _ in iter_blocks (f ):
138+ n_blocks_read += 1
139+
140+ assert n_blocks_read == 27
141+
130142def test_versions ():
131143 from corsikaio .io import read_buffer_size , read_block
132144 from corsikaio .subblocks import get_version
@@ -142,3 +154,17 @@ def test_versions():
142154
143155 block = read_block (f , buffer_size )
144156 assert get_version (block , EVTH_VERSION_POSITION ) == version
157+
158+
159+
160+ @pytest .mark .parametrize ("size" , (100 , 1000 , 5000 ))
161+ def test_iter_blocks_truncated (size , tmp_path , dummy_file ):
162+ path = tmp_path / f"test_truncated_{ size } .dat"
163+
164+ with path .open ("wb" ) as out , dummy_file .open ("rb" ) as infile :
165+ out .write (infile .read (size ))
166+
167+ with pytest .raises (IOError , match = "file seems to be truncated" ):
168+ with path .open ("rb" ) as f :
169+ for _ in iter_blocks (f ):
170+ pass
0 commit comments