https://github.com/python/cpython/commit/0e21ed7c09c687d62d6bf054022e66bccd1fa2bc
commit: 0e21ed7c09c687d62d6bf054022e66bccd1fa2bc
branch: main
author: sobolevn <m...@sobolevn.me>
committer: sobolevn <m...@sobolevn.me>
date: 2025-04-30T22:38:25+03:00
summary:

gh-133213: Add tests for `string.templatelib.TemplateIter` (#133215)

Co-authored-by: Adam Turner <9087854+aa-tur...@users.noreply.github.com>

files:
M Lib/test/test_string/test_templatelib.py

diff --git a/Lib/test/test_string/test_templatelib.py 
b/Lib/test/test_string/test_templatelib.py
index 5221ca673b24ec..5b9490c2be6de0 100644
--- a/Lib/test/test_string/test_templatelib.py
+++ b/Lib/test/test_string/test_templatelib.py
@@ -1,5 +1,6 @@
 import pickle
 import unittest
+from collections.abc import Iterator, Iterable
 from string.templatelib import Template, Interpolation
 
 from test.test_string._support import TStringBaseCase, fstring
@@ -125,5 +126,28 @@ def test_pickle_interpolation(self):
                     self.assertEqual(unpickled.format_spec, 
interpolation.format_spec)
 
 
+class TemplateIterTests(unittest.TestCase):
+    def test_abc(self):
+        self.assertIsInstance(iter(t''), Iterable)
+        self.assertIsInstance(iter(t''), Iterator)
+
+    def test_final(self):
+        TemplateIter = type(iter(t''))
+        with self.assertRaisesRegex(TypeError, 'is not an acceptable base 
type'):
+            class Sub(TemplateIter): ...
+
+    def test_iter(self):
+        x = 1
+        res = list(iter(t'abc {x} yz'))
+
+        self.assertEqual(res[0], 'abc ')
+        self.assertIsInstance(res[1], Interpolation)
+        self.assertEqual(res[1].value, 1)
+        self.assertEqual(res[1].expression, 'x')
+        self.assertEqual(res[1].conversion, None)
+        self.assertEqual(res[1].format_spec, '')
+        self.assertEqual(res[2], ' yz')
+
+
 if __name__ == '__main__':
     unittest.main()

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to