8000 Merge branch 'pr/227' into develop · waynr/github3.py@ab5e05c · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit ab5e05c

Browse filesBrowse files
committed
Merge branch 'pr/227' into develop
2 parents 0565d3e + e08a5b0 commit ab5e05c

15 files changed

+74
-64
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ python:
44
- 2.7
55
- 3.2
66
- 3.3
7+
- 3.4
78
- pypy
89
# command to run tests, e.g. python setup.py test
910
before_script:

AUTHORS.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,5 @@ Contributors
6060
- Philip Chimento (@ptomato)
6161

6262
- Benjamin Gilbert (@bgilbert)
63+
64+
- Daniel Johnson (@danielj7)

setup.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
"github3.search",
1919
]
2020

21-
kwargs['tests_require'] = ['mock == 1.0.1', 'betamax >=0.1.6', 'pytest']
21+
kwargs['tests_require'] = ['betamax >=0.2.0', 'pytest']
2222
if sys.version_info < (3, 0):
23-
kwargs['tests_require'].append('unittest2==0.5.1')
23+
kwargs['tests_require'].append('unittest2 ==0.5.1')
24+
if sys.version_info < (3, 3):
25+
kwargs['tests_require'].append('mock ==1.0.1')
2426

2527
if sys.argv[-1] in ("submit", "publish"):
2628
os.system("python setup.py bdist_wheel sdist upload")
@@ -77,6 +79,7 @@ def run_tests(self):
7779
'Programming Language :: Python :: 3',
7880
'Programming Language :: Python :: 3.2',
7981
'Programming Language :: Python :: 3.3',
82+
'Programming Language :: Python :: 3.4',
8083
'Programming Language :: Python :: Implementation :: CPython',
8184
],
8285
extras_require={'test': kwargs['tests_require']},

tests/test_api.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import github3
22
from unittest import TestCase
3-
from mock import patch, NonCallableMock
3+
#from .utils.mock import patch, NonCallableMock
4+
from .utils import mock
45

56

67
class TestAPI(TestCase):
78
def setUp(self):
8-
self.mock = patch('github3.api.gh', autospec=github3.GitHub)
9+
self.mock = mock.patch('github3.api.gh', autospec=github3.GitHub)
910
self.gh = self.mock.start()
1011

1112
def tearDown(self):
@@ -14,21 +15,21 @@ def tearDown(self):
1415
def test_authorize(self):
1516
args = ('login', 'password', ['scope1'], 'note', 'note_url.com', '',
1617
'')
17-
with patch.object(github3.api.GitHub, 'authorize') as authorize:
18+
with mock.patch.object(github3.api.GitHub, 'authorize') as authorize:
1819
github3.authorize(*args)
1920
authorize.assert_called_once_with(*args)
2021

2122
def test_login(self):
2223
args = ('login', 'password', None, None)
23-
with patch.object(github3.api.GitHub, 'login') as login:
24+
with mock.patch.object(github3.api.GitHub, 'login') as login:
2425
g = github3.login(*args)
2526
assert isinstance(g, github3.github.GitHub)
2627
assert not isinstance(g, github3.github.GitHubEnterprise)
2728
login.assert_called_with(*args)
2829

2930
def test_enterprise_login(self):
3031
args = ('login', 'password', None, 'http://ghe.invalid/', None)
31-
with patch.object(github3.api.GitHubEnterprise, 'login') as login:
32+
with mock.patch.object(github3.api.GitHubEnterprise, 'login') as login:
3233
g = github3.login(*args)
3334
assert isinstance(g, github3.github.GitHubEnterprise)
3435
login.assert_called_with('login', 'password', None, None)
@@ -143,7 +144,7 @@ def test_rate_limit(self):
143144
def test_ratelimit_remaining(self):
144145
# This prevents a regression in the API
145146
# See 81c800658db43f86419b9c0764fc16aad3d60007
146-
self.gh.ratelimit_remaining = NonCallableMock()
147+
self.gh.ratelimit_remaining = mock.NonCallableMock()
147148
github3.ratelimit_remaining()
148149

149150
def test_zen(self):

tests/test_github.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import github3
2-
from mock import patch, Mock
3-
from tests.utils import (BaseCase, load)
2+
from tests.utils import (BaseCase, load, mock)
43

54

