diff options
| -rw-r--r-- | tests/test_unidecode.py | 9 | ||||
| -rw-r--r-- | unidecode/__init__.py | 11 |
2 files changed, 16 insertions, 4 deletions
diff --git a/tests/test_unidecode.py b/tests/test_unidecode.py index 5fadf46..4a93301 100644 --- a/tests/test_unidecode.py +++ b/tests/test_unidecode.py @@ -525,6 +525,11 @@ class BaseTestUnidecode(): self.assertEqual(5, e.exception.index) + # This checks that the exception is not chained (i.e. you don't get the + # "During handling of the above exception, another exception occurred") + if sys.version_info[0] >= 3: + self.assertIsNone(e.exception.__context__) + @unittest.skipIf(sys.maxunicode < 0x10000, "narrow build") def test_errors_preserve(self): s = u"test \U000f0000 test" @@ -537,6 +542,10 @@ class BaseTestUnidecode(): with self.assertRaises(UnidecodeError) as e: self.unidecode(u"test \U000f0000 test", errors='invalid') + # This checks that the exception is not chained (i.e. you don't get the + # "During handling of the above exception, another exception occurred") + if sys.version_info[0] >= 3: + self.assertIsNone(e.exception.__context__) class TestUnidecode(BaseTestUnidecode, unittest.TestCase): unidecode = staticmethod(unidecode) diff --git a/unidecode/__init__.py b/unidecode/__init__.py index 54c543d..776d6e4 100644 --- a/unidecode/__init__.py +++ b/unidecode/__init__.py @@ -65,11 +65,14 @@ def unidecode_expect_ascii(string, errors='ignore', replace_str='?'): try: bytestring = string.encode('ASCII') except UnicodeEncodeError: - return _unidecode(string, errors, replace_str) - if version_info[0] >= 3: - return string + pass else: - return bytestring + if version_info[0] >= 3: + return string + else: + return bytestring + + return _unidecode(string, errors, replace_str) def unidecode_expect_nonascii(string, errors='ignore', replace_str='?'): """Transliterate an Unicode object into an ASCII string |
