Skip to content

Commit 31c377c

Browse files
Fix diff
1 parent cf2917f commit 31c377c

File tree

1 file changed

+54
-54
lines changed

1 file changed

+54
-54
lines changed

Lib/test/test_tools/test_i18n.py

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,60 @@ def get_msgids(self, data):
8282

8383
return msgids
8484

85+
def assert_POT_equal(self, expected, actual):
86+
"""Check if two POT files are equal"""
87+
self.maxDiff = None
88+
self.assertEqual(normalize_POT_file(expected), normalize_POT_file(actual))
89+
90+
def extract_from_str(self, module_content, *, args=(), strict=True, with_stderr=False):
91+
"""Return all msgids extracted from module_content."""
92+
filename = 'test.py'
93+
with temp_cwd(None):
94+
with open(filename, 'w', encoding='utf-8') as fp:
95+
fp.write(module_content)
96+
res = assert_python_ok('-Xutf8', self.script, *args, filename)
97+
if strict:
98+
self.assertEqual(res.err, b'')
99+
with open('messages.pot', encoding='utf-8') as fp:
100+
data = fp.read()
101+
msgids = self.get_msgids(data)
102+
if not with_stderr:
103+
return msgids
104+
return msgids, res.err
105+
106+
def extract_docstrings_from_str(self, module_content):
107+
"""Return all docstrings extracted from module_content."""
108+
return self.extract_from_str(module_content, args=('--docstrings',), strict=False)
109+
110+
def get_stderr(self, module_content):
111+
return self.extract_from_str(module_content, strict=False, with_stderr=True)[1]
112+
113+
def test_header(self):
114+
"""Make sure the required fields are in the header, according to:
115+
http://www.gnu.org/software/gettext/manual/gettext.html#Header-Entry
116+
"""
117+
with temp_cwd(None) as cwd:
118+
assert_python_ok('-Xutf8', self.script)
119+
with open('messages.pot', encoding='utf-8') as fp:
120+
data = fp.read()
121+
header = self.get_header(data)
122+
123+
self.assertIn("Project-Id-Version", header)
124+
self.assertIn("POT-Creation-Date", header)
125+
self.assertIn("PO-Revision-Date", header)
126+
self.assertIn("Last-Translator", header)
127+
self.assertIn("Language-Team", header)
128+
self.assertIn("MIME-Version", header)
129+
self.assertIn("Content-Type", header)
130+
self.assertIn("Content-Transfer-Encoding", header)
131+
self.assertIn("Generated-By", header)
132+
133+
# not clear if these should be required in POT (template) files
134+
#self.assertIn("Report-Msgid-Bugs-To", header)
135+
#self.assertIn("Language", header)
136+
137+
#"Plural-Forms" is optional
138+
85139
def test_msgid(self):
86140
msgids = self.extract_docstrings_from_str(
87141
'''_("""doc""" r'str' u"ing")''')
@@ -166,60 +220,6 @@ def test_calls_in_fstring_with_partially_wrong_expression(self):
166220
self.assertNotIn('foo', msgids)
167221
self.assertIn('bar', msgids)
168222

169-
def assert_POT_equal(self, expected, actual):
170-
"""Check if two POT files are equal"""
171-
self.maxDiff = None
172-
self.assertEqual(normalize_POT_file(expected), normalize_POT_file(actual))
173-
174-
def extract_from_str(self, module_content, *, args=(), strict=True, with_stderr=False):
175-
"""Return all msgids extracted from module_content."""
176-
filename = 'test.py'
177-
with temp_cwd(None):
178-
with open(filename, 'w', encoding='utf-8') as fp:
179-
fp.write(module_content)
180-
res = assert_python_ok('-Xutf8', self.script, *args, filename)
181-
if strict:
182-
self.assertEqual(res.err, b'')
183-
with open('messages.pot', encoding='utf-8') as fp:
184-
data = fp.read()
185-
msgids = self.get_msgids(data)
186-
if not with_stderr:
187-
return msgids
188-
return msgids, res.err
189-
190-
def extract_docstrings_from_str(self, module_content):
191-
"""Return all docstrings extracted from module_content."""
192-
return self.extract_from_str(module_content, args=('--docstrings',), strict=False)
193-
194-
def get_stderr(self, module_content):
195-
return self.extract_from_str(module_content, strict=False, with_stderr=True)[1]
196-
197-
def test_header(self):
198-
"""Make sure the required fields are in the header, according to:
199-
http://www.gnu.org/software/gettext/manual/gettext.html#Header-Entry
200-
"""
201-
with temp_cwd(None) as cwd:
202-
assert_python_ok('-Xutf8', self.script)
203-
with open('messages.pot', encoding='utf-8') as fp:
204-
data = fp.read()
205-
header = self.get_header(data)
206-
207-
self.assertIn("Project-Id-Version", header)
208-
self.assertIn("POT-Creation-Date", header)
209-
self.assertIn("PO-Revision-Date", header)
210-
self.assertIn("Last-Translator", header)
211-
self.assertIn("Language-Team", header)
212-
self.assertIn("MIME-Version", header)
213-
self.assertIn("Content-Type", header)
214-
self.assertIn("Content-Transfer-Encoding", header)
215-
self.assertIn("Generated-By", header)
216-
217-
# not clear if these should be required in POT (template) files
218-
#self.assertIn("Report-Msgid-Bugs-To", header)
219-
#self.assertIn("Language", header)
220-
221-
#"Plural-Forms" is optional
222-
223223
@unittest.skipIf(sys.platform.startswith('aix'),
224224
'bpo-29972: broken test on AIX')
225225
def test_POT_Creation_Date(self):

0 commit comments

Comments
 (0)