Skip to content

Commit

Permalink
Fix output of --list-locales to not be a bytes repr
Browse files Browse the repository at this point in the history
Co-authored-by: Aarni Koskela <akx@iki.fi>
  • Loading branch information
morganwahl and akx committed Apr 8, 2022
1 parent 6be6b1f commit a805eb7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 1 addition & 5 deletions babel/messages/frontend.py
Expand Up @@ -22,7 +22,6 @@
from configparser import RawConfigParser
from datetime import datetime
from io import StringIO
from locale import getpreferredencoding

from babel import __version__ as VERSION
from babel import Locale, localedata
Expand Down Expand Up @@ -906,10 +905,7 @@ def run(self, argv=None):
format = u'%%-%ds %%s' % (longest + 1)
for identifier in identifiers:
locale = Locale.parse(identifier)
output = format % (identifier, locale.english_name)
print(output.encode(sys.stdout.encoding or
getpreferredencoding() or
'ascii', 'replace'))
print(format % (identifier, locale.english_name))
return 0

if not args:
Expand Down
11 changes: 11 additions & 0 deletions tests/messages/test_frontend.py
Expand Up @@ -756,6 +756,17 @@ def test_usage(self):
pybabel: error: no valid command or option passed. try the -h/--help option for more information.
""", sys.stderr.getvalue().lower())

def test_list_locales(self):
"""
Test the command with the --list-locales arg.
"""
result = self.cli.run(sys.argv + ['--list-locales'])
assert not result
output = sys.stdout.getvalue()
assert 'fr_CH' in output
assert 'French (Switzerland)' in output
assert "\nb'" not in output # No bytes repr markers in output

def _run_init_catalog(self):
i18n_dir = os.path.join(data_dir, 'project', 'i18n')
pot_path = os.path.join(data_dir, 'project', 'i18n', 'messages.pot')
Expand Down

0 comments on commit a805eb7

Please sign in to comment.