|
1 | 1 | importpickle
|
2 | 2 | importunittest
|
| 3 | +fromcollections.abcimportIterator,Iterable |
3 | 4 | fromstring.templatelibimportTemplate,Interpolation
|
4 | 5 |
|
5 | 6 | fromtest.test_string._supportimportTStringBaseCase,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 | +classTemplateIterTests(unittest.TestCase): |
| 130 | +deftest_abc(self): |
| 131 | +self.assertIsInstance(iter(t''),Iterable) |
| 132 | +self.assertIsInstance(iter(t''),Iterator) |
| 133 | + |
| 134 | +deftest_final(self): |
| 135 | +TemplateIter=type(iter(t'')) |
| 136 | +withself.assertRaisesRegex(TypeError,'is not an acceptable base type'): |
| 137 | +classSub(TemplateIter): ... |
| 138 | + |
| 139 | +deftest_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()
|