[Checkins] SVN: zope.app.locales/trunk/ When sorting locations, sort line numbers as ints, not as strings.
Marius Gedminas
marius at pov.lt
Mon Dec 12 14:46:40 UTC 2011
Log message for revision 123774:
When sorting locations, sort line numbers as ints, not as strings.
Changed:
U zope.app.locales/trunk/CHANGES.txt
U zope.app.locales/trunk/src/zope/app/locales/extract.py
U zope.app.locales/trunk/src/zope/app/locales/tests.py
-=-
Modified: zope.app.locales/trunk/CHANGES.txt
===================================================================
--- zope.app.locales/trunk/CHANGES.txt 2011-12-12 14:16:15 UTC (rev 123773)
+++ zope.app.locales/trunk/CHANGES.txt 2011-12-12 14:46:39 UTC (rev 123774)
@@ -7,7 +7,10 @@
- Handle Unicode msgids and default values.
+- Consistent sorting of source filenames for each msgid. Also sort line
+ numbers numerically, not lexicographically.
+
3.7.1 (2011-12-07)
------------------
Modified: zope.app.locales/trunk/src/zope/app/locales/extract.py
===================================================================
--- zope.app.locales/trunk/src/zope/app/locales/extract.py 2011-12-12 14:16:15 UTC (rev 123773)
+++ zope.app.locales/trunk/src/zope/app/locales/extract.py 2011-12-12 14:46:39 UTC (rev 123774)
@@ -113,13 +113,15 @@
def __init__(self, msgid, comments=None):
self.msgid = msgid
self.comments = comments or ''
+ self._location = []
def addComment(self, comment):
self.comments += comment + '\n'
def addLocationComment(self, filename, line):
- self.comments += '#: %s:%s\n' % (
- filename.replace(os.sep, '/'), line)
+ filename = filename.replace(os.sep, '/')
+ self.comments += '#: %s:%s\n' % (filename, line)
+ self._location.append((filename, line))
def write(self, file):
if self.comments:
@@ -137,7 +139,8 @@
file.write('\n')
def __cmp__(self, other):
- return cmp(self.comments, other.comments)
+ return cmp((self._location, self.msgid),
+ (other._location, other.msgid))
def __repr__(self):
return '<POTEntry: %r>' % self.msgid
Modified: zope.app.locales/trunk/src/zope/app/locales/tests.py
===================================================================
--- zope.app.locales/trunk/src/zope/app/locales/tests.py 2011-12-12 14:16:15 UTC (rev 123773)
+++ zope.app.locales/trunk/src/zope/app/locales/tests.py 2011-12-12 14:46:39 UTC (rev 123774)
@@ -67,6 +67,41 @@
self.assertEqual(h_count, len(list(gsm.registeredHandlers())))
+def doctest_POTEntry_sort_order():
+ """Test for POTEntry.__cmp__
+
+ >>> from zope.app.locales.extract import POTEntry
+
+ 'file1' comes before 'file2'
+
+ >>> pe1 = POTEntry('msgid1')
+ >>> pe1.addLocationComment('file1', 42)
+
+ >>> pe2 = POTEntry('msgid1')
+ >>> pe2.addLocationComment('file2', 42)
+
+ >>> pe1 < pe2
+ True
+
+ line 9 comes before line 42
+
+ >>> pe3 = POTEntry('msgid1')
+ >>> pe3.addLocationComment('file1', 9)
+
+ >>> pe3 < pe1
+ True
+
+ Finally, msgid1 comes before msgid2
+
+ >>> pe4 = POTEntry('msgid2')
+ >>> pe4.addLocationComment('file1', 42)
+
+ >>> pe1 < pe4
+ True
+
+ """
+
+
def doctest_POTMaker_add():
"""Test for POTMaker.add
More information about the checkins
mailing list