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