Ejemplo n.º 1
0
 def test_chunk_size_none(self):
     """
     Test chunks with parameter chunk_size equals None.
     Should raise ValueError.
     """
     with pytest.raises(ValueError):
         list(chunks(list(range(10)), None))
Ejemplo n.º 2
0
 def test_invalid_chunk_size_types(self):
     """
     Test chunks with invalid type of parameter chunk_size.
     """
     types = [19.84, tuple(), list(), dict(), set(), "string"]
     for t in types:
         with pytest.raises(TypeError):
             list(chunks(list(range(10)), t))
Ejemplo n.º 3
0
 def test_invalid_lst_types(self):
     """
     Test chunks with invalid types of parameter L.
     """
     types = [19.84, 1970, tuple(), dict(), set()]
     for t in types:
         with pytest.raises(TypeError):
             list(chunks(t, 10))
Ejemplo n.º 4
0
    def test_valid(self):
        """
        Test chunks with valid parameters.
        """
        lst = list(range(1000))
        chunk_size = 10
        chunk_list = list(chunks(lst, chunk_size))

        # expect 100 chunks of len 10
        assert len(chunk_list) == 100
        assert all(len(chunk) == 10 for chunk in chunk_list)

        lst = list(range(100))
        chunk_size = 100
        chunk_list = list(chunks(lst, chunk_size))
        # expect 1 chunk of len 100
        assert len(chunk_list) == 1
        assert all(len(chunk) == 100 for chunk in chunk_list)