65
def merge(first, second=None, **kwargs):
@@ -20,7 +19,7 @@ def test_init(self):
2019

2120
def test_context_manager(self):
2221
with github3.GitHub() as gh:
23-
gh.__exit__ = Mock()
22+
gh.__exit__ = mock.Mock()
2423
assert isinstance(gh, github3.GitHub)
2524

2625
gh.__exit__.assert_called()
@@ -92,7 +91,7 @@ def test_create_issue(self):
9291
assert i is None
9392
assert self.request.called is False
9493

95-
with patch.object(github3.GitHub, 'repository') as repo:
94+
with mock.patch.object(github3.GitHub, 'repository') as repo:
9695
repo.return_value = github3.repos.Repository(
9796
load('repo'), self.g)
9897
i = self.g.create_issue('user', 'repo', 'Title')
@@ -125,7 +124,7 @@ def test_delete_key(self):
125124
self.response(None, 204)
126125

127126
self.login()
128-
with patch.object(github3.github.GitHub, 'key') as key:
127+
with mock.patch.object(github3.github.GitHub, 'key') as key:
129128
key.return_value = github3.users.Key(load('key'), self.g)
130129
assert self.g.delete_key(10) is True
131130
key.return_value = None
@@ -216,7 +215,7 @@ def test_issue(self):
216215
'issues/1')
217216

218217
assert self.g.issue(None, None, 0) is None
219-
with patch.object(github3.github.GitHub, 'repository') as repo:
218+
with mock.patch.object(github3.github.GitHub, 'repository') as repo:
220219
repo.return_value = github3.repos.Repository(load('repo'))
221220
i = self.g.issue('user', 'repo', 1)
222221

@@ -315,7 +314,7 @@ def test_iter_followers(self):
315314

316315
self.assertRaises(github3.GitHubError, self.g.iter_followers)
317316

318-
with patch.object(github3.github.GitHub, 'user') as ghuser:
317+
with mock.patch.object(github3.github.GitHub, 'user') as ghuser:
319318
ghuser.return_value = github3.users.User(load('user'))
320319
u = next(self.g.iter_followers('sigmavirus24'))
321320
assert isinstance(u, github3.users.User)
@@ -337,7 +336,7 @@ def test_iter_following(self):
337336
self.assertRaises(github3.GitHubError, self.g.iter_following)
338337
assert self.request.called is False
339338

340-
with patch.object(github3.github.GitHub, 'user') as ghuser:
339+
with mock.patch.object(github3.github.GitHub, 'user') as ghuser:
341340
ghuser.return_value = github3.users.User(load('user'))
342341
u = next(self.g.iter_following('sigmavirus24'))
343342
assert isinstance(u, github3.users.User)
@@ -453,7 +452,7 @@ def test_iter_repo_issues(self):
453452
self.get('https://api.github.com/repos/sigmavirus24/github3.py/'
454453
'issues')
455454

456-
with patch.object(github3.GitHub, 'repository') as repo:
455+
with mock.patch.object(github3.GitHub, 'repository') as repo:
457456
repo.return_value = github3.repos.Repository(load('repo'),
458457
self.g)
459458
i = next(self.g.iter_repo_issues('sigmavirus24', 'github3.py'))
@@ -546,7 +545,7 @@ def test_iter_starred(self):
546545
github3.repos.Repository)
547546
self.mock_assertions()
548547

549-
with patch.object(github3.github.GitHub, 'user') as user:
548+
with mock.patch.object(github3.github.GitHub, 'user') as user:
550549
user.return_value = github3.users.User(load('user'))
551550
self.get('https://api.github.com/users/sigmavirus24/starred')
552551
assert isinstance(next(self.g.iter_starred('sigmavirus24')),
@@ -563,7 +562,7 @@ def test_iter_subscriptions(self):
563562
github3.repos.Repository)
564563
self.mock_assertions()
565564

566-
with patch.object(github3.github.GitHub, 'user') as user:
565+
with mock.patch.object(github3.github.GitHub, 'user') as user:
567566
user.return_value = github3.users.User(load('user'))
568567
self.get('https://api.github.com/users/sigmavirus24/'
569568
'subscriptions')
@@ -663,7 +662,7 @@ def test_pull_request(self):
663662
'github3.py/pulls/18')
664663
pr = None
665664

