Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_redislite_double_patch_redis(self):
original_redis = redis.Redis
redislite.patch.patch_redis()
self.assertNotEqual(original_redis, redis.Redis)
redislite.patch.patch_redis()
self.assertNotEqual(original_redis, redis.Redis)
redislite.patch.unpatch_redis()
self.assertEqual(original_redis, redis.Redis)
self.tempdir,
'test_redislite_patch_redis_with_dbfile.db'
)
if os.path.exists(dbfilename):
os.remove(dbfilename)
redislite.patch.patch_redis(dbfilename)
r = redis.Redis()
self._log_redis_pid(r)
self.assertIsInstance(r.pid, int) # Should have a redislite pid
s = redis.Redis()
self._log_redis_pid(s)
self.assertIsInstance(r.pid, int) # Should have a redislite pid
# Both instances should be talking to the same redis server
self.assertEqual(r.pid, s.pid)
redislite.patch.unpatch_redis()
r._cleanup()
s._cleanup()
if os.path.exists(dbfilename):
os.remove(dbfilename)
def test_redislite_patch_redis(self):
redislite.patch.patch_redis()
r = redis.Redis()
self._log_redis_pid(r)
self.assertIsInstance(r.pid, int) # Should have a redislite pid
s = redis.StrictRedis()
self._log_redis_pid(s)
self.assertIsInstance(s.pid, int) # Should have a redislite pid
redislite.patch.unpatch_redis()
def test_redislite_patch_redis_with_dbfile_in_cwd(self):
dbfilename = 'test_redislite_patch_redis_with_dbfile_in_cwd.db'
if os.path.exists(dbfilename):
os.remove(dbfilename)
redislite.patch.patch_redis(dbfilename)
r = redis.Redis()
self._log_redis_pid(r)
self.assertIsInstance(r.pid, int) # Should have a redislite pid
s = redis.Redis()
self._log_redis_pid(s)
self.assertIsInstance(r.pid, int) # Should have a redislite pid
# Both instances should be talking to the same redis server
self.assertEqual(r.pid, s.pid)
redislite.patch.unpatch_redis()
r._cleanup()
s._cleanup()
if os.path.exists(dbfilename):
os.remove(dbfilename)