Esempio n. 1
0
 def it_uses_batch_size():
     with zest.mock(zap._cpu_count) as m:
         sl = zap._make_batch_slices(_batch_size=2,
                                     n_rows=6,
                                     _limit_slice=None)
         assert sl == [(0, 2), (2, 4), (4, 6)]
     assert not m.called()
Esempio n. 2
0
 def it_limits_from_start():
     sl = zap._make_batch_slices(_batch_size=2,
                                 n_rows=6,
                                 _limit_slice=slice(2, 6))
     assert sl == [
         (2, 4),
         (4, 6),
     ]
Esempio n. 3
0
 def it_solves_for_batch_size_by_scaling_the_cpu_count():
     with zest.mock(zap._cpu_count, returns=2):
         sl = zap._make_batch_slices(_batch_size=None,
                                     n_rows=32,
                                     _limit_slice=None)
         assert sl == [
             (0, 3),
             (3, 6),
             (6, 9),
             (9, 12),
             (12, 15),
             (15, 18),
             (18, 21),
             (21, 24),
             (24, 27),
             (27, 30),
             (30, 32),
         ]
Esempio n. 4
0
 def it_raises_on_illegal_batch_size():
     with zest.raises(ValueError):
         zap._make_batch_slices(_batch_size=-5,
                                n_rows=10,
                                _limit_slice=None)
Esempio n. 5
0
 def it_handles_zero_rows():
     sl = zap._make_batch_slices(_batch_size=10,
                                 n_rows=0,
                                 _limit_slice=None)
     assert sl == []
Esempio n. 6
0
 def it_handles_one_large_batch():
     sl = zap._make_batch_slices(_batch_size=10,
                                 n_rows=6,
                                 _limit_slice=None)
     assert sl == [(0, 6)]
Esempio n. 7
0
 def it_handles_odd():
     sl = zap._make_batch_slices(_batch_size=5, n_rows=6, _limit_slice=None)
     assert sl == [(0, 5), (5, 6)]
Esempio n. 8
0
 def it_solves_for_batch_size_by_scaling_the_cpu_count_and_clamps():
     with zest.mock(zap._cpu_count, returns=2):
         sl = zap._make_batch_slices(_batch_size=None,
                                     n_rows=6,
                                     _limit_slice=None)
         assert sl == [(0, 2), (2, 4), (4, 6)]