Skip to content

Commit

Permalink
pofile: Use .sort(key=...), not cmp
Browse files Browse the repository at this point in the history
Fixes #79 (#79)
  • Loading branch information
akx committed Dec 24, 2015
1 parent cb73864 commit 94bff46
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion babel/messages/pofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def _write_message(message, prefix=''):
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"
Expand Down
9 changes: 9 additions & 0 deletions tests/messages/test_pofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,15 @@ def test_sorted_po(self):
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)],
Expand Down

0 comments on commit 94bff46

Please sign in to comment.