mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
Summary:
Test PeekableIterator behavior
Add `.github/scripts/test_*.py` to list of tests run by test_tools
workflow and pin Python version to 3.7 in test_tools workflow
Change PeekableIterator inheritance from collections.abc.Iterator, to
typing.Iterator, which is a correct alias starting from Python-3.7
Pull Request resolved: https://github.com/pytorch/pytorch/pull/71580
Reviewed By: bigfootjon
Differential Revision: D33690659
Pulled By: malfet
fbshipit-source-id: 71f270b15138230772e2eed0da66cdfcb34825cc
(cherry picked from commit 42abb07396)
28 lines
853 B
Python
28 lines
853 B
Python
#!/usr/bin/env python3
|
|
from gitutils import PeekableIterator
|
|
from unittest import TestCase, main
|
|
|
|
class TestPeekableIterator(TestCase):
|
|
def test_iterator(self, input_: str = "abcdef") -> None:
|
|
iter_ = PeekableIterator(input_)
|
|
for idx, c in enumerate(iter_):
|
|
self.assertEqual(c, input_[idx])
|
|
|
|
def test_is_iterable(self) -> None:
|
|
from collections.abc import Iterator
|
|
iter_ = PeekableIterator("")
|
|
self.assertTrue(isinstance(iter_, Iterator))
|
|
|
|
def test_peek(self, input_: str = "abcdef") -> None:
|
|
iter_ = PeekableIterator(input_)
|
|
for idx, c in enumerate(iter_):
|
|
if idx + 1 < len(input_):
|
|
self.assertEqual(iter_.peek(), input_[idx + 1])
|
|
else:
|
|
self.assertTrue(iter_.peek() is None)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|