remove default locale C.UTF-8

pull/288/head
Wolfgang Walther 5 years ago
parent 2afb6cc2a5
commit 7bb5de0a42

@ -197,10 +197,10 @@ It is possible to set the ``locale`` option globally. This is passed to Python's
`locale.setlocale `locale.setlocale
<https://docs.python.org/3/library/locale.html#locale.setlocale>`_, <https://docs.python.org/3/library/locale.html#locale.setlocale>`_,
so an empty string ``""`` will use the system default locale, while e.g. so an empty string ``""`` will use the system default locale, while e.g.
``"en_US.UTF-8"`` will use that. If unset, the default is ``"C.UTF-8"``. ``"en_US.UTF-8"`` will use that.
Currently this only affects the ``key-ordering`` rule. The default will order Currently this only affects the ``key-ordering`` rule. The default will order
by Unicode code point number, while other locales will sort case and accents by Unicode code point number, while locales will sort case and accents
properly as well. properly as well.
.. code-block:: yaml .. code-block:: yaml

@ -114,7 +114,7 @@ class KeyOrderingTestCase(RuleTestCase):
']\n', conf) ']\n', conf)
def test_locale_case(self): def test_locale_case(self):
self.addCleanup(locale.setlocale, locale.LC_ALL, 'C.UTF-8') self.addCleanup(locale.setlocale, locale.LC_ALL, (None, None))
try: try:
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
except locale.Error: except locale.Error:
@ -133,7 +133,7 @@ class KeyOrderingTestCase(RuleTestCase):
problem=(4, 1)) problem=(4, 1))
def test_locale_accents(self): def test_locale_accents(self):
self.addCleanup(locale.setlocale, locale.LC_ALL, 'C.UTF-8') self.addCleanup(locale.setlocale, locale.LC_ALL, (None, None))
try: try:
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
except locale.Error: except locale.Error:

@ -331,11 +331,12 @@ class CommandLineTestCase(unittest.TestCase):
self.assertEqual(ctx.returncode, 1) self.assertEqual(ctx.returncode, 1)
def test_run_with_locale(self): def test_run_with_locale(self):
self.addCleanup(locale.setlocale, locale.LC_ALL, 'C.UTF-8') self.addCleanup(locale.setlocale, locale.LC_ALL, (None, None))
try: try:
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
except locale.Error: except locale.Error:
self.skipTest('locale en_US.UTF-8 not available') self.skipTest('locale en_US.UTF-8 not available')
locale.setlocale(locale.LC_ALL, (None, None))
# C + en.yaml should fail # C + en.yaml should fail
with RunContext(self) as ctx: with RunContext(self) as ctx:
@ -343,6 +344,12 @@ class CommandLineTestCase(unittest.TestCase):
os.path.join(self.wd, 'en.yaml'))) os.path.join(self.wd, 'en.yaml')))
self.assertEqual(ctx.returncode, 1) self.assertEqual(ctx.returncode, 1)
# C + c.yaml should pass
with RunContext(self) as ctx:
cli.run(('-d', 'rules: { key-ordering: enable }',
os.path.join(self.wd, 'c.yaml')))
self.assertEqual(ctx.returncode, 0)
# en_US + en.yaml should pass # en_US + en.yaml should pass
with RunContext(self) as ctx: with RunContext(self) as ctx:
cli.run(('-d', 'locale: en_US.UTF-8\n' cli.run(('-d', 'locale: en_US.UTF-8\n'
@ -357,12 +364,6 @@ class CommandLineTestCase(unittest.TestCase):
os.path.join(self.wd, 'c.yaml'))) os.path.join(self.wd, 'c.yaml')))
self.assertEqual(ctx.returncode, 1) self.assertEqual(ctx.returncode, 1)
# C + c.yaml should pass
with RunContext(self) as ctx:
cli.run(('-d', 'rules: { key-ordering: enable }',
os.path.join(self.wd, 'c.yaml')))
self.assertEqual(ctx.returncode, 0)
def test_run_version(self): def test_run_version(self):
with RunContext(self) as ctx: with RunContext(self) as ctx:
cli.run(('--version', )) cli.run(('--version', ))
@ -421,6 +422,15 @@ class CommandLineTestCase(unittest.TestCase):
def test_run_non_ascii_file(self): def test_run_non_ascii_file(self):
path = os.path.join(self.wd, 'non-ascii', 'éçäγλνπ¥', 'utf-8') path = os.path.join(self.wd, 'non-ascii', 'éçäγλνπ¥', 'utf-8')
# Make sure the default localization conditions on this "system"
# support UTF-8 encoding.
loc = locale.getlocale()
try:
locale.setlocale(locale.LC_ALL, 'C.UTF-8')
except locale.Error:
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
self.addCleanup(locale.setlocale, locale.LC_ALL, loc)
with RunContext(self) as ctx: with RunContext(self) as ctx:
cli.run(('-f', 'parsable', path)) cli.run(('-f', 'parsable', path))
self.assertEqual((ctx.returncode, ctx.stdout, ctx.stderr), (0, '', '')) self.assertEqual((ctx.returncode, ctx.stdout, ctx.stderr), (0, '', ''))

@ -176,7 +176,8 @@ def run(argv=None):
print(e, file=sys.stderr) print(e, file=sys.stderr)
sys.exit(-1) sys.exit(-1)
locale.setlocale(locale.LC_ALL, conf.locale) if conf.locale is not None:
locale.setlocale(locale.LC_ALL, conf.locale)
max_level = 0 max_level = 0

@ -35,7 +35,7 @@ class YamlLintConfig(object):
self.yaml_files = pathspec.PathSpec.from_lines( self.yaml_files = pathspec.PathSpec.from_lines(
'gitwildmatch', ['*.yaml', '*.yml', '.yamllint']) 'gitwildmatch', ['*.yaml', '*.yml', '.yamllint'])
self.locale = 'C.UTF-8' self.locale = None
if file is not None: if file is not None:
with open(file) as f: with open(file) as f:

Loading…
Cancel
Save