-
Notifications
You must be signed in to change notification settings - Fork 6
Update islice
to align behavior closer to CP
#23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
.. | ||
SPDX-FileCopyrightText: KB Sriram | ||
SPDX-License-Identifier: MIT | ||
.. | ||
|
||
Itertools Tests | ||
=============== | ||
|
||
These tests run under CPython, and are intended to verify that the | ||
Adafruit library functions return the same outputs compared to ones in | ||
the standard `itertools` module. | ||
|
||
These tests run automatically from the standard `circuitpython github | ||
workflow <wf_>`_. To run them manually, first install these packages | ||
if necessary:: | ||
|
||
$ pip3 install pytest | ||
|
||
Then ensure you're in the *root* directory of the repository and run | ||
the following command:: | ||
|
||
$ python -m pytest | ||
|
||
.. _wf: https://github.com/adafruit/workflows-circuitpython-libs/blob/6e1562eaabced4db1bd91173b698b1cc1dfd35ab/build/action.yml#L78-L84 |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# SPDX-FileCopyrightText: KB Sriram | ||
# SPDX-License-Identifier: MIT | ||
|
||
from typing import Iterator, Optional, Sequence, TypeVar | ||
import itertools as it | ||
import pytest | ||
import adafruit_itertools as ait | ||
|
||
_T = TypeVar("_T") | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"seq, start", | ||
[ | ||
("", 0), | ||
("", 2), | ||
("ABCDEFG", 0), | ||
("ABCDEFG", 2), | ||
("ABCDEFG", 20), | ||
], | ||
) | ||
def test_islice_start(seq: Sequence[_T], start: int) -> None: | ||
x: Iterator[_T] = ait.islice(seq, start) | ||
y: Iterator[_T] = it.islice(seq, start) | ||
assert list(x) == list(y) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"seq, start, stop", | ||
[ | ||
("", 0, 5), | ||
("", 2, 5), | ||
("", 0, 0), | ||
("ABCDEFG", 2, 2), | ||
("ABCDEFG", 2, 6), | ||
("ABCDEFG", 2, None), | ||
("ABCDEFG", 2, 17), | ||
("ABCDEFG", 20, 30), | ||
], | ||
) | ||
def test_islice_start_stop(seq: Sequence[_T], start: int, stop: Optional[int]) -> None: | ||
x: Iterator[_T] = ait.islice(seq, start, stop) | ||
y: Iterator[_T] = it.islice(seq, start, stop) | ||
assert list(x) == list(y) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"seq, start, stop, step", | ||
[ | ||
("", 0, 5, 3), | ||
("", 2, 5, 2), | ||
("", 0, 0, 1), | ||
("ABCDEFG", 2, 2, 2), | ||
("ABCDEFG", 2, 6, 3), | ||
("ABCDEFG", 2, 17, 2), | ||
("ABCDEFG", 0, None, 2), | ||
("ABCDEFG", 20, 30, 3), | ||
("ABCDEFG", 0, None, 3), | ||
], | ||
) | ||
def test_islice_start_stop_step( | ||
seq: Sequence[_T], start: int, stop: Optional[int], step: int | ||
) -> None: | ||
x: Iterator[_T] = ait.islice(seq, start, stop, step) | ||
y: Iterator[_T] = it.islice(seq, start, stop, step) | ||
assert list(x) == list(y) | ||
|
||
|
||
def test_islice_error() -> None: | ||
with pytest.raises(ValueError): | ||
list(ait.islice("abc", -1)) | ||
with pytest.raises(ValueError): | ||
list(ait.islice("abc", 0, -1)) | ||
with pytest.raises(ValueError): | ||
list(ait.islice("abc", 0, 0, 0)) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.