Exemple #1
0
    def test_n__greater_than_iterable_length(self):
        batched = __unit__.batch(
            self.WITHOUT_LEFTOVERS, len(self.WITHOUT_LEFTOVERS) + self.N)

        self._assertGenerator(batched)
        batched = list(batched)

        self.assertEquals(1, len(batched))
        self.assertItemsEqual(self.WITHOUT_LEFTOVERS, batched[0])
Exemple #2
0
    def test_n__greater_than_iterable_length(self):
        batched = __unit__.batch(self.WITHOUT_LEFTOVERS,
                                 len(self.WITHOUT_LEFTOVERS) + self.N)

        self._assertGenerator(batched)
        batched = list(batched)

        self.assertEquals(1, len(batched))
        self.assertItemsEqual(self.WITHOUT_LEFTOVERS, batched[0])
Exemple #3
0
    def test_iterable__with_leftovers__trimmed(self):
        batched = __unit__.batch(self.WITH_LEFTOVERS, self.N)

        self._assertGenerator(batched)
        batched = list(batched)

        self.assertEquals(
            int(len(self.WITH_LEFTOVERS) / self.N) + 1, len(batched))
        for i, batch in enumerate(batched):
            self._assertTuple(batch)
            self.assertGreaterEqual(self.N, len(batch))
            self.assertItemsEqual(
                self.WITH_LEFTOVERS[i * self.N:(i + 1) * self.N], batch)
Exemple #4
0
    def test_iterable__with_leftovers__trimmed(self):
        batched = __unit__.batch(self.WITH_LEFTOVERS, self.N)

        self._assertGenerator(batched)
        batched = list(batched)

        self.assertEquals(
            int(len(self.WITH_LEFTOVERS) / self.N) + 1, len(batched))
        for i, batch in enumerate(batched):
            self._assertTuple(batch)
            self.assertGreaterEqual(self.N, len(batch))
            self.assertItemsEqual(
                self.WITH_LEFTOVERS[i * self.N:(i + 1) * self.N], batch)
Exemple #5
0
    def test_iterable__with_leftovers__padded(self):
        batched = __unit__.batch(self.WITH_LEFTOVERS, self.N, self.FILLVALUE)

        self._assertGenerator(batched)
        batched = list(batched)

        self.assertEquals(
            int(len(self.WITH_LEFTOVERS) / self.N) + 1, len(batched))
        for i, batch in enumerate(batched):
            self._assertTuple(batch)
            self.assertEquals(self.N, len(batch))
            for j, elem in enumerate(batch):
                index = i * self.N + j
                if index < len(self.WITH_LEFTOVERS):
                    self.assertEquals(self.WITH_LEFTOVERS[index], elem)
                else:
                    self.assertIs(self.FILLVALUE, elem)
Exemple #6
0
    def test_iterable__with_leftovers__padded(self):
        batched = __unit__.batch(self.WITH_LEFTOVERS, self.N, self.FILLVALUE)

        self._assertGenerator(batched)
        batched = list(batched)

        self.assertEquals(
            int(len(self.WITH_LEFTOVERS) / self.N) + 1, len(batched))
        for i, batch in enumerate(batched):
            self._assertTuple(batch)
            self.assertEquals(self.N, len(batch))
            for j, elem in enumerate(batch):
                index = i * self.N + j
                if index < len(self.WITH_LEFTOVERS):
                    self.assertEquals(self.WITH_LEFTOVERS[index], elem)
                else:
                    self.assertIs(self.FILLVALUE, elem)
Exemple #7
0
 def test_n__negative(self):
     with self.assertRaises(ValueError):
         __unit__.batch(self.WITH_LEFTOVERS, -1)
Exemple #8
0
 def test_n__zero(self):
     with self.assertRaises(ValueError):
         __unit__.batch(self.WITH_LEFTOVERS, 0)
Exemple #9
0
 def test_n__none(self):
     with self.assertRaises(TypeError):
         __unit__.batch(self.WITH_LEFTOVERS, None)
Exemple #10
0
 def test_iterable__some_object(self):
     with self.assertRaises(TypeError):
         __unit__.batch(object(), 1)
Exemple #11
0
 def test_iterable__none(self):
     with self.assertRaises(TypeError):
         __unit__.batch(None, 1)
Exemple #12
0
 def test_n__negative(self):
     with self.assertRaises(ValueError):
         __unit__.batch(self.WITH_LEFTOVERS, -1)
Exemple #13
0
 def test_n__zero(self):
     with self.assertRaises(ValueError):
         __unit__.batch(self.WITH_LEFTOVERS, 0)
Exemple #14
0
 def test_n__none(self):
     with self.assertRaises(TypeError):
         __unit__.batch(self.WITH_LEFTOVERS, None)
Exemple #15
0
 def test_iterable__some_object(self):
     with self.assertRaises(TypeError):
         __unit__.batch(object(), 1)
Exemple #16
0
 def test_iterable__none(self):
     with self.assertRaises(TypeError):
         __unit__.batch(None, 1)