2014-12-14 23:55:09 -05:00
|
|
|
|
# coding=utf-8
|
2014-12-14 22:35:47 -05:00
|
|
|
|
import locale
|
2014-12-05 21:46:44 -05: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 23:13:50 -05:00
|
|
|
|
from sickbeard import encodingKludge as ek
|
2014-12-05 21:46:44 -05:00
|
|
|
|
from sickbeard.exceptions import ex
|
2014-12-14 22:35:47 -05:00
|
|
|
|
from sickbeard.helpers import sanitizeFileName
|
2014-12-05 21:46:44 -05:00
|
|
|
|
|
|
|
|
|
class EncodingTests(unittest.TestCase):
|
|
|
|
|
def test_encoding(self):
|
2014-12-14 22:35:47 -05:00
|
|
|
|
rootDir = 'C:\\Temp\\TV'
|
2014-12-14 23:55:09 -05:00
|
|
|
|
strings = [u'Les Enfants De La T\xe9l\xe9', u'RT<EFBFBD> One']
|
2014-12-14 22:35:47 -05: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'
|
|
|
|
|
|
2014-12-05 23:13:50 -05:00
|
|
|
|
for s in strings:
|
|
|
|
|
try:
|
2014-12-14 22:35:47 -05:00
|
|
|
|
show_dir = ek.ek(os.path.join, rootDir, sanitizeFileName(s))
|
|
|
|
|
self.assertTrue(isinstance(show_dir, unicode))
|
2014-12-05 23:13:50 -05:00
|
|
|
|
except Exception, e:
|
2014-12-12 23:25:44 -05:00
|
|
|
|
ex(e)
|
2014-12-05 21:46:44 -05:00
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
print "=================="
|
2014-12-13 18:53:50 -05:00
|
|
|
|
print "STARTING - ENCODING TESTS"
|
2014-12-05 21:46:44 -05:00
|
|
|
|
print "=================="
|
|
|
|
|
print "######################################################################"
|
2014-12-13 18:16:11 -05:00
|
|
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(EncodingTests)
|
|
|
|
|
unittest.TextTestRunner(verbosity=2).run(suite)
|