666-
with patch.object(github3.github.GitHub, 'repository') as repo:
665+
with mock.patch.object(github3.github.GitHub, 'repository') as repo:
667666
repo.return_value = github3.repos.Repository(load('repo'))
668667
pr = self.g.pull_request('sigmavirus24', 'github3.py', 18)
669668

@@ -766,8 +765,8 @@ def test_update_user(self):
766765
args = ('Ian Cordasco', 'example@mail.com', 'www.blog.com', 'company',
767766
'loc', True, 'bio')
768767

769-
with patch.object(github3.github.GitHub, 'user') as user:
770-
with patch.object(github3.users.User, 'update') as upd:
768+
with mock.patch.object(github3.github.GitHub, 'user') as user:
769+
with mock.patch.object(github3.users.User, 'update') as upd:
771770
user.return_value = github3.users.User(load('user'), self.g)
772771
upd.return_value = True
773772
assert self.g.update_user(*args)

tests/test_issues.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
from github3.issues.milestone import Milestone
66
from github3.issues import Issue
77
import datetime
8-
from tests.utils import BaseCase, load
9-
from mock import patch
8+
from tests.utils import BaseCase, load, mock
109

1110

1211
class TestLabel(BaseCase):
@@ -168,7 +167,7 @@ def test_assign(self):
168167

169168
self.login()
170169

171-
with patch.object(Issue, 'edit') as ed:
170+
with mock.patch.object(Issue, 'edit') as ed:
172171
ed.return_value = True
173172
assert self.i.assign(None) is False
174173
self.not_called()
@@ -186,7 +185,7 @@ def test_close(self):
186185
self.not_called()
187186
self.login()
188187

189-
with patch.object(Issue, 'edit') as ed:
188+
with mock.patch.object(Issue, 'edit') as ed:
190189
ed.return_value = True
191190
assert self.i.close()
192191
u = self.i.assignee.login if self.i.assignee else ''
@@ -274,7 +273,7 @@ def test_remove_all_labels(self):
274273

275274
self.login()
276275

277-
with patch.object(Issue, 'replace_labels') as rl:
276+
with mock.patch.object(Issue, 'replace_labels') as rl:
278277
rl.return_value = []
279278
assert self.i.remove_all_labels() == []
280279
rl.assert_called_once_with([])
@@ -300,7 +299,7 @@ def test_reopen(self):
300299
n = self.i.milestone.number if self.i.milestone else None
301300
u = self.i.assignee.login if self.i.assignee else None
302301

303-
with patch.object(Issue, 'edit') as ed:
302+
with mock.patch.object(Issue, 'edit') as ed:
304303
ed.return_value = True
305304
assert self.i.reopen()
306305
labels = [str(l) for l in self.i.labels]

tests/test_orgs.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import github3
2-
from mock import patch, Mock
3-
from tests.utils import BaseCase, load
2+
from tests.utils import BaseCase, load, mock
43

54

65
class TestTeam(BaseCase):
@@ -146,10 +145,10 @@ def test_add_member(self):
146145
self.assertRaises(github3.GitHubError, self.org.add_member, None, None)
147146

148147
self.login()
149-
with patch.object(github3.orgs.Organization, 'iter_teams') as it:
148+
with mock.patch.object(github3.orgs.Organization, 'iter_teams') as it:
150149
it.return_value = iter([])
151150
assert self.org.add_member('foo', 'bar') is False
152-
team = Mock()
151+
team = mock.Mock()
153152
team.name = 'bar'
154153
team.add_member.return_value = True
155154
it.return_value = iter([team])
@@ -160,10 +159,10 @@ def test_add_repo(self):
160159
self.assertRaises(github3.GitHubError, self.org.add_repo, None, None)
161160

162161
self.login()
163-
with patch.object(github3.orgs.Organization, 'iter_teams') as it:
162+
with mock.patch.object(github3.orgs.Organization, 'iter_teams') as it:
164163
it.return_value = iter([])
165164
assert self.org.add_repo('foo', 'bar') is False
166-
team = Mock()
165+
team = mock.Mock()
167166
team.name = 'bar'
168167
team.add_repo.return_value = True
169168
it.return_value = iter([team])
@@ -340,10 +339,10 @@ def test_remove_repo(self):
340339
None, None)
341340

