diff options
| author | Tomaz Solc <tomaz.solc@tablix.org> | 2020-12-20 11:30:31 +0100 |
|---|---|---|
| committer | Tomaz Solc <tomaz.solc@tablix.org> | 2020-12-20 11:51:09 +0100 |
| commit | 4104e5ac951210eb35e57b494f7ebc227edb651a (patch) | |
| tree | 8abbefe6a44397786ff9f9290129ba0b7bdc9a0c /tests | |
| parent | b1bdf8df548205c265f26db8acd468ad412e2cbd (diff) | |
| download | unidecode-4104e5ac951210eb35e57b494f7ebc227edb651a.tar.gz | |
Add errors parameter to unidecode()
This implements the idea in https://github.com/avian2/unidecode/pull/53
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_unidecode.py | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/tests/test_unidecode.py b/tests/test_unidecode.py index 100cfca..42bb678 100644 --- a/tests/test_unidecode.py +++ b/tests/test_unidecode.py @@ -2,7 +2,7 @@ # vim:ts=4 sw=4 expandtab softtabstop=4 import unittest import sys -from unidecode import unidecode, unidecode_expect_ascii, unidecode_expect_nonascii +from unidecode import unidecode, unidecode_expect_ascii, unidecode_expect_nonascii, UnidecodeError import warnings @@ -502,6 +502,41 @@ class BaseTestUnidecode(): self.unidecode(u'ⓐⒶ⑳⒇⒛⓴⓾⓿'), ) + @unittest.skipIf(sys.maxunicode < 0x10000, "narrow build") + def test_errors_ignore(self): + # unidecode doesn't have replacements for private use characters + o = self.unidecode(u"test \U000f0000 test", errors='ignore') + self.assertEqual('test test', o) + + @unittest.skipIf(sys.maxunicode < 0x10000, "narrow build") + def test_errors_replace(self): + o = self.unidecode(u"test \U000f0000 test", errors='replace') + self.assertEqual('test ? test', o) + + @unittest.skipIf(sys.maxunicode < 0x10000, "narrow build") + def test_errors_replace_char(self): + o = self.unidecode(u"test \U000f0000 test", errors='replace', replace_char='[?] ') + self.assertEqual('test [?] test', o) + + @unittest.skipIf(sys.maxunicode < 0x10000, "narrow build") + def test_errors_strict(self): + with self.assertRaises(UnidecodeError) as e: + o = self.unidecode(u"test \U000f0000 test", errors='strict') + + self.assertEqual(5, e.exception.index) + + @unittest.skipIf(sys.maxunicode < 0x10000, "narrow build") + def test_errors_preserve(self): + s = u"test \U000f0000 test" + o = self.unidecode(s, errors='preserve') + + self.assertEqual(s, o) + + @unittest.skipIf(sys.maxunicode < 0x10000, "narrow build") + def test_errors_invalid(self): + with self.assertRaises(UnidecodeError) as e: + self.unidecode(u"test \U000f0000 test", errors='invalid') + class TestUnidecode(BaseTestUnidecode, unittest.TestCase): unidecode = staticmethod(unidecode) |
