Skip to content

Commit

Permalink
tests should pass on older redis versions
Browse files Browse the repository at this point in the history
  • Loading branch information
andy committed Apr 27, 2013
1 parent f57d471 commit a4a44dc
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/server_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,18 +457,39 @@ def test_renamenx(self):
self.assertEquals(self.client['b'], b('2'))

def test_set_nx(self):
version = self.client.info()['redis_version']
if StrictVersion(version) < StrictVersion('2.6.12'):
try:
raise unittest.SkipTest()
except AttributeError:
return

self.assertEquals(self.client.set('foo', '1', nx=True), True)
self.assertEquals(self.client.set('foo', '2', nx=True), None)
self.assertEquals(self.client.get('foo'), b('1'))

def test_set_xx(self):
version = self.client.info()['redis_version']
if StrictVersion(version) < StrictVersion('2.6.12'):
try:
raise unittest.SkipTest()
except AttributeError:
return

self.assertEquals(self.client.set('foo', '1', xx=True), None)
self.assertEquals(self.client.get('foo'), None)
self.client.set('foo', 'bar')
self.assertEquals(self.client.set('foo', '2', xx=True), True)
self.assertEquals(self.client.get('foo'), b('2'))

def test_set_px(self):
version = self.client.info()['redis_version']
if StrictVersion(version) < StrictVersion('2.6.12'):
try:
raise unittest.SkipTest()
except AttributeError:
return

self.assertEquals(self.client.set('foo', '1', px=10000), True)
self.assertEquals(self.client['foo'], b('1'))
self.assert_(0 < self.client.pttl('foo') <= 10000)
Expand All @@ -480,6 +501,13 @@ def test_set_px(self):
self.assert_(0 < self.client.ttl('foo') <= 1)

def test_set_ex(self):
version = self.client.info()['redis_version']
if StrictVersion(version) < StrictVersion('2.6.12'):
try:
raise unittest.SkipTest()
except AttributeError:
return

self.assertEquals(self.client.set('foo', '1', ex=10), True)
self.assertEquals(self.client.ttl('foo'), 10)
# expire given a timedelta
Expand All @@ -488,6 +516,13 @@ def test_set_ex(self):
self.assertEquals(self.client.ttl('foo'), 60)

def test_set_multipleoptions(self):
version = self.client.info()['redis_version']
if StrictVersion(version) < StrictVersion('2.6.12'):
try:
raise unittest.SkipTest()
except AttributeError:
return

self.client['foo'] = 'val'
self.assertEquals(
self.client.set('foo', 'bar', xx=True, px=10000),
Expand Down

0 comments on commit a4a44dc

Please sign in to comment.