Mercurial > hgrepos > Python > apps > py-cutils
comparison tests/test_match.py @ 296:ca293f708cb4
Begin some preparation for handling glob-style patterns in treeview.
Needed to implement inclusions and exclusions.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sun, 02 Mar 2025 22:54:40 +0100 |
| parents | |
| children | 141a3aa0b403 |
comparison
equal
deleted
inserted
replaced
| 295:4a259fb9968e | 296:ca293f708cb4 |
|---|---|
| 1 # -*- coding: utf-8 -*- | |
| 2 r"""Unit tests for :mod:`cutils.util.glob` | |
| 3 | |
| 4 """ | |
| 5 | |
| 6 from __future__ import absolute_import, print_function | |
| 7 | |
| 8 import _test_setup # noqa: F401 imported but unused | |
| 9 | |
| 10 import sys | |
| 11 import unittest | |
| 12 | |
| 13 from cutils.util.glob import CharIter | |
| 14 | |
| 15 | |
| 16 class TestCharIter(unittest.TestCase): | |
| 17 | |
| 18 def test_transitive_iter(self): | |
| 19 it = CharIter("1234") | |
| 20 self.assertIs(iter(it), it) | |
| 21 | |
| 22 def test_native_str(self): | |
| 23 it = CharIter("1234") | |
| 24 chars = [] | |
| 25 for c in it: | |
| 26 chars.append(c) | |
| 27 self.assertEqual("1234", "".join(chars)) | |
| 28 | |
| 29 def test_unicode_str(self): | |
| 30 it = CharIter(u"1234") | |
| 31 chars = [] | |
| 32 for c in it: | |
| 33 chars.append(c) | |
| 34 self.assertEqual(u"1234", "".join(chars)) | |
| 35 | |
| 36 def test_byte_str(self): | |
| 37 it = CharIter(b"1234") | |
| 38 chars = [] | |
| 39 for c in it: | |
| 40 chars.append(c) | |
| 41 self.assertEqual(b"1234", b"".join(chars)) | |
| 42 | |
| 43 def test_peek_exhausted(self): | |
| 44 it = CharIter("1234") | |
| 45 for _ in it: | |
| 46 pass | |
| 47 self.assertIsNone(it.peek()) | |
| 48 | |
| 49 def test_peek_first(self): | |
| 50 it = CharIter("1234") | |
| 51 self.assertEqual("1", it.peek()) | |
| 52 chars = "".join(it) | |
| 53 self.assertEqual("1234", chars) | |
| 54 self.assertIsNone(it.peek()) | |
| 55 | |
| 56 def test_peek_from_second(self): | |
| 57 it = CharIter("1234") | |
| 58 self.assertEqual("1", it.peek()) | |
| 59 self.assertEqual("1", next(it)) | |
| 60 self.assertEqual("2", it.peek()) | |
| 61 chars = "".join(it) | |
| 62 self.assertEqual("234", chars) | |
| 63 self.assertIsNone(it.peek()) | |
| 64 | |
| 65 | |
| 66 if __name__ == "__main__": | |
| 67 sys.exit(unittest.main()) |
