diff options
Diffstat (limited to 'Lib/test/test_tools')
| -rw-r--r-- | Lib/test/test_tools/test_gprof2html.py | 2 | ||||
| -rw-r--r-- | Lib/test/test_tools/test_i18n.py | 68 | ||||
| -rw-r--r-- | Lib/test/test_tools/test_md5sum.py | 2 | ||||
| -rw-r--r-- | Lib/test/test_tools/test_pindent.py | 2 | ||||
| -rw-r--r-- | Lib/test/test_tools/test_reindent.py | 2 | ||||
| -rw-r--r-- | Lib/test/test_tools/test_unparse.py | 5 |
6 files changed, 77 insertions, 4 deletions
diff --git a/Lib/test/test_tools/test_gprof2html.py b/Lib/test/test_tools/test_gprof2html.py index 845a2a8..0c294ec 100644 --- a/Lib/test/test_tools/test_gprof2html.py +++ b/Lib/test/test_tools/test_gprof2html.py @@ -22,7 +22,7 @@ class Gprof2htmlTests(unittest.TestCase): sys.argv = [] def test_gprof(self): - # Issue #14508: this used to fail with an NameError. + # Issue #14508: this used to fail with a NameError. with mock.patch.object(self.gprof, 'webbrowser') as wmock, \ tempfile.TemporaryDirectory() as tmpdir: fn = os.path.join(tmpdir, 'abc') diff --git a/Lib/test/test_tools/test_i18n.py b/Lib/test/test_tools/test_i18n.py new file mode 100644 index 0000000..6eaa8dd --- /dev/null +++ b/Lib/test/test_tools/test_i18n.py @@ -0,0 +1,68 @@ +"""Tests to cover the Tools/i18n package""" + +import os +import unittest + +from test.support.script_helper import assert_python_ok +from test.test_tools import toolsdir +from test.support import temp_cwd + +class Test_pygettext(unittest.TestCase): + """Tests for the pygettext.py tool""" + + script = os.path.join(toolsdir,'i18n', 'pygettext.py') + + def get_header(self, data): + """ utility: return the header of a .po file as a dictionary """ + headers = {} + for line in data.split('\n'): + if not line or line.startswith(('#', 'msgid','msgstr')): + continue + line = line.strip('"') + key, val = line.split(':',1) + headers[key] = val.strip() + return headers + + def test_header(self): + """Make sure the required fields are in the header, according to: + http://www.gnu.org/software/gettext/manual/gettext.html#Header-Entry + """ + with temp_cwd(None) as cwd: + assert_python_ok(self.script) + with open('messages.pot') as fp: + data = fp.read() + header = self.get_header(data) + + self.assertIn("Project-Id-Version", header) + self.assertIn("POT-Creation-Date", header) + self.assertIn("PO-Revision-Date", header) + self.assertIn("Last-Translator", header) + self.assertIn("Language-Team", header) + self.assertIn("MIME-Version", header) + self.assertIn("Content-Type", header) + self.assertIn("Content-Transfer-Encoding", header) + self.assertIn("Generated-By", header) + + # not clear if these should be required in POT (template) files + #self.assertIn("Report-Msgid-Bugs-To", header) + #self.assertIn("Language", header) + + #"Plural-Forms" is optional + + + def test_POT_Creation_Date(self): + """ Match the date format from xgettext for POT-Creation-Date """ + from datetime import datetime + with temp_cwd(None) as cwd: + assert_python_ok(self.script) + with open('messages.pot') as fp: + data = fp.read() + header = self.get_header(data) + creationDate = header['POT-Creation-Date'] + + # peel off the escaped newline at the end of string + if creationDate.endswith('\\n'): + creationDate = creationDate[:-len('\\n')] + + # This will raise if the date format does not exactly match. + datetime.strptime(creationDate, '%Y-%m-%d %H:%M%z') diff --git a/Lib/test/test_tools/test_md5sum.py b/Lib/test/test_tools/test_md5sum.py index 59ea149..1305295 100644 --- a/Lib/test/test_tools/test_md5sum.py +++ b/Lib/test/test_tools/test_md5sum.py @@ -4,7 +4,7 @@ import os import sys import unittest from test import support -from test.script_helper import assert_python_ok, assert_python_failure +from test.support.script_helper import assert_python_ok, assert_python_failure from test.test_tools import scriptsdir, import_tool, skip_if_missing diff --git a/Lib/test/test_tools/test_pindent.py b/Lib/test/test_tools/test_pindent.py index 14a0aa2..e293bc8 100644 --- a/Lib/test/test_tools/test_pindent.py +++ b/Lib/test/test_tools/test_pindent.py @@ -6,7 +6,7 @@ import unittest import subprocess import textwrap from test import support -from test.script_helper import assert_python_ok +from test.support.script_helper import assert_python_ok from test.test_tools import scriptsdir, skip_if_missing diff --git a/Lib/test/test_tools/test_reindent.py b/Lib/test/test_tools/test_reindent.py index 45cebf7..d7c20e1 100644 --- a/Lib/test/test_tools/test_reindent.py +++ b/Lib/test/test_tools/test_reindent.py @@ -6,7 +6,7 @@ Tools directory of a Python checkout or tarball, such as reindent.py. import os import unittest -from test.script_helper import assert_python_ok +from test.support.script_helper import assert_python_ok from test.test_tools import scriptsdir, skip_if_missing diff --git a/Lib/test/test_tools/test_unparse.py b/Lib/test/test_tools/test_unparse.py index 976a6c5..734bbc2 100644 --- a/Lib/test/test_tools/test_unparse.py +++ b/Lib/test/test_tools/test_unparse.py @@ -250,6 +250,11 @@ class UnparseTestCase(ASTTestCase): def test_with_two_items(self): self.check_roundtrip(with_two_items) + def test_dict_unpacking_in_dict(self): + # See issue 26489 + self.check_roundtrip(r"""{**{'y': 2}, 'x': 1}""") + self.check_roundtrip(r"""{**{'y': 2}, **{'x': 1}}""") + class DirectoryTestCase(ASTTestCase): """Test roundtrip behaviour on all files in Lib and Lib/test.""" |
