|
2 | 2 |
|
3 | 3 |
|
4 | 4 | class TStringBaseCase:
|
| 5 | + def assertInterpolationEqual(self, i, exp): |
| 6 | + """Test Interpolation equality. |
| 7 | +
|
| 8 | + The *i* argument must be an Interpolation instance. |
| 9 | +
|
| 10 | + The *exp* argument must be a tuple of the form |
| 11 | + (value, expression, conversion, format_spec) where the final three |
| 12 | + items may be omitted and are assumed to be '', None and '' respectively. |
| 13 | + """ |
| 14 | + if len(exp) == 4: |
| 15 | + actual = (i.value, i.expression, i.conversion, i.format_spec) |
| 16 | + self.assertEqual(actual, exp) |
| 17 | + elif len(exp) == 3: |
| 18 | + self.assertEqual((i.value, i.expression, i.conversion), exp) |
| 19 | + self.assertEqual(i.format_spec, "") |
| 20 | + elif len(exp) == 2: |
| 21 | + self.assertEqual((i.value, i.expression), exp) |
| 22 | + self.assertEqual(i.conversion, None) |
| 23 | + self.assertEqual(i.format_spec, "") |
| 24 | + elif len(exp) == 1: |
| 25 | + self.assertEqual((i.value,), exp) |
| 26 | + self.assertEqual(i.expression, "") |
| 27 | + self.assertEqual(i.conversion, None) |
| 28 | + self.assertEqual(i.format_spec, "") |
| 29 | + |
5 | 30 | def assertTStringEqual(self, t, strings, interpolations):
|
6 | 31 | """Test template string literal equality.
|
7 | 32 |
|
8 | 33 | The *strings* argument must be a tuple of strings equal to *t.strings*.
|
9 | 34 |
|
10 | 35 | The *interpolations* argument must be a sequence of tuples which are
|
11 |
| - compared against *t.interpolations*. Each tuple consists of |
12 |
| - (value, expression, conversion, format_spec), though the final two |
13 |
| - items may be omitted, and are assumed to be None and '' respectively. |
| 36 | + compared against *t.interpolations*. Each tuple must match the form |
| 37 | + described in the `assertInterpolationEqual` method. |
14 | 38 | """
|
15 | 39 | self.assertEqual(t.strings, strings)
|
16 | 40 | self.assertEqual(len(t.interpolations), len(interpolations))
|
17 | 41 |
|
18 | 42 | for i, exp in zip(t.interpolations, interpolations, strict=True):
|
19 |
| - if len(exp) == 4: |
20 |
| - actual = (i.value, i.expression, i.conversion, i.format_spec) |
21 |
| - self.assertEqual(actual, exp) |
22 |
| - continue |
23 |
| - |
24 |
| - if len(exp) == 3: |
25 |
| - self.assertEqual((i.value, i.expression, i.conversion), exp) |
26 |
| - self.assertEqual(i.format_spec, '') |
27 |
| - continue |
28 |
| - |
29 |
| - self.assertEqual((i.value, i.expression), exp) |
30 |
| - self.assertEqual(i.format_spec, '') |
31 |
| - self.assertIsNone(i.conversion) |
| 43 | + self.assertInterpolationEqual(i, exp) |
32 | 44 |
|
33 | 45 |
|
34 | 46 | def convert(value, conversion):
|
|
0 commit comments