Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1)

Unified Diff: Lib/test/test_tools/test_i18n.py

Issue 18128: pygettext: non-standard timestamp format in POT-Creation-Date
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Tools/i18n/pygettext.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
new file mode 100644
index 0000000..05a9abb
--- /dev/null
+++ b/Lib/test/test_tools/test_i18n.py
@@ -0,0 +1,75 @@
+"""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):
blackfawn 2015/04/16 18:58:42 Rename the class GettextTests or PygettextTests to
+ """Tests for the pygettext.py tool"""
+
+ script = os.path.join(toolsdir,'i18n', 'pygettext.py')
blackfawn 2015/04/16 18:58:42 Space after the first comma.
+
+ def getHeader(self, data):
blackfawn 2015/04/16 18:58:42 "get" implies a very fast+simple operation. A bett
blackfawn 2015/04/16 18:58:42 Maybe also add a test to verify the header format?
blackfawn 2015/04/16 18:58:42 Keep a consistent naming style for your methods, i
+ """ utility: return the header of a .po file as a dictionary """
blackfawn 2015/04/16 18:58:42 No spaces at the start/end of the docstring.
+ header = {}
+ for line in data.split('\n'):
+
blackfawn 2015/04/16 18:58:42 No blank lines in the beginning of blocks.
+ if not line:
+ continue
+ if line.startswith(('#', 'msgid','msgstr')):
+ continue
+
+ line = line.strip('"')
+
+ key, val = line.split(':',1)
+ header[key] = val.strip()
+
+ return header
+
+ def test_header(self):
+ """Make sure the required fields are in the header
+ spec: http://www.gnu.org/software/gettext/manual/gettext.html#Header-Entry
+ """
+ with temp_cwd(None) as cwd:
blackfawn 2015/04/16 18:58:42 It would be nicer to have this temp_cwd as part of
+ assert_python_ok(self.script)
+ with open('messages.pot') as fp:
+ data = fp.read()
+ header = self.getHeader(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)
blackfawn 2015/04/16 18:58:42 Pretty sure this field is optional. If you're chec
+
+ #not sure if these should be required in POT (template) files
blackfawn 2015/04/16 18:58:42 Language is definitely optional. I'm almost certai
+ #self.assertIn("Report-Msgid-Bugs-To", header)
+ #self.assertIn("Language", header)
+
+ #"Plural-Forms" is optional
+
+
+ def test_POT_Creation_Date(self):
blackfawn 2015/04/16 18:58:42 Don't capitalize "creation" and "date".
+ """ 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.getHeader(data)
+ creationDate = header['POT-Creation-Date']
+
+ #peel off the escaped newline at the end of string
blackfawn 2015/04/16 18:58:42 Maybe do this in getHeader?
+ if creationDate.endswith('\\n'):
+ creationDate = creationDate[:-len('\\n')]
+
+ #if this throws an exception: you fail.
blackfawn 2015/04/16 18:58:42 This is true for every line of code in every unitt
+ asDatetime = datetime.strptime(creationDate, '%Y-%m-%d %H:%M%z')
« no previous file with comments | « no previous file | Tools/i18n/pygettext.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+