Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Lib/test/test_string/test_templatelib.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also test two interpolations next to each other?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have tests for the iteration, I just test that direct iter() call work correctly.


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()
Loading