summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2016-09-08 17:59:53 (GMT)
committerR David Murray <rdmurray@bitdance.com>2016-09-08 17:59:53 (GMT)
commit44b548dda872c0d4f30afd6b44fd74b053a55ad8 (patch)
treeb3c1ff8485bc279000f9db95491ebc69a4385876 /Lib/test
parent513d7478a136e7646075592da2593476299cc8be (diff)
downloadcpython-44b548dda872c0d4f30afd6b44fd74b053a55ad8.zip
cpython-44b548dda872c0d4f30afd6b44fd74b053a55ad8.tar.gz
cpython-44b548dda872c0d4f30afd6b44fd74b053a55ad8.tar.bz2
#27364: fix "incorrect" uses of escape character in the stdlib.
And most of the tools. Patch by Emanual Barry, reviewed by me, Serhiy Storchaka, and Martin Panter.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/_test_multiprocessing.py2
-rw-r--r--Lib/test/datetimetester.py4
-rwxr-xr-xLib/test/re_tests.py4
-rw-r--r--Lib/test/sortperf.py2
-rw-r--r--Lib/test/support/__init__.py2
-rw-r--r--Lib/test/test_asyncio/test_streams.py2
-rw-r--r--Lib/test/test_builtin.py4
-rw-r--r--Lib/test/test_capi.py10
-rw-r--r--Lib/test/test_cgi.py2
-rw-r--r--Lib/test/test_codeccallbacks.py4
-rw-r--r--Lib/test/test_codecs.py14
-rw-r--r--Lib/test/test_coroutines.py8
-rw-r--r--Lib/test/test_doctest.py2
-rw-r--r--Lib/test/test_email/test__header_value_parser.py4
-rw-r--r--Lib/test/test_email/test_email.py2
-rw-r--r--Lib/test/test_faulthandler.py8
-rw-r--r--Lib/test/test_fnmatch.py16
-rw-r--r--Lib/test/test_future.py2
-rw-r--r--Lib/test/test_gdb.py12
-rw-r--r--Lib/test/test_getargs2.py12
-rw-r--r--Lib/test/test_htmlparser.py2
-rw-r--r--Lib/test/test_http_cookiejar.py6
-rw-r--r--Lib/test/test_mailcap.py2
-rw-r--r--Lib/test/test_os.py2
-rw-r--r--Lib/test/test_platform.py4
-rw-r--r--Lib/test/test_re.py200
-rw-r--r--Lib/test/test_regrtest.py4
-rw-r--r--Lib/test/test_ssl.py2
-rw-r--r--Lib/test/test_strftime.py6
-rw-r--r--Lib/test/test_strlit.py4
-rw-r--r--Lib/test/test_strptime.py10
-rw-r--r--Lib/test/test_unicode.py4
-rw-r--r--Lib/test/test_urllib.py4
-rw-r--r--Lib/test/test_xmlrpc.py2
34 files changed, 184 insertions, 184 deletions
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py
index d88cd07..c00846c 100644
--- a/Lib/test/_test_multiprocessing.py
+++ b/Lib/test/_test_multiprocessing.py
@@ -3857,7 +3857,7 @@ class TestSemaphoreTracker(unittest.TestCase):
p.stderr.close()
expected = 'semaphore_tracker: There appear to be 2 leaked semaphores'
self.assertRegex(err, expected)
- self.assertRegex(err, 'semaphore_tracker: %r: \[Errno' % name1)
+ self.assertRegex(err, r'semaphore_tracker: %r: \[Errno' % name1)
#
# Mixins
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
index 86c9373..988c6f7 100644
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -4001,12 +4001,12 @@ class Oddballs(unittest.TestCase):
datetime(xx, xx, xx, xx, xx, xx, xx))
with self.assertRaisesRegex(TypeError, '^an integer is required '
- '\(got type str\)$'):
+ r'\(got type str\)$'):
datetime(10, 10, '10')
f10 = Number(10.9)
with self.assertRaisesRegex(TypeError, '^__int__ returned non-int '
- '\(type float\)$'):
+ r'\(type float\)$'):
datetime(10, 10, f10)
class Float(float):
diff --git a/Lib/test/re_tests.py b/Lib/test/re_tests.py
index 8c158f8..d3692f8 100755
--- a/Lib/test/re_tests.py
+++ b/Lib/test/re_tests.py
@@ -158,7 +158,7 @@ tests = [
('(abc', '-', SYNTAX_ERROR),
('a]', 'a]', SUCCEED, 'found', 'a]'),
('a[]]b', 'a]b', SUCCEED, 'found', 'a]b'),
- ('a[\]]b', 'a]b', SUCCEED, 'found', 'a]b'),
+ ('a[\\]]b', 'a]b', SUCCEED, 'found', 'a]b'),
('a[^bc]d', 'aed', SUCCEED, 'found', 'aed'),
('a[^bc]d', 'abd', FAIL),
('a[^-b]c', 'adc', SUCCEED, 'found', 'adc'),
@@ -551,7 +551,7 @@ tests = [
# lookbehind: split by : but not if it is escaped by -.
('(?<!-):(.*?)(?<!-):', 'a:bc-:de:f', SUCCEED, 'g1', 'bc-:de' ),
# escaping with \ as we know it
- ('(?<!\\\):(.*?)(?<!\\\):', 'a:bc\\:de:f', SUCCEED, 'g1', 'bc\\:de' ),
+ ('(?<!\\\\):(.*?)(?<!\\\\):', 'a:bc\\:de:f', SUCCEED, 'g1', 'bc\\:de' ),
# terminating with ' and escaping with ? as in edifact
("(?<!\\?)'(.*?)(?<!\\?)'", "a'bc?'de'f", SUCCEED, 'g1', "bc?'de" ),
diff --git a/Lib/test/sortperf.py b/Lib/test/sortperf.py
index 90722f7..171e5ce 100644
--- a/Lib/test/sortperf.py
+++ b/Lib/test/sortperf.py
@@ -64,7 +64,7 @@ def doit(L):
flush()
def tabulate(r):
- """Tabulate sort speed for lists of various sizes.
+ r"""Tabulate sort speed for lists of various sizes.
The sizes are 2**i for i in r (the argument, a list).
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 3e2ab43..8b66f95 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -2202,7 +2202,7 @@ def can_xattr():
os.setxattr(fp.fileno(), b"user.test", b"")
# Kernels < 2.6.39 don't respect setxattr flags.
kernel_version = platform.release()
- m = re.match("2.6.(\d{1,2})", kernel_version)
+ m = re.match(r"2.6.(\d{1,2})", kernel_version)
can = m is None or int(m.group(1)) >= 39
except OSError:
can = False
diff --git a/Lib/test/test_asyncio/test_streams.py b/Lib/test/test_asyncio/test_streams.py
index 1783d5f..35557c3 100644
--- a/Lib/test/test_asyncio/test_streams.py
+++ b/Lib/test/test_asyncio/test_streams.py
@@ -831,7 +831,7 @@ os.close(fd)
stream._waiter = asyncio.Future(loop=self.loop)
self.assertRegex(
repr(stream),
- "<StreamReader w=<Future pending[\S ]*>>")
+ r"<StreamReader w=<Future pending[\S ]*>>")
stream._waiter.set_result(None)
self.loop.run_until_complete(stream._waiter)
stream._waiter = None
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index 486f445..c0343ef 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -83,7 +83,7 @@ test_conv_no_sign = [
('', ValueError),
(' ', ValueError),
(' \t\t ', ValueError),
- (str(b'\u0663\u0661\u0664 ','raw-unicode-escape'), 314),
+ (str(br'\u0663\u0661\u0664 ','raw-unicode-escape'), 314),
(chr(0x200), ValueError),
]
@@ -105,7 +105,7 @@ test_conv_sign = [
('', ValueError),
(' ', ValueError),
(' \t\t ', ValueError),
- (str(b'\u0663\u0661\u0664 ','raw-unicode-escape'), 314),
+ (str(br'\u0663\u0661\u0664 ','raw-unicode-escape'), 314),
(chr(0x200), ValueError),
]
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py
index 6852381..5521e76 100644
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -533,21 +533,21 @@ class SkipitemTest(unittest.TestCase):
parse((1, 2, 3), {}, b'OOO', ['', '', 'a'])
parse((1, 2), {'a': 3}, b'OOO', ['', '', 'a'])
with self.assertRaisesRegex(TypeError,
- 'Function takes at least 2 positional arguments \(1 given\)'):
+ r'Function takes at least 2 positional arguments \(1 given\)'):
parse((1,), {'a': 3}, b'OOO', ['', '', 'a'])
parse((1,), {}, b'O|OO', ['', '', 'a'])
with self.assertRaisesRegex(TypeError,
- 'Function takes at least 1 positional arguments \(0 given\)'):
+ r'Function takes at least 1 positional arguments \(0 given\)'):
parse((), {}, b'O|OO', ['', '', 'a'])
parse((1, 2), {'a': 3}, b'OO$O', ['', '', 'a'])
with self.assertRaisesRegex(TypeError,
- 'Function takes exactly 2 positional arguments \(1 given\)'):
+ r'Function takes exactly 2 positional arguments \(1 given\)'):
parse((1,), {'a': 3}, b'OO$O', ['', '', 'a'])
parse((1,), {}, b'O|O$O', ['', '', 'a'])
with self.assertRaisesRegex(TypeError,
- 'Function takes at least 1 positional arguments \(0 given\)'):
+ r'Function takes at least 1 positional arguments \(0 given\)'):
parse((), {}, b'O|O$O', ['', '', 'a'])
- with self.assertRaisesRegex(SystemError, 'Empty parameter name after \$'):
+ with self.assertRaisesRegex(SystemError, r'Empty parameter name after \$'):
parse((1,), {}, b'O|$OO', ['', '', 'a'])
with self.assertRaisesRegex(SystemError, 'Empty keyword'):
parse((1,), {}, b'O|OO', ['', 'a', ''])
diff --git a/Lib/test/test_cgi.py b/Lib/test/test_cgi.py
index 1647849..6373221 100644
--- a/Lib/test/test_cgi.py
+++ b/Lib/test/test_cgi.py
@@ -148,7 +148,7 @@ class CgiTests(unittest.TestCase):
def test_escape(self):
# cgi.escape() is deprecated.
with warnings.catch_warnings():
- warnings.filterwarnings('ignore', 'cgi\.escape',
+ warnings.filterwarnings('ignore', r'cgi\.escape',
DeprecationWarning)
self.assertEqual("test &amp; string", cgi.escape("test & string"))
self.assertEqual("&lt;test string&gt;", cgi.escape("<test string>"))
diff --git a/Lib/test/test_codeccallbacks.py b/Lib/test/test_codeccallbacks.py
index c8cdacf..6a3e993 100644
--- a/Lib/test/test_codeccallbacks.py
+++ b/Lib/test/test_codeccallbacks.py
@@ -280,12 +280,12 @@ class CodecCallbackTest(unittest.TestCase):
)
self.assertEqual(
- b"\\u3042\u3xxx".decode("unicode-escape", "test.handler1"),
+ b"\\u3042\\u3xxx".decode("unicode-escape", "test.handler1"),
"\u3042[<92><117><51>]xxx"
)
self.assertEqual(
- b"\\u3042\u3xx".decode("unicode-escape", "test.handler1"),
+ b"\\u3042\\u3xx".decode("unicode-escape", "test.handler1"),
"\u3042[<92><117><51>]xx"
)
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index 825a7dd..1af5524 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -2703,8 +2703,8 @@ class TransformCodecTest(unittest.TestCase):
bad_input = "bad input type"
for encoding in bytes_transform_encodings:
with self.subTest(encoding=encoding):
- fmt = ( "{!r} is not a text encoding; "
- "use codecs.encode\(\) to handle arbitrary codecs")
+ fmt = (r"{!r} is not a text encoding; "
+ r"use codecs.encode\(\) to handle arbitrary codecs")
msg = fmt.format(encoding)
with self.assertRaisesRegex(LookupError, msg) as failure:
bad_input.encode(encoding)
@@ -2713,7 +2713,7 @@ class TransformCodecTest(unittest.TestCase):
def test_text_to_binary_blacklists_text_transforms(self):
# Check str.encode gives a good error message for str -> str codecs
msg = (r"^'rot_13' is not a text encoding; "
- "use codecs.encode\(\) to handle arbitrary codecs")
+ r"use codecs.encode\(\) to handle arbitrary codecs")
with self.assertRaisesRegex(LookupError, msg):
"just an example message".encode("rot_13")
@@ -2725,7 +2725,7 @@ class TransformCodecTest(unittest.TestCase):
with self.subTest(encoding=encoding):
encoded_data = codecs.encode(data, encoding)
fmt = (r"{!r} is not a text encoding; "
- "use codecs.decode\(\) to handle arbitrary codecs")
+ r"use codecs.decode\(\) to handle arbitrary codecs")
msg = fmt.format(encoding)
with self.assertRaisesRegex(LookupError, msg):
encoded_data.decode(encoding)
@@ -2737,7 +2737,7 @@ class TransformCodecTest(unittest.TestCase):
for bad_input in (b"immutable", bytearray(b"mutable")):
with self.subTest(bad_input=bad_input):
msg = (r"^'rot_13' is not a text encoding; "
- "use codecs.decode\(\) to handle arbitrary codecs")
+ r"use codecs.decode\(\) to handle arbitrary codecs")
with self.assertRaisesRegex(LookupError, msg) as failure:
bad_input.decode("rot_13")
self.assertIsNone(failure.exception.__cause__)
@@ -2956,12 +2956,12 @@ class ExceptionChainingTest(unittest.TestCase):
self.assertEqual(decoded, b"not str!")
# Text model methods should complain
fmt = (r"^{!r} encoder returned 'str' instead of 'bytes'; "
- "use codecs.encode\(\) to encode to arbitrary types$")
+ r"use codecs.encode\(\) to encode to arbitrary types$")
msg = fmt.format(self.codec_name)
with self.assertRaisesRegex(TypeError, msg):
"str_input".encode(self.codec_name)
fmt = (r"^{!r} decoder returned 'bytes' instead of 'str'; "
- "use codecs.decode\(\) to decode to arbitrary types$")
+ r"use codecs.decode\(\) to decode to arbitrary types$")
msg = fmt.format(self.codec_name)
with self.assertRaisesRegex(TypeError, msg):
b"bytes input".decode(self.codec_name)
diff --git a/Lib/test/test_coroutines.py b/Lib/test/test_coroutines.py
index e52654c..ee2482d 100644
--- a/Lib/test/test_coroutines.py
+++ b/Lib/test/test_coroutines.py
@@ -891,7 +891,7 @@ class CoroutineTest(unittest.TestCase):
return await Awaitable()
with self.assertRaisesRegex(
- TypeError, "__await__\(\) returned a coroutine"):
+ TypeError, r"__await__\(\) returned a coroutine"):
run_async(foo())
@@ -1333,7 +1333,7 @@ class CoroutineTest(unittest.TestCase):
with self.assertRaisesRegex(
TypeError,
- "async for' received an invalid object.*__aiter.*\: I"):
+ r"async for' received an invalid object.*__aiter.*\: I"):
run_async(foo())
@@ -1667,8 +1667,8 @@ class SysSetCoroWrapperTest(unittest.TestCase):
try:
with silence_coro_gc(), self.assertRaisesRegex(
RuntimeError,
- "coroutine wrapper.*\.wrapper at 0x.*attempted to "
- "recursively wrap .* wrap .*"):
+ r"coroutine wrapper.*\.wrapper at 0x.*attempted to "
+ r"recursively wrap .* wrap .*"):
foo()
finally:
diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py
index a9520a5..2258c6b 100644
--- a/Lib/test/test_doctest.py
+++ b/Lib/test/test_doctest.py
@@ -291,7 +291,7 @@ constructor:
...
... Non-example text.
...
- ... >>> print('another\example')
+ ... >>> print('another\\example')
... another
... example
... '''
diff --git a/Lib/test/test_email/test__header_value_parser.py b/Lib/test/test_email/test__header_value_parser.py
index f7ac0e3..26ece69 100644
--- a/Lib/test/test_email/test__header_value_parser.py
+++ b/Lib/test/test_email/test__header_value_parser.py
@@ -581,7 +581,7 @@ class TestParser(TestParserMixin, TestEmailBase):
def test_get_comment_quoted_parens(self):
self._test_get_x(parser.get_comment,
- '(foo\) \(\)bar)', '(foo\) \(\)bar)', ' ', [], '', ['foo) ()bar'])
+ r'(foo\) \(\)bar)', r'(foo\) \(\)bar)', ' ', [], '', ['foo) ()bar'])
def test_get_comment_non_printable(self):
self._test_get_x(parser.get_comment,
@@ -625,7 +625,7 @@ class TestParser(TestParserMixin, TestEmailBase):
def test_get_comment_qs_in_nested_comment(self):
comment = self._test_get_x(parser.get_comment,
- '(foo (b\)))', '(foo (b\)))', ' ', [], '', ['foo (b\))'])
+ r'(foo (b\)))', r'(foo (b\)))', ' ', [], '', [r'foo (b\))'])
self.assertEqual(comment[2].content, 'b)')
# get_cfws
diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py
index 529d3ef..e95f08d 100644
--- a/Lib/test/test_email/test_email.py
+++ b/Lib/test/test_email/test_email.py
@@ -3040,7 +3040,7 @@ class TestMiscellaneous(TestEmailBase):
def test_escape_backslashes(self):
self.assertEqual(
- utils.formataddr(('Arthur \Backslash\ Foobar', 'person@dom.ain')),
+ utils.formataddr((r'Arthur \Backslash\ Foobar', 'person@dom.ain')),
r'"Arthur \\Backslash\\ Foobar" <person@dom.ain>')
a = r'Arthur \Backslash\ Foobar'
b = 'person@dom.ain'
diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py
index 1ff17bb..d2bd2d2 100644
--- a/Lib/test/test_faulthandler.py
+++ b/Lib/test/test_faulthandler.py
@@ -93,7 +93,7 @@ class FaultHandlerTests(unittest.TestCase):
header = 'Thread 0x[0-9a-f]+'
else:
header = 'Stack'
- regex = """
+ regex = r"""
^{fatal_error}
{header} \(most recent call first\):
@@ -490,7 +490,7 @@ class FaultHandlerTests(unittest.TestCase):
lineno = 8
else:
lineno = 10
- regex = """
+ regex = r"""
^Thread 0x[0-9a-f]+ \(most recent call first\):
(?: File ".*threading.py", line [0-9]+ in [_a-z]+
){{1,3}} File "<string>", line 23 in run
@@ -669,9 +669,9 @@ class FaultHandlerTests(unittest.TestCase):
trace = '\n'.join(trace)
if not unregister:
if all_threads:
- regex = 'Current thread 0x[0-9a-f]+ \(most recent call first\):\n'
+ regex = r'Current thread 0x[0-9a-f]+ \(most recent call first\):\n'
else:
- regex = 'Stack \(most recent call first\):\n'
+ regex = r'Stack \(most recent call first\):\n'
regex = expected_traceback(14, 32, regex)
self.assertRegex(trace, regex)
else:
diff --git a/Lib/test/test_fnmatch.py b/Lib/test/test_fnmatch.py
index fa37f90..a5f5832 100644
--- a/Lib/test/test_fnmatch.py
+++ b/Lib/test/test_fnmatch.py
@@ -62,14 +62,14 @@ class FnmatchTestCase(unittest.TestCase):
class TranslateTestCase(unittest.TestCase):
def test_translate(self):
- self.assertEqual(translate('*'), '.*\Z(?ms)')
- self.assertEqual(translate('?'), '.\Z(?ms)')
- self.assertEqual(translate('a?b*'), 'a.b.*\Z(?ms)')
- self.assertEqual(translate('[abc]'), '[abc]\Z(?ms)')
- self.assertEqual(translate('[]]'), '[]]\Z(?ms)')
- self.assertEqual(translate('[!x]'), '[^x]\Z(?ms)')
- self.assertEqual(translate('[^x]'), '[\\^x]\Z(?ms)')
- self.assertEqual(translate('[x'), '\\[x\Z(?ms)')
+ self.assertEqual(translate('*'), r'.*\Z(?ms)')
+ self.assertEqual(translate('?'), r'.\Z(?ms)')
+ self.assertEqual(translate('a?b*'), r'a.b.*\Z(?ms)')
+ self.assertEqual(translate('[abc]'), r'[abc]\Z(?ms)')
+ self.assertEqual(translate('[]]'), r'[]]\Z(?ms)')
+ self.assertEqual(translate('[!x]'), r'[^x]\Z(?ms)')
+ self.assertEqual(translate('[^x]'), r'[\^x]\Z(?ms)')
+ self.assertEqual(translate('[x'), r'\[x\Z(?ms)')
class FilterTestCase(unittest.TestCase):
diff --git a/Lib/test/test_future.py b/Lib/test/test_future.py
index beac993..213b2ba 100644
--- a/Lib/test/test_future.py
+++ b/Lib/test/test_future.py
@@ -4,7 +4,7 @@ import unittest
from test import support
import re
-rx = re.compile('\((\S+).py, line (\d+)')
+rx = re.compile(r'\((\S+).py, line (\d+)')
def get_error_location(msg):
mo = rx.search(str(msg))
diff --git a/Lib/test/test_gdb.py b/Lib/test/test_gdb.py
index ff65190..5fbf154 100644
--- a/Lib/test/test_gdb.py
+++ b/Lib/test/test_gdb.py
@@ -244,7 +244,7 @@ class DebuggerTests(unittest.TestCase):
# gdb can insert additional '\n' and space characters in various places
# in its output, depending on the width of the terminal it's connected
# to (using its "wrap_here" function)
- m = re.match('.*#0\s+builtin_id\s+\(self\=.*,\s+v=\s*(.*?)\)\s+at\s+\S*Python/bltinmodule.c.*',
+ m = re.match(r'.*#0\s+builtin_id\s+\(self\=.*,\s+v=\s*(.*?)\)\s+at\s+\S*Python/bltinmodule.c.*',
gdb_output, re.DOTALL)
if not m:
self.fail('Unexpected gdb output: %r\n%s' % (gdb_output, gdb_output))
@@ -552,7 +552,7 @@ class Foo:
foo = Foo()
foo.an_attr = foo
id(foo)''')
- self.assertTrue(re.match('<Foo\(an_attr=<\.\.\.>\) at remote 0x-?[0-9a-f]+>',
+ self.assertTrue(re.match(r'<Foo\(an_attr=<\.\.\.>\) at remote 0x-?[0-9a-f]+>',
gdb_repr),
'Unexpected gdb representation: %r\n%s' % \
(gdb_repr, gdb_output))
@@ -565,7 +565,7 @@ class Foo(object):
foo = Foo()
foo.an_attr = foo
id(foo)''')
- self.assertTrue(re.match('<Foo\(an_attr=<\.\.\.>\) at remote 0x-?[0-9a-f]+>',
+ self.assertTrue(re.match(r'<Foo\(an_attr=<\.\.\.>\) at remote 0x-?[0-9a-f]+>',
gdb_repr),
'Unexpected gdb representation: %r\n%s' % \
(gdb_repr, gdb_output))
@@ -579,7 +579,7 @@ b = Foo()
a.an_attr = b
b.an_attr = a
id(a)''')
- self.assertTrue(re.match('<Foo\(an_attr=<Foo\(an_attr=<\.\.\.>\) at remote 0x-?[0-9a-f]+>\) at remote 0x-?[0-9a-f]+>',
+ self.assertTrue(re.match(r'<Foo\(an_attr=<Foo\(an_attr=<\.\.\.>\) at remote 0x-?[0-9a-f]+>\) at remote 0x-?[0-9a-f]+>',
gdb_repr),
'Unexpected gdb representation: %r\n%s' % \
(gdb_repr, gdb_output))
@@ -614,7 +614,7 @@ id(a)''')
def test_builtin_method(self):
gdb_repr, gdb_output = self.get_gdb_repr('import sys; id(sys.stdout.readlines)')
- self.assertTrue(re.match('<built-in method readlines of _io.TextIOWrapper object at remote 0x-?[0-9a-f]+>',
+ self.assertTrue(re.match(r'<built-in method readlines of _io.TextIOWrapper object at remote 0x-?[0-9a-f]+>',
gdb_repr),
'Unexpected gdb representation: %r\n%s' % \
(gdb_repr, gdb_output))
@@ -629,7 +629,7 @@ id(foo.__code__)''',
breakpoint='builtin_id',
cmds_after_breakpoint=['print (PyFrameObject*)(((PyCodeObject*)v)->co_zombieframe)']
)
- self.assertTrue(re.match('.*\s+\$1 =\s+Frame 0x-?[0-9a-f]+, for file <string>, line 3, in foo \(\)\s+.*',
+ self.assertTrue(re.match(r'.*\s+\$1 =\s+Frame 0x-?[0-9a-f]+, for file <string>, line 3, in foo \(\)\s+.*',
gdb_output,
re.DOTALL),
'Unexpected gdb representation: %r\n%s' % (gdb_output, gdb_output))
diff --git a/Lib/test/test_getargs2.py b/Lib/test/test_getargs2.py
index 0fbe12d..8a194aa 100644
--- a/Lib/test/test_getargs2.py
+++ b/Lib/test/test_getargs2.py
@@ -625,20 +625,20 @@ class KeywordOnly_TestCase(unittest.TestCase):
)
# required arg missing
with self.assertRaisesRegex(TypeError,
- "Required argument 'required' \(pos 1\) not found"):
+ r"Required argument 'required' \(pos 1\) not found"):
getargs_keyword_only(optional=2)
with self.assertRaisesRegex(TypeError,
- "Required argument 'required' \(pos 1\) not found"):
+ r"Required argument 'required' \(pos 1\) not found"):
getargs_keyword_only(keyword_only=3)
def test_too_many_args(self):
with self.assertRaisesRegex(TypeError,
- "Function takes at most 2 positional arguments \(3 given\)"):
+ r"Function takes at most 2 positional arguments \(3 given\)"):
getargs_keyword_only(1, 2, 3)
with self.assertRaisesRegex(TypeError,
- "function takes at most 3 arguments \(4 given\)"):
+ r"function takes at most 3 arguments \(4 given\)"):
getargs_keyword_only(1, 2, 3, keyword_only=5)
def test_invalid_keyword(self):
@@ -673,11 +673,11 @@ class PositionalOnlyAndKeywords_TestCase(unittest.TestCase):
self.assertEqual(self.getargs(1), (1, -1, -1))
# required positional arg missing
with self.assertRaisesRegex(TypeError,
- "Function takes at least 1 positional arguments \(0 given\)"):
+ r"Function takes at least 1 positional arguments \(0 given\)"):
self.getargs()
with self.assertRaisesRegex(TypeError,
- "Function takes at least 1 positional arguments \(0 given\)"):
+ r"Function takes at least 1 positional arguments \(0 given\)"):
self.getargs(keyword=3)
def test_empty_keyword(self):
diff --git a/Lib/test/test_htmlparser.py b/Lib/test/test_htmlparser.py
index a7f53d3..326e342 100644
--- a/Lib/test/test_htmlparser.py
+++ b/Lib/test/test_htmlparser.py
@@ -701,7 +701,7 @@ class AttributesTestCase(TestCaseBase):
def test_attr_funky_names2(self):
self._run_check(
- "<a $><b $=%><c \=/>",
+ r"<a $><b $=%><c \=/>",
[("starttag", "a", [("$", None)]),
("starttag", "b", [("$", "%")]),
("starttag", "c", [("\\", "/")])])
diff --git a/Lib/test/test_http_cookiejar.py b/Lib/test/test_http_cookiejar.py
index 49c01ae..6fee4df 100644
--- a/Lib/test/test_http_cookiejar.py
+++ b/Lib/test/test_http_cookiejar.py
@@ -1051,7 +1051,7 @@ class CookieTests(unittest.TestCase):
url = "http://foo.bar.com/"
interact_2965(c, url, "spam=eggs; Version=1; Port")
h = interact_2965(c, url)
- self.assertRegex(h, "\$Port([^=]|$)",
+ self.assertRegex(h, r"\$Port([^=]|$)",
"port with no value not returned with no value")
c = CookieJar(pol)
@@ -1396,9 +1396,9 @@ class LWPCookieTests(unittest.TestCase):
self.assertRegex(cookie, r'^\$Version="?1"?;')
self.assertRegex(cookie, r'Part_Number="?Rocket_Launcher_0001"?;'
- '\s*\$Path="\/acme"')
+ r'\s*\$Path="\/acme"')
self.assertRegex(cookie, r'Customer="?WILE_E_COYOTE"?;'
- '\s*\$Path="\/acme"')
+ r'\s*\$Path="\/acme"')
#
# 7. User Agent -> Server
diff --git a/Lib/test/test_mailcap.py b/Lib/test/test_mailcap.py
index 623fadb..5c7d6cb 100644
--- a/Lib/test/test_mailcap.py
+++ b/Lib/test/test_mailcap.py
@@ -101,7 +101,7 @@ class HelperFunctionTest(unittest.TestCase):
(["echo foo", "audio/*", "foo.txt"], "echo foo"),
(["echo %s", "audio/*", "foo.txt"], "echo foo.txt"),
(["echo %t", "audio/*", "foo.txt"], "echo audio/*"),
- (["echo \%t", "audio/*", "foo.txt"], "echo %t"),
+ (["echo \\%t", "audio/*", "foo.txt"], "echo %t"),
(["echo foo", "audio/*", "foo.txt", plist], "echo foo"),
(["echo %{total}", "audio/*", "foo.txt", plist], "echo 3")
]
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index aee31ed..b504cf7 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -2086,7 +2086,7 @@ class Win32JunctionTests(unittest.TestCase):
class NonLocalSymlinkTests(unittest.TestCase):
def setUp(self):
- """
+ r"""
Create this structure:
base
diff --git a/Lib/test/test_platform.py b/Lib/test/test_platform.py
index ed18773..8eed7c0 100644
--- a/Lib/test/test_platform.py
+++ b/Lib/test/test_platform.py
@@ -255,7 +255,7 @@ class PlatformTest(unittest.TestCase):
with warnings.catch_warnings():
warnings.filterwarnings(
'ignore',
- 'dist\(\) and linux_distribution\(\) '
+ r'dist\(\) and linux_distribution\(\) '
'functions are deprecated .*',
PendingDeprecationWarning,
)
@@ -331,7 +331,7 @@ class PlatformTest(unittest.TestCase):
with warnings.catch_warnings():
warnings.filterwarnings(
'ignore',
- 'dist\(\) and linux_distribution\(\) '
+ r'dist\(\) and linux_distribution\(\) '
'functions are deprecated .*',
PendingDeprecationWarning,
)
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index 24a0604..02fed21 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -113,10 +113,10 @@ class ReTests(unittest.TestCase):
self.assertEqual(re.sub('(.)', re.escape(s), 'x'), s)
self.assertEqual(re.sub('(.)', lambda m: s, 'x'), s)
- self.assertEqual(re.sub('(?P<a>x)', '\g<a>\g<a>', 'xx'), 'xxxx')
- self.assertEqual(re.sub('(?P<a>x)', '\g<a>\g<1>', 'xx'), 'xxxx')
- self.assertEqual(re.sub('(?P<unk>x)', '\g<unk>\g<unk>', 'xx'), 'xxxx')
- self.assertEqual(re.sub('(?P<unk>x)', '\g<1>\g<1>', 'xx'), 'xxxx')
+ self.assertEqual(re.sub('(?P<a>x)', r'\g<a>\g<a>', 'xx'), 'xxxx')
+ self.assertEqual(re.sub('(?P<a>x)', r'\g<a>\g<1>', 'xx'), 'xxxx')
+ self.assertEqual(re.sub('(?P<unk>x)', r'\g<unk>\g<unk>', 'xx'), 'xxxx')
+ self.assertEqual(re.sub('(?P<unk>x)', r'\g<1>\g<1>', 'xx'), 'xxxx')
self.assertEqual(re.sub('a', r'\t\n\v\r\f\a\b', 'a'), '\t\n\v\r\f\a\b')
self.assertEqual(re.sub('a', '\t\n\v\r\f\a\b', 'a'), '\t\n\v\r\f\a\b')
@@ -127,11 +127,11 @@ class ReTests(unittest.TestCase):
with self.assertRaises(re.error):
self.assertEqual(re.sub('a', '\\' + c, 'a'), '\\' + c)
- self.assertEqual(re.sub('^\s*', 'X', 'test'), 'Xtest')
+ self.assertEqual(re.sub(r'^\s*', 'X', 'test'), 'Xtest')
def test_bug_449964(self):
# fails for group followed by other escape
- self.assertEqual(re.sub(r'(?P<unk>x)', '\g<1>\g<1>\\b', 'xx'),
+ self.assertEqual(re.sub(r'(?P<unk>x)', r'\g<1>\g<1>\b', 'xx'),
'xx\bxx\b')
def test_bug_449000(self):
@@ -218,26 +218,26 @@ class ReTests(unittest.TestCase):
self.assertEqual(re.sub('x+', '-', 'abxd'), 'ab-d')
def test_symbolic_groups(self):
- re.compile('(?P<a>x)(?P=a)(?(a)y)')
- re.compile('(?P<a1>x)(?P=a1)(?(a1)y)')
- re.compile('(?P<a1>x)\1(?(1)y)')
- self.checkPatternError('(?P<a>)(?P<a>)',
+ re.compile(r'(?P<a>x)(?P=a)(?(a)y)')
+ re.compile(r'(?P<a1>x)(?P=a1)(?(a1)y)')
+ re.compile(r'(?P<a1>x)\1(?(1)y)')
+ self.checkPatternError(r'(?P<a>)(?P<a>)',
"redefinition of group name 'a' as group 2; "
"was group 1")
- self.checkPatternError('(?P<a>(?P=a))',
+ self.checkPatternError(r'(?P<a>(?P=a))',
"cannot refer to an open group", 10)
- self.checkPatternError('(?Pxy)', 'unknown extension ?Px')
- self.checkPatternError('(?P<a>)(?P=a', 'missing ), unterminated name', 11)
- self.checkPatternError('(?P=', 'missing group name', 4)
- self.checkPatternError('(?P=)', 'missing group name', 4)
- self.checkPatternError('(?P=1)', "bad character in group name '1'", 4)
- self.checkPatternError('(?P=a)', "unknown group name 'a'")
- self.checkPatternError('(?P=a1)', "unknown group name 'a1'")
- self.checkPatternError('(?P=a.)', "bad character in group name 'a.'", 4)
- self.checkPatternError('(?P<)', 'missing >, unterminated name', 4)
- self.checkPatternError('(?P<a', 'missing >, unterminated name', 4)
- self.checkPatternError('(?P<', 'missing group name', 4)
- self.checkPatternError('(?P<>)', 'missing group name', 4)
+ self.checkPatternError(r'(?Pxy)', 'unknown extension ?Px')
+ self.checkPatternError(r'(?P<a>)(?P=a', 'missing ), unterminated name', 11)
+ self.checkPatternError(r'(?P=', 'missing group name', 4)
+ self.checkPatternError(r'(?P=)', 'missing group name', 4)
+ self.checkPatternError(r'(?P=1)', "bad character in group name '1'", 4)
+ self.checkPatternError(r'(?P=a)', "unknown group name 'a'")
+ self.checkPatternError(r'(?P=a1)', "unknown group name 'a1'")
+ self.checkPatternError(r'(?P=a.)', "bad character in group name 'a.'", 4)
+ self.checkPatternError(r'(?P<)', 'missing >, unterminated name', 4)
+ self.checkPatternError(r'(?P<a', 'missing >, unterminated name', 4)
+ self.checkPatternError(r'(?P<', 'missing group name', 4)
+ self.checkPatternError(r'(?P<>)', 'missing group name', 4)
self.checkPatternError(r'(?P<1>)', "bad character in group name '1'", 4)
self.checkPatternError(r'(?P<a.>)', "bad character in group name 'a.'", 4)
self.checkPatternError(r'(?(', 'missing group name', 3)
@@ -256,35 +256,35 @@ class ReTests(unittest.TestCase):
self.assertEqual(re.match(pat, 'xc8yz').span(), (0, 5))
def test_symbolic_refs(self):
- self.checkTemplateError('(?P<a>x)', '\g<a', 'xx',
+ self.checkTemplateError('(?P<a>x)', r'\g<a', 'xx',
'missing >, unterminated name', 3)
- self.checkTemplateError('(?P<a>x)', '\g<', 'xx',
+ self.checkTemplateError('(?P<a>x)', r'\g<', 'xx',
'missing group name', 3)
- self.checkTemplateError('(?P<a>x)', '\g', 'xx', 'missing <', 2)
- self.checkTemplateError('(?P<a>x)', '\g<a a>', 'xx',
+ self.checkTemplateError('(?P<a>x)', r'\g', 'xx', 'missing <', 2)
+ self.checkTemplateError('(?P<a>x)', r'\g<a a>', 'xx',
"bad character in group name 'a a'", 3)
- self.checkTemplateError('(?P<a>x)', '\g<>', 'xx',
+ self.checkTemplateError('(?P<a>x)', r'\g<>', 'xx',
'missing group name', 3)
- self.checkTemplateError('(?P<a>x)', '\g<1a1>', 'xx',
+ self.checkTemplateError('(?P<a>x)', r'\g<1a1>', 'xx',
"bad character in group name '1a1'", 3)
self.checkTemplateError('(?P<a>x)', r'\g<2>', 'xx',
'invalid group reference')
self.checkTemplateError('(?P<a>x)', r'\2', 'xx',
'invalid group reference')
with self.assertRaisesRegex(IndexError, "unknown group name 'ab'"):
- re.sub('(?P<a>x)', '\g<ab>', 'xx')
+ re.sub('(?P<a>x)', r'\g<ab>', 'xx')
self.assertEqual(re.sub('(?P<a>x)|(?P<b>y)', r'\g<b>', 'xx'), '')
self.assertEqual(re.sub('(?P<a>x)|(?P<b>y)', r'\2', 'xx'), '')
- self.checkTemplateError('(?P<a>x)', '\g<-1>', 'xx',
+ self.checkTemplateError('(?P<a>x)', r'\g<-1>', 'xx',
"bad character in group name '-1'", 3)
# New valid/invalid identifiers in Python 3
self.assertEqual(re.sub('(?P<ยต>x)', r'\g<ยต>', 'xx'), 'xx')
self.assertEqual(re.sub('(?P<๐”˜๐”ซ๐”ฆ๐” ๐”ฌ๐”ก๐”ข>x)', r'\g<๐”˜๐”ซ๐”ฆ๐” ๐”ฌ๐”ก๐”ข>', 'xx'), 'xx')
- self.checkTemplateError('(?P<a>x)', '\g<ยฉ>', 'xx',
+ self.checkTemplateError('(?P<a>x)', r'\g<ยฉ>', 'xx',
"bad character in group name 'ยฉ'", 3)
# Support > 100 groups.
pat = '|'.join('x(?P<a%d>%x)y' % (i, i) for i in range(1, 200 + 1))
- self.assertEqual(re.sub(pat, '\g<200>', 'xc8yzxc8y'), 'c8zc8')
+ self.assertEqual(re.sub(pat, r'\g<200>', 'xc8yzxc8y'), 'c8zc8')
def test_re_subn(self):
self.assertEqual(re.subn("(?i)b+", "x", "bbbb BBBB"), ('x x', 2))
@@ -472,19 +472,19 @@ class ReTests(unittest.TestCase):
re.compile(r".*?").fullmatch("abcd", pos=1, endpos=3).span(), (1, 3))
def test_re_groupref_exists(self):
- self.assertEqual(re.match('^(\()?([^()]+)(?(1)\))$', '(a)').groups(),
+ self.assertEqual(re.match(r'^(\()?([^()]+)(?(1)\))$', '(a)').groups(),
('(', 'a'))
- self.assertEqual(re.match('^(\()?([^()]+)(?(1)\))$', 'a').groups(),
+ self.assertEqual(re.match(r'^(\()?([^()]+)(?(1)\))$', 'a').groups(),
(None, 'a'))
- self.assertIsNone(re.match('^(\()?([^()]+)(?(1)\))$', 'a)'))
- self.assertIsNone(re.match('^(\()?([^()]+)(?(1)\))$', '(a'))
+ self.assertIsNone(re.match(r'^(\()?([^()]+)(?(1)\))$', 'a)'))
+ self.assertIsNone(re.match(r'^(\()?([^()]+)(?(1)\))$', '(a'))
self.assertEqual(re.match('^(?:(a)|c)((?(1)b|d))$', 'ab').groups(),
('a', 'b'))
- self.assertEqual(re.match('^(?:(a)|c)((?(1)b|d))$', 'cd').groups(),
+ self.assertEqual(re.match(r'^(?:(a)|c)((?(1)b|d))$', 'cd').groups(),
(None, 'd'))
- self.assertEqual(re.match('^(?:(a)|c)((?(1)|d))$', 'cd').groups(),
+ self.assertEqual(re.match(r'^(?:(a)|c)((?(1)|d))$', 'cd').groups(),
(None, 'd'))
- self.assertEqual(re.match('^(?:(a)|c)((?(1)|d))$', 'a').groups(),
+ self.assertEqual(re.match(r'^(?:(a)|c)((?(1)|d))$', 'a').groups(),
('a', ''))
# Tests for bug #1177831: exercise groups other than the first group
@@ -509,7 +509,7 @@ class ReTests(unittest.TestCase):
'two branches', 10)
def test_re_groupref_overflow(self):
- self.checkTemplateError('()', '\g<%s>' % sre_constants.MAXGROUPS, 'xx',
+ self.checkTemplateError('()', r'\g<%s>' % sre_constants.MAXGROUPS, 'xx',
'invalid group reference', 3)
self.checkPatternError(r'(?P<a>)(?(%d))' % sre_constants.MAXGROUPS,
'invalid group reference', 10)
@@ -544,37 +544,37 @@ class ReTests(unittest.TestCase):
" ")
def test_repeat_minmax(self):
- self.assertIsNone(re.match("^(\w){1}$", "abc"))
- self.assertIsNone(re.match("^(\w){1}?$", "abc"))
- self.assertIsNone(re.match("^(\w){1,2}$", "abc"))
- self.assertIsNone(re.match("^(\w){1,2}?$", "abc"))
-
- self.assertEqual(re.match("^(\w){3}$", "abc").group(1), "c")
- self.assertEqual(re.match("^(\w){1,3}$", "abc").group(1), "c")
- self.assertEqual(re.match("^(\w){1,4}$", "abc").group(1), "c")
- self.assertEqual(re.match("^(\w){3,4}?$", "abc").group(1), "c")
- self.assertEqual(re.match("^(\w){3}?$", "abc").group(1), "c")
- self.assertEqual(re.match("^(\w){1,3}?$", "abc").group(1), "c")
- self.assertEqual(re.match("^(\w){1,4}?$", "abc").group(1), "c")
- self.assertEqual(re.match("^(\w){3,4}?$", "abc").group(1), "c")
-
- self.assertIsNone(re.match("^x{1}$", "xxx"))
- self.assertIsNone(re.match("^x{1}?$", "xxx"))
- self.assertIsNone(re.match("^x{1,2}$", "xxx"))
- self.assertIsNone(re.match("^x{1,2}?$", "xxx"))
-
- self.assertTrue(re.match("^x{3}$", "xxx"))
- self.assertTrue(re.match("^x{1,3}$", "xxx"))
- self.assertTrue(re.match("^x{3,3}$", "xxx"))
- self.assertTrue(re.match("^x{1,4}$", "xxx"))
- self.assertTrue(re.match("^x{3,4}?$", "xxx"))
- self.assertTrue(re.match("^x{3}?$", "xxx"))
- self.assertTrue(re.match("^x{1,3}?$", "xxx"))
- self.assertTrue(re.match("^x{1,4}?$", "xxx"))
- self.assertTrue(re.match("^x{3,4}?$", "xxx"))
-
- self.assertIsNone(re.match("^x{}$", "xxx"))
- self.assertTrue(re.match("^x{}$", "x{}"))
+ self.assertIsNone(re.match(r"^(\w){1}$", "abc"))
+ self.assertIsNone(re.match(r"^(\w){1}?$", "abc"))
+ self.assertIsNone(re.match(r"^(\w){1,2}$", "abc"))
+ self.assertIsNone(re.match(r"^(\w){1,2}?$", "abc"))
+
+ self.assertEqual(re.match(r"^(\w){3}$", "abc").group(1), "c")
+ self.assertEqual(re.match(r"^(\w){1,3}$", "abc").group(1), "c")
+ self.assertEqual(re.match(r"^(\w){1,4}$", "abc").group(1), "c")
+ self.assertEqual(re.match(r"^(\w){3,4}?$", "abc").group(1), "c")
+ self.assertEqual(re.match(r"^(\w){3}?$", "abc").group(1), "c")
+ self.assertEqual(re.match(r"^(\w){1,3}?$", "abc").group(1), "c")
+ self.assertEqual(re.match(r"^(\w){1,4}?$", "abc").group(1), "c")
+ self.assertEqual(re.match(r"^(\w){3,4}?$", "abc").group(1), "c")
+
+ self.assertIsNone(re.match(r"^x{1}$", "xxx"))
+ self.assertIsNone(re.match(r"^x{1}?$", "xxx"))
+ self.assertIsNone(re.match(r"^x{1,2}$", "xxx"))
+ self.assertIsNone(re.match(r"^x{1,2}?$", "xxx"))
+
+ self.assertTrue(re.match(r"^x{3}$", "xxx"))
+ self.assertTrue(re.match(r"^x{1,3}$", "xxx"))
+ self.assertTrue(re.match(r"^x{3,3}$", "xxx"))
+ self.assertTrue(re.match(r"^x{1,4}$", "xxx"))
+ self.assertTrue(re.match(r"^x{3,4}?$", "xxx"))
+ self.assertTrue(re.match(r"^x{3}?$", "xxx"))
+ self.assertTrue(re.match(r"^x{1,3}?$", "xxx"))
+ self.assertTrue(re.match(r"^x{1,4}?$", "xxx"))
+ self.assertTrue(re.match(r"^x{3,4}?$", "xxx"))
+
+ self.assertIsNone(re.match(r"^x{}$", "xxx"))
+ self.assertTrue(re.match(r"^x{}$", "x{}"))
self.checkPatternError(r'x{2,1}',
'min repeat greater than max repeat', 2)
@@ -697,10 +697,10 @@ class ReTests(unittest.TestCase):
"a\n\nb")
def test_lookahead(self):
- self.assertEqual(re.match("(a(?=\s[^a]))", "a b").group(1), "a")
- self.assertEqual(re.match("(a(?=\s[^a]*))", "a b").group(1), "a")
- self.assertEqual(re.match("(a(?=\s[abc]))", "a b").group(1), "a")
- self.assertEqual(re.match("(a(?=\s[abc]*))", "a bc").group(1), "a")
+ self.assertEqual(re.match(r"(a(?=\s[^a]))", "a b").group(1), "a")
+ self.assertEqual(re.match(r"(a(?=\s[^a]*))", "a b").group(1), "a")
+ self.assertEqual(re.match(r"(a(?=\s[abc]))", "a b").group(1), "a")
+ self.assertEqual(re.match(r"(a(?=\s[abc]*))", "a bc").group(1), "a")
self.assertEqual(re.match(r"(a)(?=\s\1)", "a a").group(1), "a")
self.assertEqual(re.match(r"(a)(?=\s\1*)", "a aa").group(1), "a")
self.assertEqual(re.match(r"(a)(?=\s(abc|a))", "a a").group(1), "a")
@@ -848,12 +848,12 @@ class ReTests(unittest.TestCase):
self.assertEqual(re.match(b"abc", b"ABC", re.I|re.L).group(0), b"ABC")
def test_not_literal(self):
- self.assertEqual(re.search("\s([^a])", " b").group(1), "b")
- self.assertEqual(re.search("\s([^a]*)", " bb").group(1), "bb")
+ self.assertEqual(re.search(r"\s([^a])", " b").group(1), "b")
+ self.assertEqual(re.search(r"\s([^a]*)", " bb").group(1), "bb")
def test_search_coverage(self):
- self.assertEqual(re.search("\s(b)", " b").group(1), "b")
- self.assertEqual(re.search("a\s", "a ").group(0), "a ")
+ self.assertEqual(re.search(r"\s(b)", " b").group(1), "b")
+ self.assertEqual(re.search(r"a\s", "a ").group(0), "a ")
def assertMatch(self, pattern, text, match=None, span=None,
matcher=re.match):
@@ -1055,8 +1055,8 @@ class ReTests(unittest.TestCase):
self.assertIsNone(re.match(r'(a)?a','a').lastindex)
self.assertEqual(re.match(r'(a)(b)?b','ab').lastindex, 1)
self.assertEqual(re.match(r'(?P<a>a)(?P<b>b)?b','ab').lastgroup, 'a')
- self.assertEqual(re.match("(?P<a>a(b))", "ab").lastgroup, 'a')
- self.assertEqual(re.match("((a))", "a").lastindex, 1)
+ self.assertEqual(re.match(r"(?P<a>a(b))", "ab").lastgroup, 'a')
+ self.assertEqual(re.match(r"((a))", "a").lastindex, 1)
def test_bug_418626(self):
# bugs 418626 at al. -- Testing Greg Chapman's addition of op code
@@ -1228,7 +1228,7 @@ class ReTests(unittest.TestCase):
'\uff10', # '\N{FULLWIDTH DIGIT ZERO}', category 'Nd'
]
for x in decimal_digits:
- self.assertEqual(re.match('^\d$', x).group(0), x)
+ self.assertEqual(re.match(r'^\d$', x).group(0), x)
not_decimal_digits = [
'\u2165', # '\N{ROMAN NUMERAL SIX}', category 'Nl'
@@ -1237,7 +1237,7 @@ class ReTests(unittest.TestCase):
'\u32b4', # '\N{CIRCLED NUMBER THIRTY NINE}', category 'No'
]
for x in not_decimal_digits:
- self.assertIsNone(re.match('^\d$', x))
+ self.assertIsNone(re.match(r'^\d$', x))
def test_empty_array(self):
# SF buf 1647541
@@ -1306,29 +1306,29 @@ class ReTests(unittest.TestCase):
for flags in (0, re.UNICODE):
pat = re.compile('\xc0', flags | re.IGNORECASE)
self.assertTrue(pat.match('\xe0'))
- pat = re.compile('\w', flags)
+ pat = re.compile(r'\w', flags)
self.assertTrue(pat.match('\xe0'))
pat = re.compile('\xc0', re.ASCII | re.IGNORECASE)
self.assertIsNone(pat.match('\xe0'))
pat = re.compile('(?a)\xc0', re.IGNORECASE)
self.assertIsNone(pat.match('\xe0'))
- pat = re.compile('\w', re.ASCII)
+ pat = re.compile(r'\w', re.ASCII)
self.assertIsNone(pat.match('\xe0'))
- pat = re.compile('(?a)\w')
+ pat = re.compile(r'(?a)\w')
self.assertIsNone(pat.match('\xe0'))
# Bytes patterns
for flags in (0, re.ASCII):
pat = re.compile(b'\xc0', flags | re.IGNORECASE)
self.assertIsNone(pat.match(b'\xe0'))
- pat = re.compile(b'\w', flags)
+ pat = re.compile(br'\w', flags)
self.assertIsNone(pat.match(b'\xe0'))
# Incompatibilities
- self.assertRaises(ValueError, re.compile, b'\w', re.UNICODE)
- self.assertRaises(ValueError, re.compile, b'(?u)\w')
- self.assertRaises(ValueError, re.compile, '\w', re.UNICODE | re.ASCII)
- self.assertRaises(ValueError, re.compile, '(?u)\w', re.ASCII)
- self.assertRaises(ValueError, re.compile, '(?a)\w', re.UNICODE)
- self.assertRaises(ValueError, re.compile, '(?au)\w')
+ self.assertRaises(ValueError, re.compile, br'\w', re.UNICODE)
+ self.assertRaises(ValueError, re.compile, br'(?u)\w')
+ self.assertRaises(ValueError, re.compile, r'\w', re.UNICODE | re.ASCII)
+ self.assertRaises(ValueError, re.compile, r'(?u)\w', re.ASCII)
+ self.assertRaises(ValueError, re.compile, r'(?a)\w', re.UNICODE)
+ self.assertRaises(ValueError, re.compile, r'(?au)\w')
def test_locale_flag(self):
import locale
@@ -1359,13 +1359,13 @@ class ReTests(unittest.TestCase):
pat = re.compile(bpat, re.IGNORECASE)
if bletter:
self.assertIsNone(pat.match(bletter))
- pat = re.compile(b'\w', re.LOCALE)
+ pat = re.compile(br'\w', re.LOCALE)
if bletter:
self.assertTrue(pat.match(bletter))
- pat = re.compile(b'(?L)\w')
+ pat = re.compile(br'(?L)\w')
if bletter:
self.assertTrue(pat.match(bletter))
- pat = re.compile(b'\w')
+ pat = re.compile(br'\w')
if bletter:
self.assertIsNone(pat.match(bletter))
# Incompatibilities
@@ -1379,7 +1379,7 @@ class ReTests(unittest.TestCase):
def test_bug_6509(self):
# Replacement strings of both types must parse properly.
# all strings
- pat = re.compile('a(\w)')
+ pat = re.compile(r'a(\w)')
self.assertEqual(pat.sub('b\\1', 'ac'), 'bc')
pat = re.compile('a(.)')
self.assertEqual(pat.sub('b\\1', 'a\u1234'), 'b\u1234')
@@ -1387,7 +1387,7 @@ class ReTests(unittest.TestCase):
self.assertEqual(pat.sub(lambda m: 'str', 'a5'), 'str')
# all bytes
- pat = re.compile(b'a(\w)')
+ pat = re.compile(br'a(\w)')
self.assertEqual(pat.sub(b'b\\1', b'ac'), b'bc')
pat = re.compile(b'a(.)')
self.assertEqual(pat.sub(b'b\\1', b'a\xCD'), b'b\xCD')
@@ -1509,7 +1509,7 @@ class ReTests(unittest.TestCase):
for string in (b'[abracadabra]', B(b'[abracadabra]'),
bytearray(b'[abracadabra]'),
memoryview(b'[abracadabra]')):
- m = re.search(rb'(.+)(.*?)\1', string)
+ m = re.search(br'(.+)(.*?)\1', string)
self.assertEqual(repr(m), "<%s.%s object; "
"span=(1, 12), match=b'abracadabra'>" %
(type(m).__module__, type(m).__qualname__))
diff --git a/Lib/test/test_regrtest.py b/Lib/test/test_regrtest.py
index dc15461..7c95b64 100644
--- a/Lib/test/test_regrtest.py
+++ b/Lib/test/test_regrtest.py
@@ -704,8 +704,8 @@ class ArgsTestCase(BaseTestCase):
test = self.create_test('coverage')
output = self.run_tests("--coverage", test)
self.check_executed_tests(output, [test])
- regex = ('lines +cov% +module +\(path\)\n'
- '(?: *[0-9]+ *[0-9]{1,2}% *[^ ]+ +\([^)]+\)+)+')
+ regex = (r'lines +cov% +module +\(path\)\n'
+ r'(?: *[0-9]+ *[0-9]{1,2}% *[^ ]+ +\([^)]+\)+)+')
self.check_line(output, regex)
def test_wait(self):
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
index d8d53af..0bdb86d 100644
--- a/Lib/test/test_ssl.py
+++ b/Lib/test/test_ssl.py
@@ -3405,7 +3405,7 @@ def test_main(verbose=False):
with warnings.catch_warnings():
warnings.filterwarnings(
'ignore',
- 'dist\(\) and linux_distribution\(\) '
+ r'dist\(\) and linux_distribution\(\) '
'functions are deprecated .*',
PendingDeprecationWarning,
)
diff --git a/Lib/test/test_strftime.py b/Lib/test/test_strftime.py
index 772cd06..72b1910 100644
--- a/Lib/test/test_strftime.py
+++ b/Lib/test/test_strftime.py
@@ -23,9 +23,9 @@ def escapestr(text, ampm):
"""
new_text = re.escape(text)
new_text = new_text.replace(re.escape(ampm), ampm)
- new_text = new_text.replace('\%', '%')
- new_text = new_text.replace('\:', ':')
- new_text = new_text.replace('\?', '?')
+ new_text = new_text.replace(r'\%', '%')
+ new_text = new_text.replace(r'\:', ':')
+ new_text = new_text.replace(r'\?', '?')
return new_text
diff --git a/Lib/test/test_strlit.py b/Lib/test/test_strlit.py
index 87cffe8..37ace23 100644
--- a/Lib/test/test_strlit.py
+++ b/Lib/test/test_strlit.py
@@ -121,9 +121,9 @@ class TestLiterals(unittest.TestCase):
self.assertEqual(eval(""" b'\x01' """), byte(1))
self.assertEqual(eval(r""" b'\x81' """), byte(0x81))
self.assertRaises(SyntaxError, eval, """ b'\x81' """)
- self.assertEqual(eval(r""" b'\u1881' """), b'\\' + b'u1881')
+ self.assertEqual(eval(r""" br'\u1881' """), b'\\' + b'u1881')
self.assertRaises(SyntaxError, eval, """ b'\u1881' """)
- self.assertEqual(eval(r""" b'\U0001d120' """), b'\\' + b'U0001d120')
+ self.assertEqual(eval(r""" br'\U0001d120' """), b'\\' + b'U0001d120')
self.assertRaises(SyntaxError, eval, """ b'\U0001d120' """)
def test_eval_bytes_incomplete(self):
diff --git a/Lib/test/test_strptime.py b/Lib/test/test_strptime.py
index 8c8f97b..22eac32 100644
--- a/Lib/test/test_strptime.py
+++ b/Lib/test/test_strptime.py
@@ -129,7 +129,7 @@ class TimeRETests(unittest.TestCase):
def test_pattern_escaping(self):
# Make sure any characters in the format string that might be taken as
# regex syntax is escaped.
- pattern_string = self.time_re.pattern("\d+")
+ pattern_string = self.time_re.pattern(r"\d+")
self.assertIn(r"\\d\+", pattern_string,
"%s does not have re characters escaped properly" %
pattern_string)
@@ -170,9 +170,9 @@ class TimeRETests(unittest.TestCase):
def test_matching_with_escapes(self):
# Make sure a format that requires escaping of characters works
- compiled_re = self.time_re.compile("\w+ %m")
- found = compiled_re.match("\w+ 10")
- self.assertTrue(found, "Escaping failed of format '\w+ 10'")
+ compiled_re = self.time_re.compile(r"\w+ %m")
+ found = compiled_re.match(r"\w+ 10")
+ self.assertTrue(found, r"Escaping failed of format '\w+ 10'")
def test_locale_data_w_regex_metacharacters(self):
# Check that if locale data contains regex metacharacters they are
@@ -403,7 +403,7 @@ class StrptimeTests(unittest.TestCase):
# unbalanced parentheses when the regex is compiled if they are not
# escaped.
# Test instigated by bug #796149 .
- need_escaping = ".^$*+?{}\[]|)("
+ need_escaping = r".^$*+?{}\[]|)("
self.assertTrue(_strptime._strptime_time(need_escaping, need_escaping))
def test_feb29_on_leap_year_without_year(self):
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index 78f9668..9ab624e 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -1564,7 +1564,7 @@ class UnicodeTest(string_tests.CommonTest,
('+', b'+-'),
('+-', b'+--'),
('+?', b'+-?'),
- ('\?', b'+AFw?'),
+ (r'\?', b'+AFw?'),
('+?', b'+-?'),
(r'\\?', b'+AFwAXA?'),
(r'\\\?', b'+AFwAXABc?'),
@@ -2326,7 +2326,7 @@ class UnicodeTest(string_tests.CommonTest,
# non-ascii format, ascii argument: ensure that PyUnicode_FromFormatV()
# raises an error
self.assertRaisesRegex(ValueError,
- '^PyUnicode_FromFormatV\(\) expects an ASCII-encoded format '
+ r'^PyUnicode_FromFormatV\(\) expects an ASCII-encoded format '
'string, got a non-ASCII byte: 0xe9$',
PyUnicode_FromFormat, b'unicode\xe9=%s', 'ascii')
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
index 247598a..8f06b08 100644
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -729,7 +729,7 @@ FF
class QuotingTests(unittest.TestCase):
- """Tests for urllib.quote() and urllib.quote_plus()
+ r"""Tests for urllib.quote() and urllib.quote_plus()
According to RFC 2396 (Uniform Resource Identifiers), to escape a
character you write it as '%' + <2 character US-ASCII hex value>.
@@ -804,7 +804,7 @@ class QuotingTests(unittest.TestCase):
# Make sure all characters that should be quoted are by default sans
# space (separate test for that).
should_quote = [chr(num) for num in range(32)] # For 0x00 - 0x1F
- should_quote.append('<>#%"{}|\^[]`')
+ should_quote.append(r'<>#%"{}|\^[]`')
should_quote.append(chr(127)) # For 0x7F
should_quote = ''.join(should_quote)
for char in should_quote:
diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py
index 0773a86..29a9878 100644
--- a/Lib/test/test_xmlrpc.py
+++ b/Lib/test/test_xmlrpc.py
@@ -1218,7 +1218,7 @@ class CGIHandlerTestCase(unittest.TestCase):
content = handle[handle.find("<?xml"):]
self.assertEqual(
- int(re.search('Content-Length: (\d+)', handle).group(1)),
+ int(re.search(r'Content-Length: (\d+)', handle).group(1)),
len(content))