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 c29b674
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 1 addition & 4 deletions babel/messages/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,10 +906,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
Original file line number Diff line number Diff line change
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 c29b674

Please sign in to comment.