]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
pofile: Use `.sort(key=...)`, not `cmp`
authorAarni Koskela <akx@iki.fi>
Thu, 24 Dec 2015 18:06:28 +0000 (20:06 +0200)
committerAarni Koskela <akx@iki.fi>
Mon, 4 Jan 2016 21:21:14 +0000 (23:21 +0200)
Fixes #79 (https://github.com/python-babel/babel/issues/79)

babel/messages/pofile.py
tests/messages/test_pofile.py

index dfc78fecb2f46c73db3a054cff7c4a6fbab90983..3c18226dabac38c57312f3a7461b568bcb584990 100644 (file)
@@ -431,7 +431,7 @@ def write_po(fileobj, catalog, width=76, no_location=False, omit_header=False,
     if sort_output:
         messages.sort()
     elif sort_by_file:
-        messages.sort(lambda x,y: cmp(x.locations, y.locations))
+        messages.sort(key=lambda m: m.locations)
 
     for message in messages:
         if not message.id: # This is the header "message"
index 4e991c63c3f320ce9a7433caa9cdfc02530ccbc6..f375a1a42df955fb1b04a4cbe5170df098c38988 100644 (file)
@@ -513,6 +513,15 @@ msgstr[0] "Voh"
 msgstr[1] "Voeh"''' in value
         assert value.find(b'msgid ""') < value.find(b'msgid "bar"') < value.find(b'msgid "foo"')
 
+    def test_file_sorted_po(self):
+        catalog = Catalog()
+        catalog.add(u'bar', locations=[('utils.py', 3)])
+        catalog.add((u'foo', u'foos'), (u'Voh', u'Voeh'), locations=[('main.py', 1)])
+        buf = BytesIO()
+        pofile.write_po(buf, catalog, sort_by_file=True)
+        value = buf.getvalue().strip()
+        assert value.find(b'main.py') < value.find(b'utils.py')
+
     def test_file_with_no_lineno(self):
         catalog = Catalog()
         catalog.add(u'bar', locations=[('utils.py', None)],