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

Side by Side Diff: Lib/test/test_re.py

Issue 22578: Add addition attributes to re.error
Patch Set: Created 5 years ago
Left:
Right:
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 unified diff | Download patch
« no previous file with comments | « Lib/sre_parse.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 from test.support import verbose, run_unittest, gc_collect, bigmemtest, _2G, \ 1 from test.support import verbose, run_unittest, gc_collect, bigmemtest, _2G, \
2 cpython_only, captured_stdout 2 cpython_only, captured_stdout
3 import io 3 import io
4 import re 4 import re
5 from re import Scanner 5 from re import Scanner
6 import sre_compile 6 import sre_compile
7 import sre_constants 7 import sre_constants
8 import sys 8 import sys
9 import string 9 import string
10 import traceback 10 import traceback
(...skipping 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 pat.split(string='abracadabra', maxsplit=1), 1268 pat.split(string='abracadabra', maxsplit=1),
1269 ['', 'ab', 'racadabra']) 1269 ['', 'ab', 'racadabra'])
1270 self.assertEqual( 1270 self.assertEqual(
1271 pat.scanner(string='abracadabra', pos=3, endpos=10).search().span(), 1271 pat.scanner(string='abracadabra', pos=3, endpos=10).search().span(),
1272 (7, 9)) 1272 (7, 9))
1273 1273
1274 def test_bug_20998(self): 1274 def test_bug_20998(self):
1275 # Issue #20998: Fullmatch of repeated single character pattern 1275 # Issue #20998: Fullmatch of repeated single character pattern
1276 # with ignore case. 1276 # with ignore case.
1277 self.assertEqual(re.fullmatch('[a-c]+', 'ABC', re.I).span(), (0, 3)) 1277 self.assertEqual(re.fullmatch('[a-c]+', 'ABC', re.I).span(), (0, 3))
1278
1279 def test_error(self):
1280 with self.assertRaises(re.error) as cm:
1281 re.compile('(\u20ac))')
1282 err = cm.exception
1283 self.assertIsInstance(err.pattern, str)
1284 self.assertEqual(err.pattern, '(\u20ac))')
1285 self.assertEqual(err.pos, 3)
1286 self.assertEqual(err.lineno, 1)
1287 self.assertEqual(err.colno, 4)
1288 self.assertIn(err.msg, str(err))
1289 self.assertIn(' at position 3', str(err))
1290 self.assertNotIn(' at position 3', err.msg)
1291 # Bytes pattern
1292 with self.assertRaises(re.error) as cm:
1293 re.compile(b'(\xa4))')
1294 err = cm.exception
1295 self.assertIsInstance(err.pattern, bytes)
1296 self.assertEqual(err.pattern, b'(\xa4))')
1297 self.assertEqual(err.pos, 3)
1298 # Multiline pattern
1299 with self.assertRaises(re.error) as cm:
1300 re.compile("""
1301 (
1302 abc
1303 )
1304 )
1305 (
1306 """, re.VERBOSE)
1307 err = cm.exception
1308 self.assertEqual(err.pos, 77)
1309 self.assertEqual(err.lineno, 5)
1310 self.assertEqual(err.colno, 17)
1311 self.assertIn(err.msg, str(err))
1312 self.assertIn(' at position 77', str(err))
1313 self.assertIn('(line 5, column 17)', str(err))
1278 1314
1279 1315
1280 class PatternReprTests(unittest.TestCase): 1316 class PatternReprTests(unittest.TestCase):
1281 def check(self, pattern, expected): 1317 def check(self, pattern, expected):
1282 self.assertEqual(repr(re.compile(pattern)), expected) 1318 self.assertEqual(repr(re.compile(pattern)), expected)
1283 1319
1284 def check_flags(self, pattern, flags, expected): 1320 def check_flags(self, pattern, flags, expected):
1285 self.assertEqual(repr(re.compile(pattern, flags)), expected) 1321 self.assertEqual(repr(re.compile(pattern, flags)), expected)
1286 1322
1287 def test_without_flags(self): 1323 def test_without_flags(self):
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1481 if result is None: 1517 if result is None:
1482 print('=== Fails on unicode-sensitive match', t) 1518 print('=== Fails on unicode-sensitive match', t)
1483 1519
1484 1520
1485 def test_main(): 1521 def test_main():
1486 run_unittest(__name__) 1522 run_unittest(__name__)
1487 run_re_tests() 1523 run_re_tests()
1488 1524
1489 if __name__ == "__main__": 1525 if __name__ == "__main__":
1490 test_main() 1526 test_main()
OLDNEW
« 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+