22
33import os
44import unittest
5- import textwrap
5+ from textwrap import dedent
66
77from test .support .script_helper import assert_python_ok
88from test .test_tools import skip_if_missing , toolsdir
@@ -107,25 +107,84 @@ def test_POT_Creation_Date(self):
107107 # This will raise if the date format does not exactly match.
108108 datetime .strptime (creationDate , '%Y-%m-%d %H:%M%z' )
109109
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+
110169 def test_funcdocstring_annotated_args (self ):
111170 """ Test docstrings for functions with annotated args """
112- msgids = self .extract_docstrings_from_str (textwrap . dedent ('''\
171+ msgids = self .extract_docstrings_from_str (dedent ('''\
113172 def foo(bar: str):
114173 """doc"""
115174 ''' ))
116175 self .assertIn ('doc' , msgids )
117176
118177 def test_funcdocstring_annotated_return (self ):
119178 """ 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 ('''\
121180 def foo(bar) -> str:
122181 """doc"""
123182 ''' ))
124183 self .assertIn ('doc' , msgids )
125184
126185 def test_funcdocstring_defvalue_args (self ):
127186 """ 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 ('''\
129188 def foo(bar=()):
130189 """doc"""
131190 ''' ))
@@ -135,7 +194,7 @@ def test_funcdocstring_multiple_funcs(self):
135194 """ Test docstring extraction for multiple functions combining
136195 annotated args, annotated return types and default arg values
137196 """
138- msgids = self .extract_docstrings_from_str (textwrap . dedent ('''\
197+ msgids = self .extract_docstrings_from_str (dedent ('''\
139198 def foo1(bar: tuple=()) -> str:
140199 """doc1"""
141200
@@ -153,7 +212,7 @@ def test_classdocstring_early_colon(self):
153212 """ Test docstring extraction for a class with colons occuring within
154213 the parentheses.
155214 """
156- msgids = self .extract_docstrings_from_str (textwrap . dedent ('''\
215+ msgids = self .extract_docstrings_from_str (dedent ('''\
157216 class D(L[1:2], F({1: 2}), metaclass=M(lambda x: x)):
158217 """doc"""
159218 ''' ))
0 commit comments