encoding.py
Go to the documentation of this file.
00001 from __future__ import with_statement
00002 import unittest
00003 
00004 import rocon_python_redis as redis
00005 from redis._compat import unichr, u, unicode
00006 from redis.connection import ConnectionPool, PythonParser, HiredisParser
00007 
00008 
00009 class EncodingTestCase(unittest.TestCase):
00010     def setUp(self):
00011         self.client = redis.Redis(
00012             host='localhost', port=6379, db=9, charset='utf-8')
00013         self.client.flushdb()
00014 
00015     def tearDown(self):
00016         self.client.flushdb()
00017 
00018     def test_simple_encoding(self):
00019         unicode_string = unichr(3456) + u('abcd') + unichr(3421)
00020         self.client.set('unicode-string', unicode_string)
00021         cached_val = self.client.get('unicode-string')
00022         self.assertEquals(
00023             unicode.__name__, type(cached_val).__name__,
00024             'Cache returned value with type "%s", expected "%s"' %
00025             (type(cached_val).__name__, unicode.__name__))
00026         self.assertEqual(unicode_string, cached_val)
00027 
00028     def test_list_encoding(self):
00029         unicode_string = unichr(3456) + u('abcd') + unichr(3421)
00030         result = [unicode_string, unicode_string, unicode_string]
00031         for i in range(len(result)):
00032             self.client.rpush('a', unicode_string)
00033         self.assertEquals(self.client.lrange('a', 0, -1), result)
00034 
00035 
00036 class PythonParserEncodingTestCase(EncodingTestCase):
00037     def setUp(self):
00038         pool = ConnectionPool(
00039             host='localhost', port=6379, db=9,
00040             encoding='utf-8', decode_responses=True, parser_class=PythonParser)
00041         self.client = redis.Redis(connection_pool=pool)
00042         self.client.flushdb()
00043 
00044 
00045 class HiredisEncodingTestCase(EncodingTestCase):
00046     def setUp(self):
00047         pool = ConnectionPool(
00048             host='localhost', port=6379, db=9,
00049             encoding='utf-8', decode_responses=True,
00050             parser_class=HiredisParser)
00051         self.client = redis.Redis(connection_pool=pool)
00052         self.client.flushdb()


rocon_python_redis
Author(s): Andy McCurdy
autogenerated on Fri May 2 2014 10:35:49