Permalink
Browse files

601 tests, coverage up to 92%. Using mock library to test socket fail…

…ures
  • Loading branch information...
1 parent 30c038b commit 7c3e758f794c674350b5156db1759e5c64173356 quantmind committed Sep 18, 2012
View
@@ -2,14 +2,20 @@
Development
===============================
-* A new ``C`` redis_ parser shipped with the library.
* Several fixes in the documentation.
-* Added an asynchronous connection class for Redis.
+* Added a *prefixed* redis client in :class:`stdnet.lib.redis.PrefixedRedis`.
+* **601 regression tests** with **92%** coverage.
+
+Ver. 0.7c6 - 2012 Sep 10
+===============================
+* **Tested with redis 2.6.0-rc6**.
+* Several fixes in the documentation.
+* Added an asynchronous connection class for Redis. It requires pulsar_ concurrent framework.
* Lua script for univariate timeseries. This means the standard redis distribution
works with the :class:`stdnet.odm.TS` structure.
* Serialisation works for :attr:`stdnet.odm.ManyToMany.through` models via
the :func:`stdnet.odm.all_models_sessions` function (issue #48).
-* **593 regression tests** with **90%** coverage.
+* **587 regression tests** with **91%** coverage.
Ver. 0.7c3 - 2012 May 02
===============================
View
@@ -24,6 +24,14 @@ Contents
:local:
+Features
+=================
+* Models with scalar and multi-value fields.
+* Reach query API including unions, intersections, ranges and more.
+* Full text search.
+* Multi-variate numeric timeseries application.
+* Publish/Subscribe application.
+
Requirements
=================
* Python 2.6 to Python 3.3. Single codebase.
@@ -168,7 +176,8 @@ Requirements for running tests:
* unittest2_ for python 2.6 only.
* argparse_ for python 2.6, 3 and 3.1 only.
-* nose_
+* mock_ for python 2.6 to python 3.2 only.
+* nose_ or pulsar_.
Note, these requirements are only needed if you are planning to run tests.
To run tests open a shell and launch Redis. On another shell,
@@ -243,4 +252,5 @@ file in the top distribution directory for the full license text.
.. _unittest2: http://pypi.python.org/pypi/unittest2
.. _nose: http://readthedocs.org/docs/nose/en/latest
.. _DynamoDB: http://aws.amazon.com/dynamodb/
-.. _pulsar: https://github.com/quantmind/pulsar
+.. _pulsar: https://github.com/quantmind/pulsar
+.. _mock: http://pypi.python.org/pypi/mock
@@ -137,8 +137,22 @@ Redis
.. autoclass:: Redis
:members:
:member-order: bysource
-
+
+RedisProxy
+~~~~~~~~~~~~~~~~
+.. autoclass:: RedisProxy
+ :members:
+ :member-order: bysource
+
+
+PrefixedRedis
+~~~~~~~~~~~~~~~~
+.. autoclass:: PrefixedRedis
+ :members:
+ :member-order: bysource
+
+
Pipeline
~~~~~~~~~~~~~~~
.. autoclass:: Pipeline
@@ -14,7 +14,7 @@ management and retrieval of large data-sets.
It includes a stand-alone, ``python 3`` compatible,
:ref:`redis client <redis-client>` which was originally forked from redis-py_.
There are no dependencies, it requires ``python 2.6`` up to ``python 3.3`` and
-there are over 500 tests with a coverage of about 90%.
+there are over 600 tests with a coverage over 90%.
**The library is stable, used in production and continuously maintained**.
View
@@ -3,6 +3,11 @@
'''
import sys
import os
+try:
+ import mock
+except ImportError:
+ print('The mock library is required to run tests.')
+ exit(0)
## This is for dev environment with pulsar and dynts.
## If not available, some tests won't run
View
@@ -55,13 +55,21 @@ def psubscribe(self, *channels):
def punsubscribe(self, *channels):
return self._subscriber.punsubscribe(self.channel_list(channels))
- def message_callback(self, command, channel, message=None):
+ def message_callback(self, command, channel, msg=None, sub_channel=None):
if command == 'subscribe':
self.channels[channel] = []
elif command == 'unsubscribe':
self.channels.pop(channel, None)
elif channel in self.channels:
- self.channels[channel].append(self.pickler.loads(message))
+ ch = self.channels[channel]
+ if sub_channel:
+ if not isinstance(ch, dict):
+ ch = {}
+ self.channels[channel] = ch
+ if sub_channel not in ch:
+ ch[sub_channel] = []
+ ch = ch[sub_channel]
+ ch.append(self.pickler.loads(msg))
else:
logger.warn('Got message for unsubscribed channel "%s"' % channel)
@@ -1,6 +1,6 @@
-'''Asynchronous Redis Connection For pulsar_ concurrent framework.
+'''Asynchronous Redis Connection for pulsar_ concurrent framework.
-Requires pulsar_
+Requires pulsar_ concurrent framework.
.. _pulsar: http://packages.python.org/pulsar/
'''
@@ -28,13 +28,21 @@ def __str__(self):
def execute(self):
result = self.connection.connect(self)
if is_async(result):
- result = result.add_callback(self._send)
+ result = result.add_callback(self.send)
else:
- result = self._send()
- result.add_callback(self.callback)
+ result = self.send()
+ if is_async(result):
+ result.add_callback(self.read_response)
+ else:
+ result = self.read_response()
+ result.addBoth(self.callback)
return self
-
- def read_response(self):
+
+ def _write(self, result=None):
+ return self.connection.sock.write(self.command)
+
+ @async(max_errors=1)
+ def read_response(self, result=None):
response = NOT_READY
sock = self.connection.sock
while response is NOT_READY:
@@ -46,15 +54,6 @@ def read_response(self):
yield response
@async(max_errors=1)
- def _send(self, result=None):
- redis_before_send.send(self.client.__class__,
- request=self,
- command=self.command)
- yield self.connection.sock.write(self.command)
- for response in self.read_response():
- yield response
-
- @async(max_errors=1)
def pool(self, num_messages=None):
if not self.pooling:
self.pooling = True
@@ -72,20 +71,20 @@ class RedisConnection(connection.Connection):
def _wrap_socket(self, sock):
return AsyncIOStream(sock)
- def on_connect(self, request, counter):
+ def on_connect(self, request):
"Initialize the connection, authenticate and select a database"
client = request.client.client
cmnd = None
if self.password:
- cmnd = self.execute_command(client, 'AUTH', self.password,
- release_connection=False)\
+ cmnd = self.request(client, 'AUTH', self.password,
+ release_connection=False).execute()\
.add_errback(lambda r: self.connection_error(r,
'Invalid Password'))
if self.db:
cmnd = make_async(cmnd)
cmnd.add_callback(
- lambda r: self.execute_command(
- client, 'SELECT', self.db, release_connection=False),
+ lambda r: self.request(client, 'SELECT', self.db,
+ release_connection=False).execute(),
lambda r: self.connection_error(r, 'Invalid Database'))
return cmnd
Oops, something went wrong.

0 comments on commit 7c3e758

Please sign in to comment.