2727
2828SAMPLES_PER_TRACE = 1501
2929
30+
3031class TestDisasterRecoveryWrapper :
3132 """Test cases for disaster recovery wrapper functionality."""
3233
@@ -51,17 +52,19 @@ def basic_segy_spec(self) -> SegySpec:
5152
5253 return spec .customize (trace_header_fields = header_fields )
5354
54- @pytest .fixture (params = [
55- {"endianness" : Endianness .BIG , "data_format" : 1 , "name" : "big_endian_ibm" },
56- {"endianness" : Endianness .BIG , "data_format" : 5 , "name" : "big_endian_ieee" },
57- {"endianness" : Endianness .LITTLE , "data_format" : 1 , "name" : "little_endian_ibm" },
58- {"endianness" : Endianness .LITTLE , "data_format" : 5 , "name" : "little_endian_ieee" },
59- ])
60- def segy_config (self , request ) -> dict :
55+ @pytest .fixture (
56+ params = [
57+ {"endianness" : Endianness .BIG , "data_format" : 1 , "name" : "big_endian_ibm" },
58+ {"endianness" : Endianness .BIG , "data_format" : 5 , "name" : "big_endian_ieee" },
59+ {"endianness" : Endianness .LITTLE , "data_format" : 1 , "name" : "little_endian_ibm" },
60+ {"endianness" : Endianness .LITTLE , "data_format" : 5 , "name" : "little_endian_ieee" },
61+ ]
62+ )
63+ def segy_config (self , request : pytest .FixtureRequest ) -> dict :
6164 """Parameterized fixture for different SEGY configurations."""
6265 return request .param
6366
64- def create_test_segy_file (
67+ def create_test_segy_file ( # noqa: PLR0913
6568 self ,
6669 spec : SegySpec ,
6770 num_traces : int ,
@@ -119,7 +122,7 @@ def extract_header_bytes_from_file(
119122 self , segy_path : Path , trace_index : int , byte_start : int , byte_length : int
120123 ) -> NDArray :
121124 """Extract specific bytes from a trace header in the SEGY file."""
122- with open (segy_path , "rb" ) as f :
125+ with segy_path . open ("rb" ) as f :
123126 # Skip text header (3200 bytes) + binary header (400 bytes)
124127 header_offset = 3600
125128
@@ -164,18 +167,12 @@ def test_header_validation_configurations(
164167 for trace_idx in test_indices :
165168 # Get raw and transformed headers
166169 raw_headers , transformed_headers , traces = get_header_raw_and_transformed (
167- segy_file = segy_file ,
168- indices = trace_idx ,
169- do_reverse_transforms = True
170+ segy_file = segy_file , indices = trace_idx , do_reverse_transforms = True
170171 )
171172
172173 # Extract bytes from disk for inline (bytes 189-192) and crossline (bytes 193-196)
173- inline_bytes_disk = self .extract_header_bytes_from_file (
174- segy_path , trace_idx , 189 , 4
175- )
176- crossline_bytes_disk = self .extract_header_bytes_from_file (
177- segy_path , trace_idx , 193 , 4
178- )
174+ inline_bytes_disk = self .extract_header_bytes_from_file (segy_path , trace_idx , 189 , 4 )
175+ crossline_bytes_disk = self .extract_header_bytes_from_file (segy_path , trace_idx , 193 , 4 )
179176
180177 # Convert raw headers to bytes for comparison
181178 if raw_headers is not None :
@@ -185,30 +182,30 @@ def test_header_validation_configurations(
185182 if raw_headers .ndim == 0 :
186183 # Single trace case
187184 raw_data_bytes = raw_headers .tobytes ()
188- inline_offset = raw_headers .dtype .fields [' inline' ][1 ]
189- crossline_offset = raw_headers .dtype .fields [' crossline' ][1 ]
190- inline_size = raw_headers .dtype .fields [' inline' ][0 ].itemsize
191- crossline_size = raw_headers .dtype .fields [' crossline' ][0 ].itemsize
192-
185+ inline_offset = raw_headers .dtype .fields [" inline" ][1 ]
186+ crossline_offset = raw_headers .dtype .fields [" crossline" ][1 ]
187+ inline_size = raw_headers .dtype .fields [" inline" ][0 ].itemsize
188+ crossline_size = raw_headers .dtype .fields [" crossline" ][0 ].itemsize
189+
193190 raw_inline_bytes = np .frombuffer (
194- raw_data_bytes [inline_offset : inline_offset + inline_size ], dtype = np .uint8
191+ raw_data_bytes [inline_offset : inline_offset + inline_size ], dtype = np .uint8
195192 )
196193 raw_crossline_bytes = np .frombuffer (
197- raw_data_bytes [crossline_offset : crossline_offset + crossline_size ], dtype = np .uint8
194+ raw_data_bytes [crossline_offset : crossline_offset + crossline_size ], dtype = np .uint8
198195 )
199196 else :
200197 # Multiple traces case - this test uses single trace index, so extract that trace
201198 raw_data_bytes = raw_headers [0 :1 ].tobytes () # Extract first trace
202- inline_offset = raw_headers .dtype .fields [' inline' ][1 ]
203- crossline_offset = raw_headers .dtype .fields [' crossline' ][1 ]
204- inline_size = raw_headers .dtype .fields [' inline' ][0 ].itemsize
205- crossline_size = raw_headers .dtype .fields [' crossline' ][0 ].itemsize
206-
199+ inline_offset = raw_headers .dtype .fields [" inline" ][1 ]
200+ crossline_offset = raw_headers .dtype .fields [" crossline" ][1 ]
201+ inline_size = raw_headers .dtype .fields [" inline" ][0 ].itemsize
202+ crossline_size = raw_headers .dtype .fields [" crossline" ][0 ].itemsize
203+
207204 raw_inline_bytes = np .frombuffer (
208- raw_data_bytes [inline_offset : inline_offset + inline_size ], dtype = np .uint8
205+ raw_data_bytes [inline_offset : inline_offset + inline_size ], dtype = np .uint8
209206 )
210207 raw_crossline_bytes = np .frombuffer (
211- raw_data_bytes [crossline_offset : crossline_offset + crossline_size ], dtype = np .uint8
208+ raw_data_bytes [crossline_offset : crossline_offset + crossline_size ], dtype = np .uint8
212209 )
213210
214211 print (f"Transformed headers: { transformed_headers .tobytes ()} " )
@@ -217,10 +214,12 @@ def test_header_validation_configurations(
217214 print (f"Crossline bytes disk: { crossline_bytes_disk .tobytes ()} " )
218215
219216 # Compare bytes
220- assert np .array_equal (raw_inline_bytes , inline_bytes_disk ), \
217+ assert np .array_equal (raw_inline_bytes , inline_bytes_disk ), (
221218 f"Inline bytes mismatch for trace { trace_idx } in { config_name } "
222- assert np .array_equal (raw_crossline_bytes , crossline_bytes_disk ), \
219+ )
220+ assert np .array_equal (raw_crossline_bytes , crossline_bytes_disk ), (
223221 f"Crossline bytes mismatch for trace { trace_idx } in { config_name } "
222+ )
224223
225224 def test_header_validation_no_transforms (
226225 self , temp_dir : Path , basic_segy_spec : SegySpec , segy_config : dict
@@ -252,7 +251,7 @@ def test_header_validation_no_transforms(
252251 raw_headers , transformed_headers , traces = get_header_raw_and_transformed (
253252 segy_file = segy_file ,
254253 indices = slice (None ), # All traces
255- do_reverse_transforms = False
254+ do_reverse_transforms = False ,
256255 )
257256
258257 # When transforms are disabled, raw_headers should be None
@@ -262,13 +261,8 @@ def test_header_validation_no_transforms(
262261 assert transformed_headers is not None
263262 assert transformed_headers .size == num_traces
264263
265- def test_multiple_traces_validation (
266- self , temp_dir : Path , basic_segy_spec : SegySpec , segy_config : dict
267- ) -> None :
264+ def test_multiple_traces_validation (self , temp_dir : Path , basic_segy_spec : SegySpec , segy_config : dict ) -> None :
268265 """Test validation with multiple traces at once."""
269- if True :
270- import segy
271- print (segy .__version__ )
272266 config_name = segy_config ["name" ]
273267 endianness = segy_config ["endianness" ]
274268 data_format = segy_config ["data_format" ]
@@ -301,20 +295,16 @@ def test_multiple_traces_validation(
301295 raw_headers , transformed_headers , traces = get_header_raw_and_transformed (
302296 segy_file = segy_file ,
303297 indices = slice (None ), # All traces
304- do_reverse_transforms = True
298+ do_reverse_transforms = True ,
305299 )
306300
307301 first = True
308302
309303 # Validate each trace
310304 for trace_idx in range (num_traces ):
311305 # Extract bytes from disk
312- inline_bytes_disk = self .extract_header_bytes_from_file (
313- segy_path , trace_idx , 189 , 4
314- )
315- crossline_bytes_disk = self .extract_header_bytes_from_file (
316- segy_path , trace_idx , 193 , 4
317- )
306+ inline_bytes_disk = self .extract_header_bytes_from_file (segy_path , trace_idx , 189 , 4 )
307+ crossline_bytes_disk = self .extract_header_bytes_from_file (segy_path , trace_idx , 193 , 4 )
318308
319309 if first :
320310 print (raw_headers .dtype )
@@ -327,30 +317,30 @@ def test_multiple_traces_validation(
327317 if raw_headers .ndim == 0 :
328318 # Single trace case
329319 raw_data_bytes = raw_headers .tobytes ()
330- inline_offset = raw_headers .dtype .fields [' inline' ][1 ]
331- crossline_offset = raw_headers .dtype .fields [' crossline' ][1 ]
332- inline_size = raw_headers .dtype .fields [' inline' ][0 ].itemsize
333- crossline_size = raw_headers .dtype .fields [' crossline' ][0 ].itemsize
334-
320+ inline_offset = raw_headers .dtype .fields [" inline" ][1 ]
321+ crossline_offset = raw_headers .dtype .fields [" crossline" ][1 ]
322+ inline_size = raw_headers .dtype .fields [" inline" ][0 ].itemsize
323+ crossline_size = raw_headers .dtype .fields [" crossline" ][0 ].itemsize
324+
335325 raw_inline_bytes = np .frombuffer (
336- raw_data_bytes [inline_offset : inline_offset + inline_size ], dtype = np .uint8
326+ raw_data_bytes [inline_offset : inline_offset + inline_size ], dtype = np .uint8
337327 )
338328 raw_crossline_bytes = np .frombuffer (
339- raw_data_bytes [crossline_offset : crossline_offset + crossline_size ], dtype = np .uint8
329+ raw_data_bytes [crossline_offset : crossline_offset + crossline_size ], dtype = np .uint8
340330 )
341331 else :
342332 # Multiple traces case
343- raw_data_bytes = raw_headers [trace_idx : trace_idx + 1 ].tobytes ()
344- inline_offset = raw_headers .dtype .fields [' inline' ][1 ]
345- crossline_offset = raw_headers .dtype .fields [' crossline' ][1 ]
346- inline_size = raw_headers .dtype .fields [' inline' ][0 ].itemsize
347- crossline_size = raw_headers .dtype .fields [' crossline' ][0 ].itemsize
348-
333+ raw_data_bytes = raw_headers [trace_idx : trace_idx + 1 ].tobytes ()
334+ inline_offset = raw_headers .dtype .fields [" inline" ][1 ]
335+ crossline_offset = raw_headers .dtype .fields [" crossline" ][1 ]
336+ inline_size = raw_headers .dtype .fields [" inline" ][0 ].itemsize
337+ crossline_size = raw_headers .dtype .fields [" crossline" ][0 ].itemsize
338+
349339 raw_inline_bytes = np .frombuffer (
350- raw_data_bytes [inline_offset : inline_offset + inline_size ], dtype = np .uint8
340+ raw_data_bytes [inline_offset : inline_offset + inline_size ], dtype = np .uint8
351341 )
352342 raw_crossline_bytes = np .frombuffer (
353- raw_data_bytes [crossline_offset : crossline_offset + crossline_size ], dtype = np .uint8
343+ raw_data_bytes [crossline_offset : crossline_offset + crossline_size ], dtype = np .uint8
354344 )
355345
356346 print (f"Raw inline bytes: { raw_inline_bytes .tobytes ()} " )
@@ -359,18 +349,23 @@ def test_multiple_traces_validation(
359349 print (f"Crossline bytes disk: { crossline_bytes_disk .tobytes ()} " )
360350
361351 # Compare
362- assert np .array_equal (raw_inline_bytes , inline_bytes_disk ), \
352+ assert np .array_equal (raw_inline_bytes , inline_bytes_disk ), (
363353 f"Inline bytes mismatch for trace { trace_idx } in { config_name } "
364- assert np .array_equal (raw_crossline_bytes , crossline_bytes_disk ), \
354+ )
355+ assert np .array_equal (raw_crossline_bytes , crossline_bytes_disk ), (
365356 f"Crossline bytes mismatch for trace { trace_idx } in { config_name } "
357+ )
366358
367- @pytest .mark .parametrize ("trace_indices" , [
368- 0 , # Single trace
369- [0 , 2 , 4 ], # Multiple specific traces
370- slice (1 , 4 ), # Range of traces
371- ])
359+ @pytest .mark .parametrize (
360+ "trace_indices" ,
361+ [
362+ 0 , # Single trace
363+ [0 , 2 , 4 ], # Multiple specific traces
364+ slice (1 , 4 ), # Range of traces
365+ ],
366+ )
372367 def test_different_index_types (
373- self , temp_dir : Path , basic_segy_spec : SegySpec , segy_config : dict , trace_indices
368+ self , temp_dir : Path , basic_segy_spec : SegySpec , segy_config : dict , trace_indices : int | list [ int ] | slice
374369 ) -> None :
375370 """Test with different types of trace indices."""
376371 config_name = segy_config ["name" ]
@@ -397,9 +392,7 @@ def test_different_index_types(
397392
398393 # Get headers with different index types
399394 raw_headers , transformed_headers , traces = get_header_raw_and_transformed (
400- segy_file = segy_file ,
401- indices = trace_indices ,
402- do_reverse_transforms = True
395+ segy_file = segy_file , indices = trace_indices , do_reverse_transforms = True
403396 )
404397
405398 # Basic validation that we got results
0 commit comments