1
+ import dataclasses
1
2
import json
2
3
from unittest import mock
3
4
47
48
DEFAULT_DENCODE_FINALISE_ARGS = dict (show_progress = True )
48
49
49
50
51
+ @dataclasses .dataclass
52
+ class FakeWorkSummary :
53
+ num_partitions : int
54
+
55
+ def asdict (self ):
56
+ return dataclasses .asdict (self )
57
+
58
+ def asjson (self ):
59
+ return json .dumps (self .asdict ())
60
+
61
+
50
62
class TestWithMocks :
51
63
vcf_path = "tests/data/vcf/sample.vcf.gz"
52
64
@@ -263,7 +275,7 @@ def test_vcf_explode_missing_and_existing_vcf(self, mocked, tmp_path):
263
275
assert "'no_such_file' does not exist" in result .stderr
264
276
mocked .assert_not_called ()
265
277
266
- @mock .patch ("bio2zarr.vcf.explode_init" , return_value = 5 )
278
+ @mock .patch ("bio2zarr.vcf.explode_init" , return_value = FakeWorkSummary ( 5 ) )
267
279
def test_vcf_dexplode_init (self , mocked , tmp_path ):
268
280
runner = ct .CliRunner (mix_stderr = False )
269
281
icf_path = tmp_path / "icf"
@@ -274,7 +286,7 @@ def test_vcf_dexplode_init(self, mocked, tmp_path):
274
286
)
275
287
assert result .exit_code == 0
276
288
assert len (result .stderr ) == 0
277
- assert result .stdout == "5 \n "
289
+ assert list ( result .stdout . split ()) == [ "num_partitions" , "5" ]
278
290
mocked .assert_called_once_with (
279
291
str (icf_path ),
280
292
(self .vcf_path ,),
@@ -416,7 +428,7 @@ def test_encode(self, mocked, tmp_path):
416
428
** DEFAULT_ENCODE_ARGS ,
417
429
)
418
430
419
- @mock .patch ("bio2zarr.vcf.encode_init" , return_value = (10 , 1024 ))
431
+ @mock .patch ("bio2zarr.vcf.encode_init" , return_value = FakeWorkSummary (10 ))
420
432
def test_dencode_init (self , mocked , tmp_path ):
421
433
icf_path = tmp_path / "icf"
422
434
icf_path .mkdir ()
@@ -428,7 +440,7 @@ def test_dencode_init(self, mocked, tmp_path):
428
440
catch_exceptions = False ,
429
441
)
430
442
assert result .exit_code == 0
431
- assert result .stdout == "10 \t 1 KiB \n "
443
+ assert list ( result .stdout . split ()) == [ "num_partitions" , "10" ]
432
444
assert len (result .stderr ) == 0
433
445
mocked .assert_called_once_with (
434
446
str (icf_path ),
@@ -534,7 +546,7 @@ def test_dexplode(self, tmp_path, one_based):
534
546
catch_exceptions = False ,
535
547
)
536
548
assert result .exit_code == 0
537
- assert json .loads (result .stdout )["partitions " ] == 3
549
+ assert json .loads (result .stdout )["num_partitions " ] == 3
538
550
539
551
for j in range (3 ):
540
552
if one_based :
@@ -603,7 +615,7 @@ def test_dencode(self, tmp_path, one_based):
603
615
catch_exceptions = False ,
604
616
)
605
617
assert result .exit_code == 0
606
- assert json .loads (result .stdout )["partitions " ] == 3
618
+ assert json .loads (result .stdout )["num_partitions " ] == 3
607
619
608
620
for j in range (3 ):
609
621
if one_based :
0 commit comments