Skip to content

Commit 5c60b01

Browse files
committed
Use mock for sleep in rate limit tests.
1 parent fbe6e45 commit 5c60b01

1 file changed

Lines changed: 7 additions & 14 deletions

File tree

tests/test_unit.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
# This file is part of python-github2, and is made available under the 3-clause
88
# BSD license. See LICENSE for the full details.
99

10-
import datetime
1110
import unittest
1211

12+
from mock import patch
1313
from nose.tools import (eq_, ok_, raises)
14-
from nose.plugins.attrib import attr
1514

1615
from github2.core import (AuthError, repr_string, requires_auth)
1716
from github2.issues import Issue
@@ -44,23 +43,17 @@ def test_non_standard_host(self):
4443

4544
class RateLimits(utils.HttpMockTestCase):
4645

47-
"""Test API rate-limitting."""
46+
"""Test API rate-limiting."""
4847

49-
@attr('slow')
50-
def test_delays(self):
51-
"""Test call delay is at least one second."""
48+
@patch('github2.request.time.sleep')
49+
def test_delays(self, sleep):
50+
"""Test calls in quick succession are delayed."""
5251
client = Github(requests_per_second=.5)
5352
client.users.show('defunkt')
54-
start = datetime.datetime.utcnow()
5553
client.users.show('mojombo')
56-
end = datetime.datetime.utcnow()
5754

58-
delta = end - start
59-
delta_seconds = delta.days * 24 * 60 * 60 + delta.seconds
60-
61-
ok_(delta_seconds >= 2,
62-
"Expected .5 reqs per second to require a 2 second delay between "
63-
"calls.")
55+
# 0.5 requests per second, means a two second delay
56+
sleep.assert_called_once_with(2.0)
6457

6558

6659
class BaseDataIter(utils.HttpMockTestCase):

0 commit comments

Comments
 (0)