FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

GitHub Viewer

# -*- coding: utf-8 -*- # vim:ts=4 sw=4 expandtab softtabstop=4 import unittest import sys from unidecode import unidecode, unidecode_expect_ascii, unidecode_expect_nonascii, UnidecodeError import warnings class WarningLogger: def __init__(self): self.clear() def start(self, filter): self.showwarning_old = warnings.showwarning def showwarning_new(message, category, *args): if (filter in str(message)) and \ (category is RuntimeWarning): self.log.append((message, category)) else: self.showwarning_old(message, category, *args) warnings.showwarning = showwarning_new warnings.filterwarnings("always") def stop(self): warnings.showwarning = self.showwarning_old def clear(self): self.log = [] class BaseTestUnidecode(): def test_ascii_to_self(self): wlog = WarningLogger() wlog.start("not an unicode object") for n in range(0,128): t = chr(n) r = self.unidecode(t) self.assertEqual(r, t) self.assertEqual(type(r), str) # unicode objects shouldn't raise warnings self.assertEqual(0, len(wlog.log)) wlog.stop() def test_all_to_ascii(self): for n in range(0,0x1ffff): # skip over surrogate pairs, which throw a warning if 0xd800

Back | FazBrowse Home | New Git URL