|
7 | 7 | """ |
8 | 8 | import os |
9 | 9 | import sys |
| 10 | +import re |
10 | 11 | import random |
11 | 12 |
|
12 | 13 | import mock |
@@ -309,21 +310,25 @@ def test_transcript(request, capsys, filename, feedback_to_output): |
309 | 310 |
|
310 | 311 |
|
311 | 312 | @pytest.mark.parametrize('expected, transformed', [ |
312 | | - ( 'text with no slashes', 'text\ with\ no\ slashes' ), |
313 | | - # stuff with just one slash |
314 | | - ( 'use 2/3 cup', 'use\ 2\/3\ cup' ), |
315 | | - ( '/tmp is nice', '\/tmp\ is\ nice'), |
316 | | - ( 'slash at end/', 'slash\ at\ end\/'), |
| 313 | + # strings with zero or one slash or with escaped slashes means no regular |
| 314 | + # expression present, so the result should just be what re.escape returns. |
| 315 | + # we don't use static strings in these tests because re.escape behaves |
| 316 | + # differently in python 3.7 than in prior versions |
| 317 | + ( 'text with no slashes', re.escape('text with no slashes') ), |
| 318 | + ( 'specials .*', re.escape('specials .*') ), |
| 319 | + ( 'use 2/3 cup', re.escape('use 2/3 cup') ), |
| 320 | + ( '/tmp is nice', re.escape('/tmp is nice') ), |
| 321 | + ( 'slash at end/', re.escape('slash at end/') ), |
| 322 | + # escaped slashes |
| 323 | + ( 'not this slash\/ or this one\/', re.escape('not this slash/ or this one/' ) ), |
317 | 324 | # regexes |
318 | | - ( 'specials .*', 'specials\ \.\*' ), |
319 | 325 | ( '/.*/', '.*' ), |
320 | | - ( 'specials ^ and + /[0-9]+/', 'specials\ \^\ and\ \+\ [0-9]+' ), |
321 | | - ( '/a{6}/ but not \/a{6} with /.*?/ more', 'a{6}\ but\ not\ \/a\{6\}\ with\ .*?\ more' ), |
322 | | - ( 'not this slash\/ or this one\/', 'not\ this\ slash\\/\ or\ this\ one\\/' ), |
323 | | - ( 'not \/, use /\|?/, not \/', 'not\ \\/\,\ use\ \|?\,\ not\ \\/' ), |
| 326 | + ( 'specials ^ and + /[0-9]+/', re.escape('specials ^ and + ') + '[0-9]+' ), |
| 327 | + ( '/a{6}/ but not \/a{6} with /.*?/ more', 'a{6}' + re.escape(' but not /a{6} with ') + '.*?' + re.escape(' more') ), |
| 328 | + ( 'not \/, use /\|?/, not \/', re.escape('not /, use ') + '\|?' + re.escape(', not /') ), |
324 | 329 | # inception: slashes in our regex. backslashed on input, bare on output |
325 | | - ( 'not \/, use /\/?/, not \/', 'not\ \\/\,\ use\ /?\,\ not\ \\/' ), |
326 | | - ( 'the /\/?/ more /.*/ stuff', 'the\ /?\ more\ .*\ stuff' ), |
| 330 | + ( 'not \/, use /\/?/, not \/', re.escape('not /, use ') + '/?' + re.escape(', not /') ), |
| 331 | + ( 'lots /\/?/ more /.*/ stuff', re.escape('lots ') + '/?' + re.escape(' more ') + '.*' + re.escape(' stuff') ), |
327 | 332 | ]) |
328 | 333 | def test_parse_transcript_expected(expected, transformed): |
329 | 334 | app = CmdLineApp() |
|
0 commit comments