Пример #1
0
    def testBatchGenerator(self):
        result = upload_symbols.BatchGenerator([], 2)
        self.assertEqual(list(result), [])

        result = upload_symbols.BatchGenerator(xrange(6), 2)
        self.assertEqual(list(result), [[0, 1], [2, 3], [4, 5]])

        result = upload_symbols.BatchGenerator(xrange(7), 2)
        self.assertEqual(list(result), [[0, 1], [2, 3], [4, 5], [6]])

        # Prove that we are streaming the results, not generating them all at once.
        result = upload_symbols.BatchGenerator(itertools.repeat(0), 2)
        self.assertEqual(result.next(), [0, 0])
Пример #2
0
    def testBatchGenerator(self):
        result = upload_symbols.BatchGenerator([], 2)
        self.assertEqual(list(result), [])

        # BatchGenerator accepts iterators, so passing it here is safe.
        # pylint: disable=range-builtin-not-iterating
        result = upload_symbols.BatchGenerator(range(6), 2)
        self.assertEqual(list(result), [[0, 1], [2, 3], [4, 5]])

        result = upload_symbols.BatchGenerator(range(7), 2)
        self.assertEqual(list(result), [[0, 1], [2, 3], [4, 5], [6]])

        # Prove that we are streaming the results, not generating them all at once.
        result = upload_symbols.BatchGenerator(itertools.repeat(0), 2)
        self.assertEqual(next(result), [0, 0])