@@ -341,6 +341,71 @@ def test_unphased_default_matches_in_process(self, fx_reader, fx_small_vcz):
341341 assert data == ref_data
342342
343343
344+ class TestBgenTotalStringLengthPlumbing :
345+ """``--total-string-length`` flows through to ``BgenEncoder``.
346+
347+ Compared against an in-process ``BgenEncoder`` built with the same
348+ kwarg, the streamed bytes must be identical.
349+ """
350+
351+ def test_default_matches_in_process (self , fx_reader , fx_small_vcz ):
352+ opts = vcztools .ViewBgenOptions ()
353+ assert opts .total_string_length is None
354+ with formats .BGEN_SPEC .encoder_factory (fx_reader , opts ) as encoder :
355+ data = encoder .read (0 , encoder .total_size )
356+ ref_reader = _open_reader (fx_small_vcz .path )
357+ with vcztools .BgenEncoder (ref_reader ) as ref :
358+ ref_data = ref .read (0 , ref .total_size )
359+ assert data == ref_data
360+
361+ def test_explicit_value_matches_in_process (self , fx_reader , fx_small_vcz ):
362+ opts = vcztools .ViewBgenOptions (total_string_length = 128 )
363+ with formats .BGEN_SPEC .encoder_factory (fx_reader , opts ) as encoder :
364+ data = encoder .read (0 , encoder .total_size )
365+ ref_reader = _open_reader (fx_small_vcz .path )
366+ with vcztools .BgenEncoder (ref_reader , total_string_length = 128 ) as ref :
367+ ref_data = ref .read (0 , ref .total_size )
368+ assert data == ref_data
369+
370+ def test_budget_too_small_raises (self , fx_reader ):
371+ opts = vcztools .ViewBgenOptions (total_string_length = 1 )
372+ with pytest .raises (ValueError , match = "total_string_length" ):
373+ with formats .BGEN_SPEC .encoder_factory (fx_reader , opts ) as encoder :
374+ encoder .read (0 , encoder .total_size )
375+
376+
377+ class TestBgenPadBytePlumbing :
378+ """``--pad-byte`` flows through to ``BgenEncoder(pad_byte=...)``."""
379+
380+ def test_default_matches_in_process (self , fx_reader , fx_small_vcz ):
381+ opts = vcztools .ViewBgenOptions ()
382+ assert opts .pad_byte is None
383+ with formats .BGEN_SPEC .encoder_factory (fx_reader , opts ) as encoder :
384+ data = encoder .read (0 , encoder .total_size )
385+ ref_reader = _open_reader (fx_small_vcz .path )
386+ with vcztools .BgenEncoder (ref_reader ) as ref :
387+ ref_data = ref .read (0 , ref .total_size )
388+ assert data == ref_data
389+
390+ def test_explicit_pad_byte_matches_in_process (self , fx_reader , fx_small_vcz ):
391+ opts = vcztools .ViewBgenOptions (pad_byte = b"X" )
392+ with formats .BGEN_SPEC .encoder_factory (fx_reader , opts ) as encoder :
393+ data = encoder .read (0 , encoder .total_size )
394+ ref_reader = _open_reader (fx_small_vcz .path )
395+ with vcztools .BgenEncoder (ref_reader , pad_byte = b"X" ) as ref :
396+ ref_data = ref .read (0 , ref .total_size )
397+ assert data == ref_data
398+
399+ def test_pad_byte_changes_bytes (self , fx_reader ):
400+ opts_default = vcztools .ViewBgenOptions ()
401+ opts_x = vcztools .ViewBgenOptions (pad_byte = b"X" )
402+ with formats .BGEN_SPEC .encoder_factory (fx_reader , opts_default ) as encoder :
403+ data_default = encoder .read (0 , encoder .total_size )
404+ with formats .BGEN_SPEC .encoder_factory (fx_reader , opts_x ) as encoder :
405+ data_x = encoder .read (0 , encoder .total_size )
406+ assert data_default != data_x
407+
408+
344409class TestSpecsRegistry :
345410 def test_specs_dict_has_both_entries (self ):
346411 assert formats .SPECS == {"plink" : formats .PLINK_SPEC , "bgen" : formats .BGEN_SPEC }
0 commit comments