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

Side by Side 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
Left:
Right:
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 unified diff | Download patch
« no previous file with comments | « no previous file | Tools/i18n/pygettext.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 """Tests to cover the Tools/i18n package"""
2
3 import os
4 import unittest
5
6 from test.script_helper import assert_python_ok
7 from test.test_tools import toolsdir
8 from test.support import temp_cwd
9
10 class Test_pygettext(unittest.TestCase):
blackfawn 2015/04/16 18:58:42 Rename the class GettextTests or PygettextTests to
11 """Tests for the pygettext.py tool"""
12
13 script = os.path.join(toolsdir,'i18n', 'pygettext.py')
blackfawn 2015/04/16 18:58:42 Space after the first comma.
14
15 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
16 """ 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.
17 header = {}
18 for line in data.split('\n'):
19
blackfawn 2015/04/16 18:58:42 No blank lines in the beginning of blocks.
20 if not line:
21 continue
22 if line.startswith(('#', 'msgid','msgstr')):
23 continue
24
25 line = line.strip('"')
26
27 key, val = line.split(':',1)
28 header[key] = val.strip()
29
30 return header
31
32 def test_header(self):
33 """Make sure the required fields are in the header
34 spec: http://www.gnu.org/software/gettext/manual/gettext.html#Header- Entry
35 """
36 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
37 assert_python_ok(self.script)
38 with open('messages.pot') as fp:
39 data = fp.read()
40 header = self.getHeader(data)
41
42 self.assertIn("Project-Id-Version", header)
43 self.assertIn("POT-Creation-Date", header)
44 self.assertIn("PO-Revision-Date", header)
45 self.assertIn("Last-Translator", header)
46 self.assertIn("Language-Team", header)
47 self.assertIn("MIME-Version", header)
48 self.assertIn("Content-Type", header)
49 self.assertIn("Content-Transfer-Encoding", header)
50 self.assertIn("Generated-By", header)
blackfawn 2015/04/16 18:58:42 Pretty sure this field is optional. If you're chec
51
52 #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
53 #self.assertIn("Report-Msgid-Bugs-To", header)
54 #self.assertIn("Language", header)
55
56 #"Plural-Forms" is optional
57
58
59 def test_POT_Creation_Date(self):
blackfawn 2015/04/16 18:58:42 Don't capitalize "creation" and "date".
60 """ Match the date format from xgettext for POT-Creation-Date """
61 from datetime import datetime
62 with temp_cwd(None) as cwd:
63 assert_python_ok(self.script)
64
65 with open('messages.pot') as fp:
66 data = fp.read()
67 header = self.getHeader(data)
68 creationDate = header['POT-Creation-Date']
69
70 #peel off the escaped newline at the end of string
blackfawn 2015/04/16 18:58:42 Maybe do this in getHeader?
71 if creationDate.endswith('\\n'):
72 creationDate = creationDate[:-len('\\n')]
73
74 #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
75 asDatetime = datetime.strptime(creationDate, '%Y-%m-%d %H:%M%z')
OLDNEW
« 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+