mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
[3.14] gh-132661: Add default value (of ""
) for Interpolation.expression
(GH-136441) (#136511)
Co-authored-by: Dave Peck <davepeck@gmail.com>
This commit is contained in:
parent
da8bcfd949
commit
95baa28d9f
5 changed files with 58 additions and 27 deletions
|
@ -3,33 +3,45 @@ from string.templatelib import Interpolation
|
|||
|
||||
|
||||
class TStringBaseCase:
|
||||
def assertInterpolationEqual(self, i, exp):
|
||||
"""Test Interpolation equality.
|
||||
|
||||
The *i* argument must be an Interpolation instance.
|
||||
|
||||
The *exp* argument must be a tuple of the form
|
||||
(value, expression, conversion, format_spec) where the final three
|
||||
items may be omitted and are assumed to be '', None and '' respectively.
|
||||
"""
|
||||
if len(exp) == 4:
|
||||
actual = (i.value, i.expression, i.conversion, i.format_spec)
|
||||
self.assertEqual(actual, exp)
|
||||
elif len(exp) == 3:
|
||||
self.assertEqual((i.value, i.expression, i.conversion), exp)
|
||||
self.assertEqual(i.format_spec, "")
|
||||
elif len(exp) == 2:
|
||||
self.assertEqual((i.value, i.expression), exp)
|
||||
self.assertEqual(i.conversion, None)
|
||||
self.assertEqual(i.format_spec, "")
|
||||
elif len(exp) == 1:
|
||||
self.assertEqual((i.value,), exp)
|
||||
self.assertEqual(i.expression, "")
|
||||
self.assertEqual(i.conversion, None)
|
||||
self.assertEqual(i.format_spec, "")
|
||||
|
||||
def assertTStringEqual(self, t, strings, interpolations):
|
||||
"""Test template string literal equality.
|
||||
|
||||
The *strings* argument must be a tuple of strings equal to *t.strings*.
|
||||
|
||||
The *interpolations* argument must be a sequence of tuples which are
|
||||
compared against *t.interpolations*. Each tuple consists of
|
||||
(value, expression, conversion, format_spec), though the final two
|
||||
items may be omitted, and are assumed to be None and '' respectively.
|
||||
compared against *t.interpolations*. Each tuple must match the form
|
||||
described in the `assertInterpolationEqual` method.
|
||||
"""
|
||||
self.assertEqual(t.strings, strings)
|
||||
self.assertEqual(len(t.interpolations), len(interpolations))
|
||||
|
||||
for i, exp in zip(t.interpolations, interpolations, strict=True):
|
||||
if len(exp) == 4:
|
||||
actual = (i.value, i.expression, i.conversion, i.format_spec)
|
||||
self.assertEqual(actual, exp)
|
||||
continue
|
||||
|
||||
if len(exp) == 3:
|
||||
self.assertEqual((i.value, i.expression, i.conversion), exp)
|
||||
self.assertEqual(i.format_spec, '')
|
||||
continue
|
||||
|
||||
self.assertEqual((i.value, i.expression), exp)
|
||||
self.assertEqual(i.format_spec, '')
|
||||
self.assertIsNone(i.conversion)
|
||||
self.assertInterpolationEqual(i, exp)
|
||||
|
||||
|
||||
def convert(value, conversion):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue