diff --git a/.travis.yml b/.travis.yml index 281d95e5..a15634ca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,12 @@ language: python +dist: xenial +sudo: true python: - 2.7 - 3.4 - 3.5 - 3.6 + - 3.7 env: - DJANGO_VERSION='>=1.11,<2.0' - DJANGO_VERSION='>=2.0,<2.1' @@ -16,6 +19,8 @@ matrix: env: DJANGO_VERSION='>=2.1,<2.2' - python: 3.4 env: DJANGO_VERSION='>=2.1,<2.2' + - python: 3.7 + env: DJANGO_VERSION='>=1.11,<2.0' # command to run tests install: ./install_redis.sh script: make test DJANGO_VERSION=$DJANGO_VERSION diff --git a/install_redis.sh b/install_redis.sh index a949ea2c..f92b462b 100755 --- a/install_redis.sh +++ b/install_redis.sh @@ -3,5 +3,6 @@ : ${REDIS_VERSION:="4.0.11"} test -d redis || git clone https://github.com/antirez/redis +git -C redis fetch git -C redis checkout $REDIS_VERSION make -C redis diff --git a/redis_cache/sharder.py b/redis_cache/sharder.py index ed65224f..3e05b735 100644 --- a/redis_cache/sharder.py +++ b/redis_cache/sharder.py @@ -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 @@ -23,7 +24,7 @@ def __init__(self, node, i): self._position = get_slot(key) def __gt__(self, other): - if isinstance(other, int): + if isinstance(other, integer_types): return self._position > other elif isinstance(other, Node): return self._position > other._position diff --git a/requirements-dev.txt b/requirements-dev.txt index a910d2be..5a2be62c 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -2,4 +2,5 @@ hiredis==0.2.0 django-nose==1.4.4 nose==1.3.6 msgpack-python==0.4.6 -pyyaml==3.11 +pyyaml +tox diff --git a/tests/settings.py b/tests/settings.py index 6ce13034..c5bd82a7 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -1,3 +1,5 @@ +import os + DEBUG = True DATABASES = { @@ -33,3 +35,5 @@ } TEST_RUNNER = 'django_nose.NoseTestSuiteRunner' MIDDLEWARE_CLASSES = tuple() + +TEST_REDIS_SERVER = os.getenv('REDIS_CACHE_TEST_SERVER', './redis/src/redis-server') diff --git a/tests/testapp/tests/base_tests.py b/tests/testapp/tests/base_tests.py index 4af2f3ed..5306aa8a 100644 --- a/tests/testapp/tests/base_tests.py +++ b/tests/testapp/tests/base_tests.py @@ -12,6 +12,7 @@ except ImportError: import pickle +from django.conf import settings from django.core.cache import caches from django.core.exceptions import ImproperlyConfigured from django.test import TestCase, override_settings @@ -52,6 +53,12 @@ def start_redis_servers(servers, db=None, master=None): db=db, password=REDIS_PASSWORD ) + server_path = getattr( + settings, + 'TEST_REDIS_SERVER', + './redis/src/redis-server', + ) + for i, server in enumerate(servers): connection_kwargs = parse_connection_kwargs( server, @@ -78,7 +85,7 @@ def start_redis_servers(servers, db=None, master=None): ) ) - args = ['./redis/src/redis-server'] + [ + args = [server_path] + [ "--{parameter} {value}".format(parameter=parameter, value=value) for parameter, value in parameters.items() ] @@ -93,8 +100,10 @@ class SetupMixin(object): @classmethod def tearDownClass(cls): - for p in cls.processes: - p.kill() + if cls.processes: + for p in cls.processes: + p.kill() + cls.processes = None # Give redis processes some time to shutdown diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..9a22915d --- /dev/null +++ b/tox.ini @@ -0,0 +1,22 @@ +[tox] +envlist = py{27,34,35,36}-django{111}, + py{34}-django{20}, + py{35,36,37}-django{20,21} + +install_command = pip install {opts} {packages} + +[testenv] +basepython = + py27: python2.7 + py34: python3.4 + py35: python3.5 + py36: python3.6 + py37: python3.7 +whitelist_externals = + make +passenv = + REDIS_CACHE_TEST_SERVER = {env:REDIS_CACHE_TEST_SERVER:./redis/src/redis-server} +commands = + django111: make test DJANGO_VERSION=">=1.11,<2.0" + django20: make test DJANGO_VERSION=">=2.0,<2.1" + django21: make test DJANGO_VERSION=">=2.1,<2.2"