Skip to content

Commit 0e21ed7

Browse files
sobolevnAA-Turner
andauthored
gh-133213: Add tests for string.templatelib.TemplateIter (#133215)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
1 parent 94b4fcd commit 0e21ed7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Lib/test/test_string/test_templatelib.py

+24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pickle
22
import unittest
3+
from collections.abc import Iterator, Iterable
34
from string.templatelib import Template, Interpolation
45

56
from test.test_string._support import TStringBaseCase, fstring
@@ -125,5 +126,28 @@ def test_pickle_interpolation(self):
125126
self.assertEqual(unpickled.format_spec, interpolation.format_spec)
126127

127128

129+
class TemplateIterTests(unittest.TestCase):
130+
def test_abc(self):
131+
self.assertIsInstance(iter(t''), Iterable)
132+
self.assertIsInstance(iter(t''), Iterator)
133+
134+
def test_final(self):
135+
TemplateIter = type(iter(t''))
136+
with self.assertRaisesRegex(TypeError, 'is not an acceptable base type'):
137+
class Sub(TemplateIter): ...
138+
139+
def test_iter(self):
140+
x = 1
141+
res = list(iter(t'abc {x} yz'))
142+
143+
self.assertEqual(res[0], 'abc ')
144+
self.assertIsInstance(res[1], Interpolation)
145+
self.assertEqual(res[1].value, 1)
146+
self.assertEqual(res[1].expression, 'x')
147+
self.assertEqual(res[1].conversion, None)
148+
self.assertEqual(res[1].format_spec, '')
149+
self.assertEqual(res[2], ' yz')
150+
151+
128152
if __name__ == '__main__':
129153
unittest.main()

0 commit comments

Comments
 (0)