Skip to content

Commit

Permalink
Fix compatibility issue between python 2.* and 3.*
Browse files Browse the repository at this point in the history
  • Loading branch information
joehybird committed Jan 15, 2019
1 parent ae33e69 commit 06f88d6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
8 changes: 3 additions & 5 deletions redis_cache/sharder.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from bisect import insort, bisect
import hashlib
from django.utils.encoding import force_text

from django.utils.encoding import force_text
from django.utils.six import integer_types

DIGITS = 8

Expand All @@ -23,17 +24,14 @@ def __init__(self, node, i):
self._position = get_slot(key)

def __gt__(self, other):
# WARNING PYTHON < 3 : in get_slot() if the hash value overflows integer a LONG is returned !
if isinstance(other, (int, long)):
if isinstance(other, integer_types):
return self._position > other
elif isinstance(other, Node):
return self._position > other._position
raise TypeError(
'Cannot compare this class with "%s" type' % type(other)
)

def __str__(self):
return 'Node(position=%s, i=%s, node=%s)' % (self._position, self._i, self.node)

class HashRing(object):

Expand Down
10 changes: 3 additions & 7 deletions tests/testapp/tests/serializers_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,15 @@ class BaseSerializerTestCase(SetupMixin, TestCase):
converts_tuple_to_list = False
serializes_objects = True

def assertion_message(self, name):
return '%s %s' % (self.__class__.__name__, name)

def test_string(self):
self.cache.set('a', 'a')
self.assertEqual(self.cache.get('a'), 'a', self.assertion_message('test_string'))
self.assertEqual(self.cache.get('a'), 'a')

def test_unicode(self):
self.cache.set('Iñtërnâtiônàlizætiøn', 'Iñtërnâtiônàlizætiøn2')
self.assertEqual(
self.cache.get('Iñtërnâtiônàlizætiøn'),
'Iñtërnâtiônàlizætiøn2',
self.assertion_message('test_unicode')
'Iñtërnâtiônàlizætiøn2'
)

def test_number(self):
Expand Down Expand Up @@ -71,7 +67,7 @@ def test_dictionary(self):
'function': f,
'class': C,
})
self.assertEqual(stuff, data, self.assertion_message('test_dictionary'))
self.assertEqual(stuff, data)


@override_settings(CACHES={
Expand Down

0 comments on commit 06f88d6

Please sign in to comment.