11# MIT License
22#
3- # Copyright (c) 2019 Tskit Developers
3+ # Copyright (c) 2019-2026 Tskit Developers
44#
55# Permission is hereby granted, free of charge, to any person obtaining a copy
66# of this software and associated documentation files (the "Software"), to deal
3434
3535import tszip
3636import tszip .cli as cli
37+ from tszip import compat
3738
3839
3940def get_stdout_for_pytest ():
@@ -98,6 +99,7 @@ def test_default_values(self):
9899 self .assertEqual (args .decompress , False )
99100 self .assertEqual (args .list , False )
100101 self .assertEqual (args .stdout , False )
102+ self .assertEqual (args .chunk_size , tszip .DEFAULT_CHUNK_SIZE )
101103 self .assertEqual (args .variants_only , False )
102104 self .assertEqual (args .suffix , ".tsz" )
103105
@@ -123,6 +125,14 @@ def test_decompress(self):
123125 args = parser .parse_args ([infile , "--decompress" ])
124126 self .assertTrue (args .decompress )
125127
128+ def test_chunk_size (self ):
129+ parser = cli .tszip_cli_parser ()
130+ infile = "tmp.trees.tsz"
131+ args = parser .parse_args ([infile , "-C" , "1234" ])
132+ self .assertEqual (args .chunk_size , 1234 )
133+ args = parser .parse_args ([infile , "--chunk-size=1234" ])
134+ self .assertTrue (args .chunk_size , 1234 )
135+
126136
127137class TestCli (unittest .TestCase ):
128138 """
@@ -248,6 +258,20 @@ def test_variants_only(self):
248258 G2 = self .ts .genotype_matrix ()
249259 self .assertTrue (np .array_equal (G1 , G2 ))
250260
261+ def test_chunk_size (self ):
262+ self .assertTrue (self .trees_path .exists ())
263+ self .run_tszip ([str (self .trees_path ), "--chunk-size=20" ])
264+ self .assertFalse (self .trees_path .exists ())
265+ outpath = pathlib .Path (str (self .trees_path ) + ".tsz" )
266+ self .assertTrue (outpath .exists ())
267+ ts = tszip .decompress (outpath )
268+ self .assertEqual (ts .tables , self .ts .tables )
269+ store = compat .create_zip_store (str (outpath ), mode = "r" )
270+ root = compat .create_zarr_group (store = store )
271+ for _ , g in root .groups ():
272+ for _ , a in g .arrays ():
273+ assert a .chunks == (20 ,)
274+
251275 def test_keep (self ):
252276 self .assertTrue (self .trees_path .exists ())
253277 self .run_tszip ([str (self .trees_path ), "--keep" ])
0 commit comments