summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Davis <matteius@gmail.com>2017-09-05 16:03:09 -0400
committerTim Graham <timograham@gmail.com>2017-11-14 14:40:35 -0500
commitcc94e72f629a7145158def6a363ff51e56dee022 (patch)
tree26c41d4a950afd143a7e3d68decadfaec686fc59
parent2e9dcfbb8efb8726468b02a2ed79f01a18ec2c26 (diff)
downloadpython-memcached-cc94e72f629a7145158def6a363ff51e56dee022.tar.gz
Fix crash on Python 3 in touch() logging
-rw-r--r--memcache.py2
-rw-r--r--test-requirements.txt1
-rw-r--r--tests/test_memcache.py14
3 files changed, 15 insertions, 2 deletions
diff --git a/memcache.py b/memcache.py
index 41ea9ca..cf2a89a 100644
--- a/memcache.py
+++ b/memcache.py
@@ -566,7 +566,7 @@ class Client(threading.local):
if line and line.strip() in expected:
return 1
self.debuglog('%s expected %s, got: %r'
- % (cmd, ' or '.join(expected), line))
+ % (cmd, b' or '.join(expected), line))
except socket.error as msg:
if isinstance(msg, tuple):
msg = msg[1]
diff --git a/test-requirements.txt b/test-requirements.txt
index 8f21390..d80827e 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -1,3 +1,4 @@
nose
coverage
hacking
+mock
diff --git a/tests/test_memcache.py b/tests/test_memcache.py
index 6408e81..58024cd 100644
--- a/tests/test_memcache.py
+++ b/tests/test_memcache.py
@@ -2,9 +2,10 @@ from __future__ import print_function
import unittest
+import mock
import six
-from memcache import Client, SERVER_MAX_KEY_LENGTH, SERVER_MAX_VALUE_LENGTH # noqa: H301
+from memcache import Client, _Host, SERVER_MAX_KEY_LENGTH, SERVER_MAX_VALUE_LENGTH # noqa: H301
from .utils import captured_stderr
@@ -183,6 +184,17 @@ class TestMemcache(unittest.TestCase):
"'NOT_FOUND'\n"
)
+ @mock.patch.object(_Host, 'readline')
+ def test_touch_unexpected_reply(self, mock_readline):
+ """touch() logs an error upon receiving an unexpected reply."""
+ mock_readline.return_value = 'SET' # the unexpected reply
+ with captured_stderr() as output:
+ self.mc.touch('key')
+ self.assertEqual(
+ output.getvalue(),
+ "MemCached: touch expected %s, got: 'SET'\n" % b'TOUCHED'
+ )
+
if __name__ == '__main__':
unittest.main()