Files
pytorch/.github/scripts/test_gitutils.py
Jane Xu c67a4d8a65 [GH1] replace globs with patterns that mergebot can process (#81414)
https://github.com/pytorch/pytorch/pull/81330#issuecomment-1182345751 shouldn't have happened and should have matched the linalg rule.

The reason it happened is cuz we don't treat the patterns like globs.

We may follow this up with a BE change to make the patterns be treated more like globs, which I expected originally.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/81414
Approved by: https://github.com/malfet
2022-07-19 16:11:32 +00:00

40 lines
1.3 KiB
Python

#!/usr/bin/env python3
from gitutils import PeekableIterator, patterns_to_regex
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)
class TestPattern(TestCase):
def test_double_asterisks(self) -> None:
allowed_patterns = [
"aten/src/ATen/native/**LinearAlgebra*",
]
patterns_re = patterns_to_regex(allowed_patterns)
fnames = [
"aten/src/ATen/native/LinearAlgebra.cpp",
"aten/src/ATen/native/cpu/LinearAlgebraKernel.cpp"]
for filename in fnames:
self.assertTrue(patterns_re.match(filename))
if __name__ == '__main__':
main()