bpo-33189: pygettext.py now accepts only literal strings (GH-6364) · python/cpython@6f87093 (original) (raw)
`@@ -2,7 +2,7 @@
`
2
2
``
3
3
`import os
`
4
4
`import unittest
`
5
``
`-
import textwrap
`
``
5
`+
from textwrap import dedent
`
6
6
``
7
7
`from test.support.script_helper import assert_python_ok
`
8
8
`from test.test_tools import skip_if_missing, toolsdir
`
`@@ -107,25 +107,84 @@ def test_POT_Creation_Date(self):
`
107
107
`# This will raise if the date format does not exactly match.
`
108
108
`datetime.strptime(creationDate, '%Y-%m-%d %H:%M%z')
`
109
109
``
``
110
`+
def test_funcdocstring(self):
`
``
111
`+
for doc in ('"""doc"""', "r'''doc'''", "R'doc'", 'u"doc"'):
`
``
112
`+
with self.subTest(doc):
`
``
113
`+
msgids = self.extract_docstrings_from_str(dedent('''\
`
``
114
`+
def foo(bar):
`
``
115
`+
%s
`
``
116
`+
''' % doc))
`
``
117
`+
self.assertIn('doc', msgids)
`
``
118
+
``
119
`+
def test_funcdocstring_bytes(self):
`
``
120
`+
msgids = self.extract_docstrings_from_str(dedent('''\
`
``
121
`+
def foo(bar):
`
``
122
`+
b"""doc"""
`
``
123
`+
'''))
`
``
124
`+
self.assertFalse([msgid for msgid in msgids if 'doc' in msgid])
`
``
125
+
``
126
`+
def test_funcdocstring_fstring(self):
`
``
127
`+
msgids = self.extract_docstrings_from_str(dedent('''\
`
``
128
`+
def foo(bar):
`
``
129
`+
f"""doc"""
`
``
130
`+
'''))
`
``
131
`+
self.assertFalse([msgid for msgid in msgids if 'doc' in msgid])
`
``
132
+
``
133
`+
def test_classdocstring(self):
`
``
134
`+
for doc in ('"""doc"""', "r'''doc'''", "R'doc'", 'u"doc"'):
`
``
135
`+
with self.subTest(doc):
`
``
136
`+
msgids = self.extract_docstrings_from_str(dedent('''\
`
``
137
`+
class C:
`
``
138
`+
%s
`
``
139
`+
''' % doc))
`
``
140
`+
self.assertIn('doc', msgids)
`
``
141
+
``
142
`+
def test_classdocstring_bytes(self):
`
``
143
`+
msgids = self.extract_docstrings_from_str(dedent('''\
`
``
144
`+
class C:
`
``
145
`+
b"""doc"""
`
``
146
`+
'''))
`
``
147
`+
self.assertFalse([msgid for msgid in msgids if 'doc' in msgid])
`
``
148
+
``
149
`+
def test_classdocstring_fstring(self):
`
``
150
`+
msgids = self.extract_docstrings_from_str(dedent('''\
`
``
151
`+
class C:
`
``
152
`+
f"""doc"""
`
``
153
`+
'''))
`
``
154
`+
self.assertFalse([msgid for msgid in msgids if 'doc' in msgid])
`
``
155
+
``
156
`+
def test_msgid(self):
`
``
157
`+
msgids = self.extract_docstrings_from_str(
`
``
158
`+
'''_("""doc""" r'str' u"ing")''')
`
``
159
`+
self.assertIn('docstring', msgids)
`
``
160
+
``
161
`+
def test_msgid_bytes(self):
`
``
162
`+
msgids = self.extract_docstrings_from_str('_(b"""doc""")')
`
``
163
`+
self.assertFalse([msgid for msgid in msgids if 'doc' in msgid])
`
``
164
+
``
165
`+
def test_msgid_fstring(self):
`
``
166
`+
msgids = self.extract_docstrings_from_str('_(f"""doc""")')
`
``
167
`+
self.assertFalse([msgid for msgid in msgids if 'doc' in msgid])
`
``
168
+
110
169
`def test_funcdocstring_annotated_args(self):
`
111
170
`""" Test docstrings for functions with annotated args """
`
112
``
`-
msgids = self.extract_docstrings_from_str(textwrap.dedent('''\
`
``
171
`+
msgids = self.extract_docstrings_from_str(dedent('''\
`
113
172
` def foo(bar: str):
`
114
173
` """doc"""
`
115
174
` '''))
`
116
175
`self.assertIn('doc', msgids)
`
117
176
``
118
177
`def test_funcdocstring_annotated_return(self):
`
119
178
`""" Test docstrings for functions with annotated return type """
`
120
``
`-
msgids = self.extract_docstrings_from_str(textwrap.dedent('''\
`
``
179
`+
msgids = self.extract_docstrings_from_str(dedent('''\
`
121
180
` def foo(bar) -> str:
`
122
181
` """doc"""
`
123
182
` '''))
`
124
183
`self.assertIn('doc', msgids)
`
125
184
``
126
185
`def test_funcdocstring_defvalue_args(self):
`
127
186
`""" Test docstring for functions with default arg values """
`
128
``
`-
msgids = self.extract_docstrings_from_str(textwrap.dedent('''\
`
``
187
`+
msgids = self.extract_docstrings_from_str(dedent('''\
`
129
188
` def foo(bar=()):
`
130
189
` """doc"""
`
131
190
` '''))
`
`@@ -135,7 +194,7 @@ def test_funcdocstring_multiple_funcs(self):
`
135
194
`""" Test docstring extraction for multiple functions combining
`
136
195
` annotated args, annotated return types and default arg values
`
137
196
` """
`
138
``
`-
msgids = self.extract_docstrings_from_str(textwrap.dedent('''\
`
``
197
`+
msgids = self.extract_docstrings_from_str(dedent('''\
`
139
198
` def foo1(bar: tuple=()) -> str:
`
140
199
` """doc1"""
`
141
200
``
`@@ -153,7 +212,7 @@ def test_classdocstring_early_colon(self):
`
153
212
`""" Test docstring extraction for a class with colons occuring within
`
154
213
` the parentheses.
`
155
214
` """
`
156
``
`-
msgids = self.extract_docstrings_from_str(textwrap.dedent('''\
`
``
215
`+
msgids = self.extract_docstrings_from_str(dedent('''\
`
157
216
` class D(L[1:2], F({1: 2}), metaclass=M(lambda x: x)):
`
158
217
` """doc"""
`
159
218
` '''))
`