view tests/test_chunk.py @ 18:56596902e9ae default tip

add some setup + tests
author Jeff Hammel <k0scist@gmail.com>
date Sun, 10 Dec 2017 17:57:03 -0800
parents
children
line wrap: on
line source

#!/usr/bin/env python

"""
test data chunking
"""

import os
import unittest
from lemuriformes.chunk import chunk

class TestChunking(unittest.TestCase):

    def test_range(self):
        """test basic chunking with range function"""

        data = list(range(64))
        chunked = list(chunk(data, 10))
        assert len(chunked) == 7
        sizes = set([len(c) for c in
                     chunked[:-1]])
        assert len(sizes) == 1
        assert sizes.pop() == 10
        reconstructed = []
        for _chunk in chunked:
            reconstructed.extend(_chunk)
        assert reconstructed == list(range(64))


if __name__ == '__main__':
    unittest.main()