Skip to content

Commit

Permalink
Merge pull request #50 from agoragames/fix-py3-int-division
Browse files Browse the repository at this point in the history
Fixes #49 integer division in python3.
  • Loading branch information
czarneckid authored Jan 11, 2018
2 parents a36f5fd + af775a0 commit 48b04a6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
4 changes: 3 additions & 1 deletion leaderboard/leaderboard.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import division

from redis import StrictRedis, Redis, ConnectionPool
import math
import sys
Expand Down Expand Up @@ -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

Expand Down
11 changes: 6 additions & 5 deletions test/leaderboard/__init__.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down
17 changes: 8 additions & 9 deletions test/leaderboard/leaderboard_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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(
Expand Down Expand Up @@ -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))]
Expand Down

0 comments on commit 48b04a6

Please sign in to comment.