|
1 | 1 | import pickle
|
2 | 2 | import unittest
|
| 3 | +from collections.abc import Iterator, Iterable |
3 | 4 | from string.templatelib import Template, Interpolation
|
4 | 5 |
|
5 | 6 | from test.test_string._support import TStringBaseCase, fstring
|
@@ -125,5 +126,28 @@ def test_pickle_interpolation(self):
|
125 | 126 | self.assertEqual(unpickled.format_spec, interpolation.format_spec)
|
126 | 127 |
|
127 | 128 |
|
| 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 | + |
128 | 152 | if __name__ == '__main__':
|
129 | 153 | unittest.main()
|
0 commit comments