2014-12-14 20:55:09 -08:00
|
|
|
|
# coding=utf-8
|
2014-12-14 19:35:47 -08:00
|
|
|
|
import locale
|
2014-12-05 18:46:44 -08:00
|
|
|
|
import unittest
|
|
|
|
|
import sys, os.path
|
|
|
|
|
|
|
|
|
|
sys.path.append(os.path.abspath('..'))
|
|
|
|
|
sys.path.append(os.path.abspath('../lib'))
|
|
|
|
|
|
|
|
|
|
import sickbeard
|
2014-12-05 20:13:50 -08:00
|
|
|
|
from sickbeard import encodingKludge as ek
|
2014-12-05 18:46:44 -08:00
|
|
|
|
from sickbeard.exceptions import ex
|
2014-12-14 19:35:47 -08:00
|
|
|
|
from sickbeard.helpers import sanitizeFileName
|
2014-12-05 18:46:44 -08:00
|
|
|
|
|
|
|
|
|
class EncodingTests(unittest.TestCase):
|
|
|
|
|
def test_encoding(self):
|
2014-12-14 19:35:47 -08:00
|
|
|
|
rootDir = 'C:\\Temp\\TV'
|
2014-12-14 20:55:09 -08:00
|
|
|
|
strings = [u'Les Enfants De La T\xe9l\xe9', u'RT<EFBFBD> One']
|
2014-12-14 19:35:47 -08:00
|
|
|
|
|
|
|
|
|
sickbeard.SYS_ENCODING = None
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
locale.setlocale(locale.LC_ALL, "")
|
|
|
|
|
sickbeard.SYS_ENCODING = locale.getpreferredencoding()
|
|
|
|
|
except (locale.Error, IOError):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
# For OSes that are poorly configured I'll just randomly force UTF-8
|
|
|
|
|
if not sickbeard.SYS_ENCODING or sickbeard.SYS_ENCODING in ('ANSI_X3.4-1968', 'US-ASCII', 'ASCII'):
|
|
|
|
|
sickbeard.SYS_ENCODING = 'UTF-8'
|
|
|
|
|
|
|
|
|
|
if not hasattr(sys, "setdefaultencoding"):
|
|
|
|
|
reload(sys)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
# pylint: disable=E1101
|
|
|
|
|
# On non-unicode builds this will raise an AttributeError, if encoding type is not valid it throws a LookupError
|
|
|
|
|
sys.setdefaultencoding(sickbeard.SYS_ENCODING)
|
|
|
|
|
except:
|
|
|
|
|
sys.exit("Sorry, you MUST add the SickRage folder to the PYTHONPATH environment variable\n" +
|
|
|
|
|
"or find another way to force Python to use " + sickbeard.SYS_ENCODING + " for string encoding.")
|
2014-12-05 20:13:50 -08:00
|
|
|
|
|
|
|
|
|
for s in strings:
|
|
|
|
|
try:
|
2014-12-14 20:55:09 -08:00
|
|
|
|
show_name = s.decode(sickbeard.SYS_ENCODING, 'xmlcharrefreplace')
|
2014-12-14 19:35:47 -08:00
|
|
|
|
show_dir = ek.ek(os.path.join, rootDir, sanitizeFileName(s))
|
|
|
|
|
self.assertTrue(isinstance(show_dir, unicode))
|
2014-12-05 20:13:50 -08:00
|
|
|
|
except Exception, e:
|
2014-12-12 20:25:44 -08:00
|
|
|
|
ex(e)
|
2014-12-05 18:46:44 -08:00
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
print "=================="
|
2014-12-13 15:53:50 -08:00
|
|
|
|
print "STARTING - ENCODING TESTS"
|
2014-12-05 18:46:44 -08:00
|
|
|
|
print "=================="
|
|
|
|
|
print "######################################################################"
|
2014-12-13 15:16:11 -08:00
|
|
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(EncodingTests)
|
|
|
|
|
unittest.TextTestRunner(verbosity=2).run(suite)
|