fix py3 languages decode added tests. close #1848, thanks @bjquinn
This commit is contained in:
+4
-1
@@ -434,7 +434,10 @@ class lazyT(object):
|
|||||||
return str(self).encode(*a, **b)
|
return str(self).encode(*a, **b)
|
||||||
|
|
||||||
def decode(self, *a, **b):
|
def decode(self, *a, **b):
|
||||||
return str(self).decode(*a, **b)
|
if PY2:
|
||||||
|
return str(self).decode(*a, **b)
|
||||||
|
else:
|
||||||
|
return str(self)
|
||||||
|
|
||||||
def read(self):
|
def read(self):
|
||||||
return str(self)
|
return str(self)
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ import tempfile
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from gluon import languages
|
from gluon import languages
|
||||||
from gluon._compat import PY2
|
from gluon._compat import PY2, to_unicode
|
||||||
|
from gluon.storage import Messages
|
||||||
|
|
||||||
MP_WORKING = 0
|
MP_WORKING = 0
|
||||||
try:
|
try:
|
||||||
@@ -108,6 +109,8 @@ class TestTranslations(unittest.TestCase):
|
|||||||
T.force('it')
|
T.force('it')
|
||||||
self.assertEqual(str(T('Hello World')),
|
self.assertEqual(str(T('Hello World')),
|
||||||
'Salve Mondo')
|
'Salve Mondo')
|
||||||
|
self.assertEqual(to_unicode(T('Hello World')),
|
||||||
|
'Salve Mondo')
|
||||||
|
|
||||||
class TestDummyApp(unittest.TestCase):
|
class TestDummyApp(unittest.TestCase):
|
||||||
|
|
||||||
@@ -179,3 +182,22 @@ def index():
|
|||||||
for key in ['hello', 'world', '%s %%{shop}', 'ahoy']:
|
for key in ['hello', 'world', '%s %%{shop}', 'ahoy']:
|
||||||
self.assertTrue(key in en_dict)
|
self.assertTrue(key in en_dict)
|
||||||
self.assertTrue(key in pt_dict)
|
self.assertTrue(key in pt_dict)
|
||||||
|
|
||||||
|
class TestMessages(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
if os.path.isdir('gluon'):
|
||||||
|
self.langpath = 'applications/welcome/languages'
|
||||||
|
else:
|
||||||
|
self.langpath = os.path.realpath(
|
||||||
|
'../../applications/welcome/languages')
|
||||||
|
self.http_accept_language = 'en'
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_decode(self):
|
||||||
|
T = languages.translator(self.langpath, self.http_accept_language)
|
||||||
|
messages = Messages(T)
|
||||||
|
messages.update({'email_sent':'Email sent', 'test': "ä"})
|
||||||
|
self.assertEqual(to_unicode(messages.email_sent, 'utf-8'), 'Email sent')
|
||||||
|
|||||||
Reference in New Issue
Block a user