diff options
author | Sean Reifschneider <jafo@tummy.com> | 2013-06-02 15:09:45 -0600 |
---|---|---|
committer | Sean Reifschneider <jafo@tummy.com> | 2013-06-02 15:09:45 -0600 |
commit | e0f4f6e248de458cabb09a4515f313b5453777ae (patch) | |
tree | 9b25c00b56a60278adcc95b135f53fead229717b | |
parent | 0e106fc6054a59d51b996325e944fea42f910300 (diff) | |
download | python-memcached-e0f4f6e248de458cabb09a4515f313b5453777ae.tar.gz |
Adding a test for set_multi submitted by Ben Hoyt.
-rw-r--r-- | tests/Makefile | 7 | ||||
-rw-r--r-- | tests/test_setmulti.py | 67 |
2 files changed, 74 insertions, 0 deletions
diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..a844aa4 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,7 @@ +TESTS = $(wildcard test_*.py) + +test: + @- $(foreach TEST,$(TESTS), \ + echo === Running test: $(TEST); \ + python $(TEST); \ + ) diff --git a/tests/test_setmulti.py b/tests/test_setmulti.py new file mode 100644 index 0000000..cba43f8 --- /dev/null +++ b/tests/test_setmulti.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python +# +# Tests for set_multi. +# +#=============== +# This is based on a skeleton test file, more information at: +# +# https://github.com/linsomniac/python-unittest-skeleton + +import unittest + +import sys +sys.path.append('..') +import memcache +import socket + +DEBUG = False + + +class test_Memcached_Set_Multi(unittest.TestCase): + def setUp(self): + RECV_CHUNKS = ['chunk1'] + + class FakeSocket(object): + def __init__(self, *args): + if DEBUG: + print 'FakeSocket{0!r}'.format(args) + self._recv_chunks = list(RECV_CHUNKS) + + def connect(self, *args): + if DEBUG: + print 'FakeSocket.connect{0!r}'.format(args) + + def sendall(self, *args): + if DEBUG: + print 'FakeSocket.sendall{0!r}'.format(args) + + def recv(self, *args): + if self._recv_chunks: + data = self._recv_chunks.pop(0) + else: + data = '' + if DEBUG: + print 'FakeSocket.recv{0!r} -> {1!r}'.format(args, data) + return data + + def close(self): + if DEBUG: + print 'FakeSocket.close()' + + self.old_socket = socket.socket + socket.socket = FakeSocket + + def tearDown(self): + socket.socket = self.old_socket + + def test_Socket_Disconnect(self): + client = memcache.Client(['memcached'], debug=True) + mapping = {'foo': 'FOO', 'bar': 'BAR'} + bad_keys = client.set_multi(mapping) + + self.assertEqual(bad_keys, 1) #@@@ Fix this + + if DEBUG: + print 'set_multi({0!r}) -> {1!r}'.format(mapping, bad_keys) + +unittest.main() |