33import os
44import sys
55import unittest
6- import textwrap
6+ from textwrap import dedent
77
88from test .support .script_helper import assert_python_ok
99from test .test_tools import skip_if_missing , toolsdir
@@ -109,25 +109,84 @@ def test_POT_Creation_Date(self):
109109 # This will raise if the date format does not exactly match.
110110 datetime .strptime (creationDate , '%Y-%m-%d %H:%M%z' )
111111
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+
112171 def test_funcdocstring_annotated_args (self ):
113172 """ Test docstrings for functions with annotated args """
114- msgids = self .extract_docstrings_from_str (textwrap . dedent ('''\
173+ msgids = self .extract_docstrings_from_str (dedent ('''\
115174 def foo(bar: str):
116175 """doc"""
117176 ''' ))
118177 self .assertIn ('doc' , msgids )
119178
120179 def test_funcdocstring_annotated_return (self ):
121180 """ 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 ('''\
123182 def foo(bar) -> str:
124183 """doc"""
125184 ''' ))
126185 self .assertIn ('doc' , msgids )
127186
128187 def test_funcdocstring_defvalue_args (self ):
129188 """ 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 ('''\
131190 def foo(bar=()):
132191 """doc"""
133192 ''' ))
@@ -137,7 +196,7 @@ def test_funcdocstring_multiple_funcs(self):
137196 """ Test docstring extraction for multiple functions combining
138197 annotated args, annotated return types and default arg values
139198 """
140- msgids = self .extract_docstrings_from_str (textwrap . dedent ('''\
199+ msgids = self .extract_docstrings_from_str (dedent ('''\
141200 def foo1(bar: tuple=()) -> str:
142201 """doc1"""
143202
@@ -155,7 +214,7 @@ def test_classdocstring_early_colon(self):
155214 """ Test docstring extraction for a class with colons occuring within
156215 the parentheses.
157216 """
158- msgids = self .extract_docstrings_from_str (textwrap . dedent ('''\
217+ msgids = self .extract_docstrings_from_str (dedent ('''\
159218 class D(L[1:2], F({1: 2}), metaclass=M(lambda x: x)):
160219 """doc"""
161220 ''' ))
0 commit comments