From c093d97a9394134908fdcbf2ecafcc977c3b927d Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Wed, 15 Feb 2017 17:26:32 +0000 Subject: [PATCH] Only run the `ascii` case on Py2 --- tests/unit/utils/locales_test.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/unit/utils/locales_test.py b/tests/unit/utils/locales_test.py index 7aa832a0ae..0d319ee765 100644 --- a/tests/unit/utils/locales_test.py +++ b/tests/unit/utils/locales_test.py @@ -28,10 +28,13 @@ class TestLocales(TestCase): reload_module(locales) def test_sdecode(self): - b = '\xe7\xb9\x81\xe4\xbd\x93' if six.PY2 else bytes((0xe7, 0xb9, 0x81, 0xe4, 0xbd, 0x93)) + b = six.b('\xe7\xb9\x81\xe4\xbd\x93') u = u'\u7e41\u4f53' - with patch('salt.utils.locales.get_encodings', return_value=['ascii']): - self.assertEqual(locales.sdecode(b), b) # no decode + if six.PY2: + # Under Py3, the above `b` as bytes, will never decode as anything even comparable using `ascii` + # but no unicode error will be raised, as such, sdecode will return the poorly decoded string + with patch('salt.utils.locales.get_encodings', return_value=['ascii']): + self.assertEqual(locales.sdecode(b), b) # no decode with patch('salt.utils.locales.get_encodings', return_value=['utf-8']): self.assertEqual(locales.sdecode(b), u)