diff options
| author | Przemysław Suliga <suligap@gmail.com> | 2016-04-04 20:18:11 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-04-05 11:16:04 -0400 |
| commit | 90ce5d46bf62a74d7c78a61c1a7bab64f7cb1735 (patch) | |
| tree | f4dbe8a8ad0947a8ab3a562eac4055661028c420 /tests/cache | |
| parent | 369fa471f46cd517edf5fc82e4ef6138de3cff6e (diff) | |
Fixed #26462 -- Fixed Python 2 UnicodeEncodeError when warning about long cache keys.
Diffstat (limited to 'tests/cache')
| -rw-r--r-- | tests/cache/tests.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/tests/cache/tests.py b/tests/cache/tests.py index ee27d71563..ee1501a029 100644 --- a/tests/cache/tests.py +++ b/tests/cache/tests.py @@ -585,15 +585,31 @@ class BaseCacheTests(object): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") # memcached does not allow whitespace or control characters in keys - cache.set('key with spaces', 'value') + key = 'key with spaces and 清' + cache.set(key, 'value') self.assertEqual(len(w), 1) self.assertIsInstance(w[0].message, CacheKeyWarning) + self.assertEqual( + # warnings.warn() crashes on Python 2 if message isn't + # coercible to str. + str(w[0].message.args[0]), + "Cache key contains characters that will cause errors if used " + "with memcached: %r" % key, + ) with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") # memcached limits key length to 250 - cache.set('a' * 251, 'value') + key = ('a' * 250) + '清' + cache.set(key, 'value') self.assertEqual(len(w), 1) self.assertIsInstance(w[0].message, CacheKeyWarning) + self.assertEqual( + # warnings.warn() crashes on Python 2 if message isn't + # coercible to str. + str(w[0].message.args[0]), + 'Cache key will cause errors if used with memcached: ' + '%r (longer than %s)' % (key, 250), + ) finally: cache.key_func = old_func |
