def test_batch_negative_index(self): """Test batch function with negative val for stop/start index""" max_val = 101 vals = list(range(max_val)) res = list(common_utils.batch(vals, stop=-1, _slice=10)) self.assertEqual(len(res), (max_val // len(res[0]))) res = list(common_utils.batch(vals, start=-1, _slice=10)) self.assertEqual(len(res), 1)
def test_batch(self): """Test batch function with default kwargs""" max_val = 101 vals = list(range(max_val)) res = list(common_utils.batch(vals)) self.assertEqual(len(res), max_val) self.assertTrue(all(len(e) == 1 for e in res))
def test_batch_value_error(self): """Test batch function with bad strings for index""" max_val = 101 vals = list(range(max_val)) with self.assertRaises(ValueError): _ = list(common_utils.batch(vals, start="eek"))
def test_batch_str_index(self): """Test batch function with number strings for indexes""" max_val = 101 vals = list(range(max_val)) res = list(common_utils.batch(vals, start="0", stop="10")) self.assertEqual(len(res), 10)
def test_batch_stop_lt_start(self): """Test batch function with stop_ix < start_ix""" max_val = 101 vals = list(range(max_val)) res = list(common_utils.batch(vals, start=10, stop=9)) self.assertEqual(res, [])
def test_batch_stop_gt_len(self): """Test batch function with stop index > len(iterable)""" max_val = 101 vals = list(range(max_val)) res = list(common_utils.batch(vals, stop=10000, _slice=10)) self.assertEqual(len(res), 11)
def test_batch_empty(self): """Test batch function with empty iterable""" res = list(common_utils.batch([])) self.assertEqual(res, [])
def test_batch_start_none(self): """Test batch function with None start index""" max_val = 101 vals = list(range(max_val)) res = list(common_utils.batch(vals, start=None)) self.assertEqual(len(res), 101)
def test_batch_start_index(self): """Test batch function with positive start index""" max_val = 101 vals = list(range(max_val)) res = list(common_utils.batch(vals, start=10)) self.assertEqual(len(res), max_val - 10)
def test_batch_set(self): """Test batch function using set as iterable""" max_val = 101 vals = list(range(max_val)) res = list(common_utils.batch(set(vals), _slice=10)) self.assertEqual(len(res), 11)