diff options
author | andy <andy@andymccurdy.com> | 2012-06-10 23:29:41 -0700 |
---|---|---|
committer | andy <andy@andymccurdy.com> | 2012-06-10 23:29:41 -0700 |
commit | 17ade97a064248f309b771c8ccf3a9ea96e79356 (patch) | |
tree | aed1cccf4784ca9f944a5c77d09dcdf392bb68cb /tests/encoding.py | |
parent | d2a7156f7fd108a24d8aa321e2ecd67b3f1f34c6 (diff) | |
parent | a99b650071ff83368d1b3b1d75d8870a682a2390 (diff) | |
download | redis-py-17ade97a064248f309b771c8ccf3a9ea96e79356.tar.gz |
Merge remote-tracking branch 'encoding/2.4.11-fix' into encoding
Conflicts:
redis/connection.py
Diffstat (limited to 'tests/encoding.py')
-rw-r--r-- | tests/encoding.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/encoding.py b/tests/encoding.py new file mode 100644 index 0000000..245a6df --- /dev/null +++ b/tests/encoding.py @@ -0,0 +1,44 @@ +from __future__ import with_statement +import redis +from redis.connection import ConnectionPool, PythonParser, HiredisParser +import unittest + +class EncodingTestCase(unittest.TestCase): + def setUp(self): + self.client = redis.Redis(host='localhost', port=6379, db=9, + charset='utf-8') + self.client.flushdb() + + def tearDown(self): + self.client.flushdb() + + def test_simple_encoding(self): + unicode_string = unichr(3456) + u'abcd' + unichr(3421) + self.client.set('unicode-string', unicode_string) + cached_val = self.client.get('unicode-string') + self.assertEquals('unicode', type(cached_val).__name__, + 'Cache returned value with type "%s", expected "unicode"' \ + % type(cached_val).__name__ + ) + self.assertEqual(unicode_string, cached_val) + + def test_list_encoding(self): + unicode_string = unichr(3456) + u'abcd' + unichr(3421) + result = [unicode_string, unicode_string, unicode_string] + for i in range(len(result)): + self.client.rpush('a', unicode_string) + self.assertEquals(self.client.lrange('a', 0, -1), result) + +class PythonParserEncodingTestCase(EncodingTestCase): + def setUp(self): + pool = ConnectionPool(host='localhost', port=6379, db=9, + encoding='utf-8', decode_responses=True, parser_class=PythonParser) + self.client = redis.Redis(connection_pool=pool) + self.client.flushdb() + +class HiredisEncodingTestCase(EncodingTestCase): + def setUp(self): + pool = ConnectionPool(host='localhost', port=6379, db=9, + encoding='utf-8', decode_responses=True, parser_class=HiredisParser) + self.client = redis.Redis(connection_pool=pool) + self.client.flushdb() |