'All the builtin backends (except memcached, see below) should warn on
keys that would be refused by memcached. This encourages portable
caching code without making it too difficult to use production backends
with more liberal key rules. Refs #6447.'

def test_invalid_keys(self):

    def func(key, *args):
        return key
    old_func = self.cache.key_func
    self.cache.key_func = func
    _warnings_state = get_warnings_state()
    warnings.simplefilter('error', CacheKeyWarning)
    try:
        self.assertRaises(CacheKeyWarning, self.cache.set, 'key    with    spaces', 'value')
        self.assertRaises(CacheKeyWarning, self.cache.set, ('a' * 251), 'value')
    finally:
        restore_warnings_state(_warnings_state)
        self.cache.key_func = old_func
