forked from iterative/dvc
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
utils: extend to_chunks functionality, can specify number of chunks o…
…r length of chunk
- Loading branch information
Showing
6 changed files
with
56 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,30 @@ | ||
import pytest | ||
|
||
from dvc.utils import chunk | ||
from dvc.utils import to_chunks | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"list_to_chunk, chunk_size, expected_chunks", | ||
[ | ||
([1, 2, 3, 4], 1, [[1], [2], [3], [4]]), | ||
([1, 2, 3, 4], 2, [[1, 2], [3, 4]]), | ||
([1, 2, 3, 4], 3, [[1, 2, 3], [4]]), | ||
], | ||
"chunk_size, expected_chunks", | ||
[(1, [[1], [2], [3], [4]]), (2, [[1, 2], [3, 4]]), (3, [[1, 2, 3], [4]])], | ||
) | ||
def test_chunk(list_to_chunk, chunk_size, expected_chunks): | ||
result = list(chunk(list_to_chunk, chunk_size)) | ||
def test_to_chunks_chunk_size(chunk_size, expected_chunks): | ||
list_to_chunk = [1, 2, 3, 4] | ||
result = list(to_chunks(list_to_chunk, chunk_size=chunk_size)) | ||
assert result == expected_chunks | ||
|
||
|
||
@pytest.mark.parametrize("num_chunks, chunk_size", [(1, 2), (None, None)]) | ||
def test_to_chunks_should_raise(num_chunks, chunk_size): | ||
list_to_chunk = [1, 2, 3] | ||
with pytest.raises(ValueError): | ||
to_chunks(list_to_chunk, num_chunks, chunk_size) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"num_chunks, expected_chunks", | ||
[(4, [[1], [2], [3], [4]]), (3, [[1, 2], [3, 4]]), (2, [[1, 2], [3, 4]])], | ||
) | ||
def test_to_chunks_num_chunks(num_chunks, expected_chunks): | ||
list_to_chunk = [1, 2, 3, 4] | ||
result = to_chunks(list_to_chunk, num_chunks=num_chunks) | ||
assert result == expected_chunks |