Skip to content

Commit 92f0cf1

Browse files
committed
100% coverage and fixed tests
1 parent 32a7c32 commit 92f0cf1

4 files changed

Lines changed: 27 additions & 15 deletions

File tree

github3/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ def __repr__(self):
7878
return '<github3-core at 0x{0:x}>'.format(id(self))
7979

8080
def _remove_none(self, data):
81+
if not data:
82+
return
8183
for (k, v) in list(data.items()):
8284
if v is None:
8385
del(data[k])

github3/utils.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
from datetime import datetime
2+
from requests.compat import basestring
23
import re
34

4-
try:
5-
# python 2
6-
_base_string_class = basestring
7-
except NameError:
8-
# python 3: no basestring class any more, everything is a str
9-
_base_string_class = str
10-
115
# with thanks to https://code.google.com/p/jquery-localtime/issues/detail?id=4
12-
ISO_8601 = re.compile("^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[0-1]|0[1-9]|[1-2][0-9])"
13-
"(T(2[0-3]|[0-1][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)?"
14-
"(Z|[+-](?:2[0-3]|[0-1][0-9]):[0-5][0-9])?)?$")
6+
ISO_8601 = re.compile("^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[0-1]|0"
7+
"[1-9]|[1-2][0-9])(T(2[0-3]|[0-1][0-9]):([0-5][0-9]):([0"
8+
"-5][0-9])(\.[0-9]+)?(Z|[+-](?:2[0-3]|[0-1][0-9]):[0-5]["
9+
"0-9])?)?$")
1510

1611

1712
def timestamp_parameter(timestamp, allow_none=True):
@@ -24,9 +19,10 @@ def timestamp_parameter(timestamp, allow_none=True):
2419
if isinstance(timestamp, datetime):
2520
return timestamp.isoformat()
2621

27-
if isinstance(timestamp, _base_string_class):
22+
if isinstance(timestamp, basestring):
2823
if not ISO_8601.match(timestamp):
29-
raise ValueError("Invalid timestamp: %s is not a valid ISO-8601 formatted date" % timestamp)
24+
raise ValueError(("Invalid timestamp: %s is not a valid ISO-8601"
25+
" formatted date") % timestamp)
3026
return timestamp
3127

3228
raise ValueError("Cannot accept type %s for timestamp" % type(timestamp))

tests/test_github.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def test_key(self):
229229
def test_iter_all_repos(self):
230230
self.response('repo', _iter=True)
231231
self.get('https://api.github.com/repositories')
232-
self.conf.update(params=None)
232+
self.conf.update(params={})
233233

234234
repo = next(self.g.iter_all_repos())
235235
expect(repo).isinstance(github3.repos.Repository)
@@ -243,15 +243,25 @@ def test_iter_all_repos(self):
243243
assert(repo.id > 100000)
244244
self.mock_assertions()
245245

246+
repo = next(self.g.iter_all_repos(per_page=100))
247+
self.conf.update(params={'per_page': 100})
248+
expect(repo).isinstance(github3.repos.Repository)
249+
self.mock_assertions()
250+
246251
def test_iter_all_users(self):
247252
self.response('user', _iter=True)
248253
self.get('https://api.github.com/users')
249-
self.conf.update(params=None)
254+
self.conf.update(params={})
250255

251256
repo = next(self.g.iter_all_users())
252257
expect(repo).isinstance(github3.users.User)
253258
self.mock_assertions()
254259

260+
repo = next(self.g.iter_all_users(per_page=100))
261+
self.conf.update(params={'per_page': 100})
262+
expect(repo).isinstance(github3.users.User)
263+
self.mock_assertions()
264+
255265
def test_iter_authorizations(self):
256266
self.response('authorization', _iter=True)
257267
self.get('https://api.github.com/authorizations')

tests/test_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,8 @@ def test_invalid_datestring(self):
3333

3434
def test_none_handling(self):
3535
self.assertTrue(timestamp_parameter(None, allow_none=True) is None)
36-
self.assertRaises(ValueError, timestamp_parameter, None, allow_none=False)
36+
self.assertRaises(ValueError, timestamp_parameter, None,
37+
allow_none=False)
38+
39+
def test_invalid_type_handling(self):
40+
self.assertRaises(ValueError, timestamp_parameter, 1)

0 commit comments

Comments
 (0)