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

Delta Between Two Patch Sets: Lib/test/test_tools/test_i18n.py

Issue 18128: pygettext: non-standard timestamp format in POT-Creation-Date
Left Patch Set: Created 4 years, 10 months ago
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | Tools/i18n/pygettext.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 """Tests to cover the Tools/i18n package""" 1 """Tests to cover the Tools/i18n package"""
2 2
3 import os 3 import os
4 import unittest 4 import unittest
5 5
6 from test.script_helper import assert_python_ok 6 from test.script_helper import assert_python_ok
7 from test.test_tools import toolsdir 7 from test.test_tools import toolsdir
8 from test.support import temp_cwd 8 from test.support import temp_cwd
9 9
10 class test_pygettext(unittest.TestCase): 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"""
11 12
12 script = os.path.join(toolsdir,'i18n', 'pygettext.py') 13 script = os.path.join(toolsdir,'i18n', 'pygettext.py')
blackfawn 2015/04/16 18:58:42 Space after the first comma.
13 #Data isn't meant to be evaluated as python, but parsed by pygettext 14
14 #src_data = """ import gettext
15 # _ = gettext.gettext
16 # print(_("hello world"))
17 # """
18
19 def getHeader(self, data): 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
20 """ return the header of a .po file """ 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.
21 header = {} 17 header = {}
22 for line in data.split('\n'): 18 for line in data.split('\n'):
23 19
blackfawn 2015/04/16 18:58:42 No blank lines in the beginning of blocks.
24 if not line: continue 20 if not line:
25 if line.startswith('#'): continue 21 continue
26 if line.startswith('msgid'): continue 22 if line.startswith(('#', 'msgid','msgstr')):
27 if line.startswith('msgstr'): continue 23 continue
28 24
29 line = line.strip('"\n') 25 line = line.strip('"')
30 26
31 key, val = line.split(':',1) 27 key, val = line.split(':',1)
32 header[key] = val 28 header[key] = val.strip()
33 29
34 return header 30 return header
35 31
36 def test_header(self): 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 """
37 with temp_cwd(None) as cwd: 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
38 assert_python_ok(self.script) 37 assert_python_ok(self.script)
39 with open('messages.pot') as fp: 38 with open('messages.pot') as fp:
40 data = fp.read() 39 data = fp.read()
41 header = self.getHeader(data) 40 header = self.getHeader(data)
42 41
42 self.assertIn("Project-Id-Version", header)
43 self.assertIn("POT-Creation-Date", header) 43 self.assertIn("POT-Creation-Date", header)
44 self.assertIn("PO-Revision-Date", header) 44 self.assertIn("PO-Revision-Date", header)
45 self.assertIn("Last-Translator", header) 45 self.assertIn("Last-Translator", header)
46 self.assertIn("Language-Team", header) 46 self.assertIn("Language-Team", header)
47 self.assertIn("MIME-Version", header) 47 self.assertIn("MIME-Version", header)
48 self.assertIn("Content-Type", header) 48 self.assertIn("Content-Type", header)
49 self.assertIn("Content-Transfer-Encoding", header) 49 self.assertIn("Content-Transfer-Encoding", header)
50 self.assertIn("Generated-By", 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
51 57
52 58
53 def test_POT_Creation_Date_tz(self): 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 """
54 from datetime import datetime 61 from datetime import datetime
55 with temp_cwd(None) as cwd: 62 with temp_cwd(None) as cwd:
56 assert_python_ok(self.script) 63 assert_python_ok(self.script)
57 64
58 with open('messages.pot') as fp: 65 with open('messages.pot') as fp:
59 data = fp.read() 66 data = fp.read()
60 header = self.getHeader(data) 67 header = self.getHeader(data)
61 creationDate = header['POT-Creation-Date'] 68 creationDate = header['POT-Creation-Date']
62 69
63 #peel off some extra string junk 70 #peel off the escaped newline at the end of string
blackfawn 2015/04/16 18:58:42 Maybe do this in getHeader?
64 creationDate = creationDate.strip('\\n ') 71 if creationDate.endswith('\\n'):
72 creationDate = creationDate[:-len('\\n')]
65 73
66 #if this throws an exception: you fail. 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
67 asDatetime = datetime.strptime(creationDate, '%Y-%m-%d %H:%M%z') 75 asDatetime = datetime.strptime(creationDate, '%Y-%m-%d %H:%M%z')
LEFTRIGHT

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