@@ -82,6 +82,90 @@ def get_msgids(self, data):
8282
8383 return msgids
8484
85+ def test_msgid (self ):
86+ msgids = self .extract_docstrings_from_str (
87+ '''_("""doc""" r'str' u"ing")''' )
88+ self .assertIn ('docstring' , msgids )
89+
90+ def test_msgid_bytes (self ):
91+ msgids = self .extract_docstrings_from_str ('_(b"""doc""")' )
92+ self .assertFalse ([msgid for msgid in msgids if 'doc' in msgid ])
93+
94+ def test_msgid_fstring (self ):
95+ msgids = self .extract_docstrings_from_str ('_(f"""doc""")' )
96+ self .assertFalse ([msgid for msgid in msgids if 'doc' in msgid ])
97+
98+
99+ def test_calls_in_fstrings (self ):
100+ msgids = self .extract_docstrings_from_str (dedent ('''\
101+ f"{_('foo bar')}"
102+ ''' ))
103+ self .assertIn ('foo bar' , msgids )
104+
105+ def test_calls_in_fstrings_raw (self ):
106+ msgids = self .extract_docstrings_from_str (dedent ('''\
107+ rf"{_('foo bar')}"
108+ ''' ))
109+ self .assertIn ('foo bar' , msgids )
110+
111+ def test_calls_in_fstrings_nested (self ):
112+ msgids = self .extract_docstrings_from_str (dedent ('''\
113+ f"""{f'{_("foo bar")}'}"""
114+ ''' ))
115+ self .assertIn ('foo bar' , msgids )
116+
117+ def test_calls_in_fstrings_attribute (self ):
118+ msgids = self .extract_docstrings_from_str (dedent ('''\
119+ f"{obj._('foo bar')}"
120+ ''' ))
121+ self .assertIn ('foo bar' , msgids )
122+
123+ def test_calls_in_fstrings_with_call_on_call (self ):
124+ msgids = self .extract_docstrings_from_str (dedent ('''\
125+ f"{type(str)('foo bar')}"
126+ ''' ))
127+ self .assertNotIn ('foo bar' , msgids )
128+
129+ def test_calls_in_fstrings_with_format (self ):
130+ msgids = self .extract_docstrings_from_str (dedent ('''\
131+ f"{_('foo {bar}').format(bar='baz')}"
132+ ''' ))
133+ self .assertIn ('foo {bar}' , msgids )
134+
135+ def test_calls_in_fstrings_with_wrong_input_1 (self ):
136+ msgids = self .extract_docstrings_from_str (dedent ('''\
137+ f"{_(f'foo {bar}')}"
138+ ''' ))
139+ self .assertFalse ([msgid for msgid in msgids if 'foo {bar}' in msgid ])
140+
141+ def test_calls_in_fstrings_with_wrong_input_2 (self ):
142+ msgids = self .extract_docstrings_from_str (dedent ('''\
143+ f"{_(1)}"
144+ ''' ))
145+ self .assertNotIn (1 , msgids )
146+
147+ def test_calls_in_fstring_with_multiple_args (self ):
148+ msgids = self .extract_docstrings_from_str (dedent ('''\
149+ f"{_('foo', 'bar')}"
150+ ''' ))
151+ self .assertIn ('foo' , msgids )
152+ self .assertNotIn ('bar' , msgids )
153+
154+ def test_calls_in_fstring_with_keyword_args (self ):
155+ msgids = self .extract_docstrings_from_str (dedent ('''\
156+ f"{_('foo', bar='baz')}"
157+ ''' ))
158+ self .assertIn ('foo' , msgids )
159+ self .assertNotIn ('bar' , msgids )
160+ self .assertNotIn ('baz' , msgids )
161+
162+ def test_calls_in_fstring_with_partially_wrong_expression (self ):
163+ msgids = self .extract_docstrings_from_str (dedent ('''\
164+ f"{_(f'foo') + _('bar')}"
165+ ''' ))
166+ self .assertNotIn ('foo' , msgids )
167+ self .assertIn ('bar' , msgids )
168+
85169 def assert_POT_equal (self , expected , actual ):
86170 """Check if two POT files are equal"""
87171 self .maxDiff = None
0 commit comments