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