summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2015-04-16 16:15:09 (GMT)
committerR David Murray <rdmurray@bitdance.com>2015-04-16 16:15:09 (GMT)
commit2b78129b3a2431d0ef80ec56aec084bf846bdef0 (patch)
tree2e83e44a3a533293e5104958f41030e00a2ef9fd /Lib
parent29fbd21d73dfecc1bb05e98d6da7fbab55ad15b4 (diff)
downloadcpython-2b78129b3a2431d0ef80ec56aec084bf846bdef0.zip
cpython-2b78129b3a2431d0ef80ec56aec084bf846bdef0.tar.gz
cpython-2b78129b3a2431d0ef80ec56aec084bf846bdef0.tar.bz2
#18128: use standard +NNNN timezone format in POT-Creation-Date header.
Patch by Michael McFadden, with a few small style tweaks.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_tools/test_i18n.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/Lib/test/test_tools/test_i18n.py b/Lib/test/test_tools/test_i18n.py
new file mode 100644
index 0000000..e88e2b1
--- /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.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')