342341
self.login()
343-
with patch.object(github3.orgs.Organization, 'iter_teams') as it:
342+
with mock.patch.object(github3.orgs.Organization, 'iter_teams') as it:
344343
it.return_value = iter([])
345344
assert self.org.remove_repo('foo', 'bar') is False
346-
team = Mock()
345+
team = mock.Mock()
347346
team.name = 'bar'
348347
team.remove_repo.return_value = True
349348
it.return_value = iter([team])

tests/test_pulls.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import github3
2-
from mock import patch
3-
from tests.utils import BaseCase, load
2+
from tests.utils import BaseCase, load, mock
43

54

65
class TestPullRequest(BaseCase):
@@ -38,7 +37,7 @@ def test_close(self):
3837

3938
self.login()
4039

41-
with patch.object(github3.pulls.PullRequest, 'update') as up:
40+
with mock.patch.object(github3.pulls.PullRequest, 'update') as up:
4241
up.return_value = True
4342
assert self.pull.close()
4443
up.assert_called_once_with(
@@ -133,7 +132,7 @@ def test_reopen(self):
133132
self.assertRaises(github3.GitHubError, self.pull.reopen)
134133

135134
self.login()
136-
with patch.object(github3.pulls.PullRequest, 'update') as up:
135+
with mock.patch.object(github3.pulls.PullRequest, 'update') as up:
137136
self.pull.reopen()
138137
up.assert_called_once_with(
139138
self.pull.title, self.pull.body, 'open')

tests/test_repos.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
import github3
33
from github3 import repos
44
from datetime import datetime
5-
from tests.utils import (BaseCase, load)
6-
from mock import patch, mock_open
5+
from tests.utils import (BaseCase, load, mock)
76

87

98
class TestRepository(BaseCase):
@@ -61,8 +60,8 @@ def test_archive(self):
6160
self.request.return_value.raw.seek(0)
6261
self.request.return_value._content_consumed = False
6362

64-
o = mock_open()
65-
with patch('{0}.open'.format(__name__), o, create=True):
63+
o = mock.mock_open()
64+
with mock.patch('{0}.open'.format(__name__), o, create=True):
6665
with open('archive', 'wb+') as fd:
6766
self.repo.archive('tarball', fd)
6867

@@ -398,15 +397,15 @@ def test_create_tag(self):
398397
None, None, None, None, None)
399398

400399
self.login()
401-
with patch.object(repos.Repository, 'create_ref'):
400+
with mock.patch.object(repos.Repository, 'create_ref'):
402401
assert self.repo.create_tag(None, None, None, None,
403402
None) is None
404403
tag = self.repo.create_tag(**data)
405404
assert isinstance(tag, github3.git.Tag)
406405
assert repr(tag).startswith('<Tag')
407406
self.mock_assertions()
408407

409-
with patch.object(repos.Repository, 'create_ref') as cr:
408+
with mock.patch.object(repos.Repository, 'create_ref') as cr:
410409
self.repo.create_tag('tag', '', 'fakesha', '', '',
411410
lightweight=True)
412411
cr.assert_called_once_with('refs/tags/tag', 'fakesha')
@@ -1017,12 +1016,12 @@ def test_update_label(self):
10171016
self.not_called()
10181017

10191018
self.login()
1020-
with patch.object(repos.Repository, 'label') as l:
1019+
with mock.patch.object(repos.Repository, 'label') as l:
10211020
l.return_value = None
10221021
assert self.repo.update_label('foo', 'bar') is False
10231022
self.not_called()
10241023

1025-
with patch.object(repos.Repository, 'label') as l:
1024+
with mock.patch.object(repos.Repository, 'label') as l:
10261025
l.return_value = github3.issues.label.Label(load('label'), self.g)
10271026
assert self.repo.update_label('big_bug', 'fafafa')
10281027

tests/test_structs.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import github3
22
from github3.structs import GitHubIterator
3-
from tests.utils import BaseCase
4-
from mock import patch
3+
from tests.utils import BaseCase, mock
54

65

76
class TestGitHubIterator(BaseCase):
@@ -71,7 +70,7 @@ def test_count_reaches_0(self):
7170
self.mock_assertions()
7271

7372
def test_refresh(self):
74-
with patch.object(GitHubIterator, '__iter__') as i:
73+
with mock.patch.object(GitHubIterator, '__iter__') as i:
7574
self.i.refresh()
7675
i.__iter__.assert_called()
7776

0 commit comments

Comments
 (0)
0