47
47
48
48
DEFAULT_DENCODE_FINALISE_ARGS = dict (show_progress = True )
49
49
50
+ DEFAULT_CONVERT_ARGS = dict (
51
+ variants_chunk_size = None ,
52
+ samples_chunk_size = None ,
53
+ show_progress = True ,
54
+ worker_processes = 1 ,
55
+ )
56
+
50
57
51
58
@dataclasses .dataclass
52
59
class FakeWorkSummary :
@@ -508,11 +515,24 @@ def test_convert_vcf(self, mocked):
508
515
mocked .assert_called_once_with (
509
516
(self .vcf_path ,),
510
517
"zarr_path" ,
511
- variants_chunk_size = None ,
512
- samples_chunk_size = None ,
513
- worker_processes = 1 ,
514
- show_progress = True ,
518
+ ** DEFAULT_CONVERT_ARGS ,
519
+ )
520
+
521
+ @pytest .mark .parametrize ("response" , ["n" , "N" , "No" ])
522
+ @mock .patch ("bio2zarr.vcf.convert" )
523
+ def test_vcf_convert_overwrite_zarr_confirm_no (self , mocked , tmp_path , response ):
524
+ zarr_path = tmp_path / "zarr"
525
+ zarr_path .mkdir ()
526
+ runner = ct .CliRunner (mix_stderr = False )
527
+ result = runner .invoke (
528
+ cli .vcf2zarr ,
529
+ f"convert { self .vcf_path } { zarr_path } " ,
530
+ catch_exceptions = False ,
531
+ input = response ,
515
532
)
533
+ assert result .exit_code == 1
534
+ assert "Aborted" in result .stderr
535
+ mocked .assert_not_called ()
516
536
517
537
@mock .patch ("bio2zarr.plink.convert" )
518
538
def test_convert_plink (self , mocked ):
@@ -523,13 +543,25 @@ def test_convert_plink(self, mocked):
523
543
assert result .exit_code == 0
524
544
assert len (result .stdout ) == 0
525
545
assert len (result .stderr ) == 0
546
+ mocked .assert_called_once_with ("in" , "out" , ** DEFAULT_CONVERT_ARGS )
547
+
548
+ @pytest .mark .parametrize ("response" , ["y" , "Y" , "yes" ])
549
+ @mock .patch ("bio2zarr.vcf.convert" )
550
+ def test_vcf_convert_overwrite_zarr_confirm_yes (self , mocked , tmp_path , response ):
551
+ zarr_path = tmp_path / "zarr"
552
+ zarr_path .mkdir ()
553
+ runner = ct .CliRunner (mix_stderr = False )
554
+ result = runner .invoke (
555
+ cli .vcf2zarr ,
556
+ f"convert { self .vcf_path } { zarr_path } " ,
557
+ catch_exceptions = False ,
558
+ input = response ,
559
+ )
560
+ assert result .exit_code == 0
561
+ assert f"Do you want to overwrite { zarr_path } " in result .stdout
562
+ assert len (result .stderr ) == 0
526
563
mocked .assert_called_once_with (
527
- "in" ,
528
- "out" ,
529
- worker_processes = 1 ,
530
- samples_chunk_size = None ,
531
- variants_chunk_size = None ,
532
- show_progress = True ,
564
+ (self .vcf_path ,), str (zarr_path ), ** DEFAULT_CONVERT_ARGS
533
565
)
534
566
535
567
0 commit comments