diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2011-05-31 09:40:11 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2011-05-31 09:40:11 (GMT) |
commit | 62ecb6aa0ae8dbfabe1f42cdda1eb6c1a184c3e7 (patch) | |
tree | 2dde340efb5f52a7cfa4fb422b5171287738c3b6 /Lib/test/test_pep292.py | |
parent | 441531f6e66e159b58a02663857a13c38719eb0b (diff) | |
download | cpython-62ecb6aa0ae8dbfabe1f42cdda1eb6c1a184c3e7.zip cpython-62ecb6aa0ae8dbfabe1f42cdda1eb6c1a184c3e7.tar.gz cpython-62ecb6aa0ae8dbfabe1f42cdda1eb6c1a184c3e7.tar.bz2 |
Tidy up the additional string module tests added at the Pycon sprints (closes #11505)
Diffstat (limited to 'Lib/test/test_pep292.py')
-rw-r--r-- | Lib/test/test_pep292.py | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/Lib/test/test_pep292.py b/Lib/test/test_pep292.py index a1e52e9..6da8d2e 100644 --- a/Lib/test/test_pep292.py +++ b/Lib/test/test_pep292.py @@ -42,19 +42,6 @@ class TestTemplate(unittest.TestCase): s = Template('$who likes $$') eq(s.substitute(dict(who='tim', what='ham')), 'tim likes $') - def test_invalid(self): - class MyPattern(Template): - pattern = r""" - (?: - (?P<invalid>) | - (?P<escaped>%(delim)s) | - @(?P<named>%(id)s) | - @{(?P<braced>%(id)s)} - ) - """ - s = MyPattern('$') - self.assertRaises(ValueError, s.substitute, dict()) - def test_percents(self): eq = self.assertEqual s = Template('%(foo)s $foo ${foo}') @@ -172,6 +159,26 @@ class TestTemplate(unittest.TestCase): val = t.safe_substitute({'location': 'Cleveland'}) self.assertEqual(val, 'PyCon in Cleveland') + def test_invalid_with_no_lines(self): + # The error formatting for invalid templates + # has a special case for no data that the default + # pattern can't trigger (always has at least '$') + # So we craft a pattern that is always invalid + # with no leading data. + class MyTemplate(Template): + pattern = r""" + (?P<invalid>) | + unreachable( + (?P<named>) | + (?P<braced>) | + (?P<escaped>) + ) + """ + s = MyTemplate('') + with self.assertRaises(ValueError) as err: + s.substitute({}) + self.assertIn('line 1, col 1', str(err.exception)) + def test_unicode_values(self): s = Template('$who likes $what') d = dict(who='t\xffm', what='f\xfe\fed') |