]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Fix output of --list-locales to not be a bytes repr
authorMorgan Wahl <morgan@addgene.org>
Sat, 26 Feb 2022 00:08:12 +0000 (19:08 -0500)
committerAarni Koskela <akx@iki.fi>
Fri, 8 Apr 2022 13:21:57 +0000 (16:21 +0300)
Co-authored-by: Aarni Koskela <akx@iki.fi>
babel/messages/frontend.py
tests/messages/test_frontend.py

index c71bc0d79993e1b8110a675af94556be8e54ce2b..36f80f1c8d96955543c165f9f9441dcb0eb7e3d4 100644 (file)
@@ -22,7 +22,6 @@ from collections import OrderedDict
 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
@@ -906,10 +905,7 @@ class CommandLineInterface(object):
             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:
index f8a58dd21f563dc722c6a9f975c5b7cf082a72a6..40afab7f9a8d3b95be9fc47640fe01c1fbb0bd96 100644 (file)
@@ -756,6 +756,17 @@ usage: pybabel command [options] [args]
 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')