-
-
Couldn't load subscription status.
- Fork 33.2k
gh-133213: Add tests for string.templatelib.TemplateIter
#133215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
@@ -118,5 +119,27 @@ def test_pickle_interpolation(self): | |
| self.assertEqual(unpickled.format_spec, interpolation.format_spec) | ||
|
|
||
|
|
||
| class TemplateIterTests(unittest.TestCase): | ||
| def test_basic(self): | ||
| self.assertIsInstance(iter(t''), Iterable) | ||
| self.assertIsInstance(iter(t''), Iterator) | ||
|
|
||
| def test_final(self): | ||
| with self.assertRaisesRegex(TypeError, 'is not an acceptable base type'): | ||
| class Sub(type(iter(t''))): ... | ||
sobolevn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| def test_iter(self): | ||
| x = 1 | ||
| res = list(iter(t'abc {x} yz')) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also test two interpolations next to each other? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have tests for the iteration, I just test that direct |
||
|
|
||
| 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() | ||
Uh oh!
There was an error while loading. Please reload this page.