Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1100)

Unified Diff: Lib/test/test_re.py

Issue 22578: Add addition attributes to re.error
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/sre_parse.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/test/test_re.py Fri Oct 10 11:14:49 2014 +0300
+++ b/Lib/test/test_re.py Fri Oct 10 11:49:08 2014 +0300
@@ -1276,6 +1276,42 @@ subpattern None
# with ignore case.
self.assertEqual(re.fullmatch('[a-c]+', 'ABC', re.I).span(), (0, 3))
+ def test_error(self):
+ with self.assertRaises(re.error) as cm:
+ re.compile('(\u20ac))')
+ err = cm.exception
+ self.assertIsInstance(err.pattern, str)
+ self.assertEqual(err.pattern, '(\u20ac))')
+ self.assertEqual(err.pos, 3)
+ self.assertEqual(err.lineno, 1)
+ self.assertEqual(err.colno, 4)
+ self.assertIn(err.msg, str(err))
+ self.assertIn(' at position 3', str(err))
+ self.assertNotIn(' at position 3', err.msg)
+ # Bytes pattern
+ with self.assertRaises(re.error) as cm:
+ re.compile(b'(\xa4))')
+ err = cm.exception
+ self.assertIsInstance(err.pattern, bytes)
+ self.assertEqual(err.pattern, b'(\xa4))')
+ self.assertEqual(err.pos, 3)
+ # Multiline pattern
+ with self.assertRaises(re.error) as cm:
+ re.compile("""
+ (
+ abc
+ )
+ )
+ (
+ """, re.VERBOSE)
+ err = cm.exception
+ self.assertEqual(err.pos, 77)
+ self.assertEqual(err.lineno, 5)
+ self.assertEqual(err.colno, 17)
+ self.assertIn(err.msg, str(err))
+ self.assertIn(' at position 77', str(err))
+ self.assertIn('(line 5, column 17)', str(err))
+
class PatternReprTests(unittest.TestCase):
def check(self, pattern, expected):
« no previous file with comments | « Lib/sre_parse.py ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+