diff --git a/leaderboard/leaderboard.py b/leaderboard/leaderboard.py index 61be149..fd2a2ca 100644 --- a/leaderboard/leaderboard.py +++ b/leaderboard/leaderboard.py @@ -1,3 +1,5 @@ +from __future__ import division + from redis import StrictRedis, Redis, ConnectionPool import math import sys @@ -1004,7 +1006,7 @@ def around_me_in(self, leaderboard_name, member, **options): page_size = options.get('page_size', self.page_size) - starting_offset = reverse_rank_for_member - (page_size / 2) + starting_offset = reverse_rank_for_member - (page_size // 2) if starting_offset < 0: starting_offset = 0 diff --git a/test/leaderboard/__init__.py b/test/leaderboard/__init__.py index 1f5e423..58ed93c 100644 --- a/test/leaderboard/__init__.py +++ b/test/leaderboard/__init__.py @@ -1,9 +1,10 @@ +from __future__ import absolute_import import unittest -from leaderboard_test import LeaderboardTest -from tie_ranking_leaderboard_test import TieRankingLeaderboardTest -from competition_ranking_leaderboard_test import CompetitionRankingLeaderboardTest -from reverse_tie_ranking_leaderboard_test import ReverseTieRankingLeaderboardTest -from reverse_competition_ranking_leaderboard_test import ReverseCompetitionRankingLeaderboardTest +from .leaderboard_test import LeaderboardTest +from .tie_ranking_leaderboard_test import TieRankingLeaderboardTest +from .competition_ranking_leaderboard_test import CompetitionRankingLeaderboardTest +from .reverse_tie_ranking_leaderboard_test import ReverseTieRankingLeaderboardTest +from .reverse_competition_ranking_leaderboard_test import ReverseCompetitionRankingLeaderboardTest def all_tests(): diff --git a/test/leaderboard/leaderboard_test.py b/test/leaderboard/leaderboard_test.py index e7ea0af..05bdfd8 100644 --- a/test/leaderboard/leaderboard_test.py +++ b/test/leaderboard/leaderboard_test.py @@ -8,7 +8,7 @@ class LeaderboardTest(unittest.TestCase): def setUp(self): - self.leaderboard = Leaderboard('name') + self.leaderboard = Leaderboard('name', decode_responses=True) def tearDown(self): self.leaderboard.redis_connection.flushdb() @@ -22,7 +22,7 @@ def test_version(self): def test_init_with_defaults(self): 'name'.should.equal(self.leaderboard.leaderboard_name) - len(self.leaderboard.options).should.be(1) + len(self.leaderboard.options).should.be(2) self.leaderboard.options['connection_pool'].should.be.a(ConnectionPool) self.leaderboard.redis_connection.should.be.a(Redis) self.leaderboard.DEFAULT_PAGE_SIZE.should.equal( @@ -388,17 +388,16 @@ def test_around_me(self): 1) leaders_around_me = self.leaderboard.around_me('member_30') - (len(leaders_around_me) / - 2).should.equal(self.leaderboard.page_size / - 2) + (len(leaders_around_me) // 2).should.equal(self.leaderboard.page_size // 2) leaders_around_me = self.leaderboard.around_me('member_1') - len(leaders_around_me).should.equal(self.leaderboard.page_size / 2 + 1) + len(leaders_around_me).should.equal(self.leaderboard.page_size // 2 + 1) leaders_around_me = self.leaderboard.around_me('member_76') - (len(leaders_around_me) / - 2).should.equal(self.leaderboard.page_size / - 2) + (len(leaders_around_me) // 2).should.equal(self.leaderboard.page_size // 2) + + leaders_around_me = self.leaderboard.around_me('member_76', page_size=1) + (len(leaders_around_me) // 2).should.equal(0) def test_members_only(self): exp = [{'member': 'member_%d' % x} for x in reversed(range(1, 27))]