1
1
import github3
2
- try :
3
- from unittest .mock import patch , Mock
4
- except ImportError :
5
- from mock import patch , Mock
6
- from tests .utils import (BaseCase , load )
2
+ from tests .utils import (BaseCase , load , mock )
7
3
8
4
9
5
def merge (first , second = None , ** kwargs ):
@@ -23,7 +19,7 @@ def test_init(self):
23
19
24
20
def test_context_manager (self ):
25
21
with github3 .GitHub () as gh :
26
- gh .__exit__ = Mock ()
22
+ gh .__exit__ = mock . Mock ()
27
23
assert isinstance (gh , github3 .GitHub )
28
24
29
25
gh .__exit__ .assert_called ()
@@ -95,7 +91,7 @@ def test_create_issue(self):
95
91
assert i is None
96
92
assert self .request .called is False
97
93
98
- with patch .object (github3 .GitHub , 'repository' ) as repo :
94
+ with mock . patch .object (github3 .GitHub , 'repository' ) as repo :
99
95
repo .return_value = github3 .repos .Repository (
100
96
load ('repo' ), self .g )
101
97
i = self .g .create_issue ('user' , 'repo' , 'Title' )
@@ -128,7 +124,7 @@ def test_delete_key(self):
128
124
self .response (None , 204 )
129
125
130
126
self .login ()
131
- with patch .object (github3 .github .GitHub , 'key' ) as key :
127
+ with mock . patch .object (github3 .github .GitHub , 'key' ) as key :
132
128
key .return_value = github3 .users .Key (load ('key' ), self .g )
133
129
assert self .g .delete_key (10 ) is True
134
130
key .return_value = None
@@ -219,7 +215,7 @@ def test_issue(self):
219
215
'issues/1' )
220
216
8000
221
217
assert self .g .issue (None , None , 0 ) is None
222
- with patch .object (github3 .github .GitHub , 'repository' ) as repo :
218
+ with mock . patch .object (github3 .github .GitHub , 'repository' ) as repo :
223
219
repo .return_value = github3 .repos .Repository (load ('repo' ))
224
220
i = self .g .issue ('user' , 'repo' , 1 )
225
221
@@ -318,7 +314,7 @@ def test_iter_followers(self):
318
314
319
315
self .assertRaises (github3 .GitHubError , self .g .iter_followers )
320
316
321
- with patch .object (github3 .github .GitHub , 'user' ) as ghuser :
317
+ with mock . patch .object (github3 .github .GitHub , 'user' ) as ghuser :
322
318
ghuser .return_value = github3 .users .User (load ('user' ))
323
319
u = next (self .g .iter_followers ('sigmavirus24' ))
324
320
assert isinstance (u , github3 .users .User )
@@ -340,7 +336,7 @@ def test_iter_following(self):
340
336
self .assertRaises (github3 .GitHubError , self .g .iter_following )
341
337
assert self .request .called is False
342
338
343
- with patch .object (github3 .github .GitHub , 'user' ) as ghuser :
339
+ with mock . patch .object (github3 .github .GitHub , 'user' ) as ghuser :
344
340
ghuser .return_value = github3 .users .User (load ('user' ))
345
341
u = next (self .g .iter_following ('sigmavirus24' ))
346
342
assert isinstance (u , github3 .users .User )
@@ -456,7 +452,7 @@ def test_iter_repo_issues(self):
456
452
self .get ('https://api.github.com/repos/sigmavirus24/github3.py/'
457
453
'issues' )
458
454
459
- with patch .object (github3 .GitHub , 'repository' ) as repo :
455
+ with mock . patch .object (github3 .GitHub , 'repository' ) as repo :
460
456
repo .return_value = github3 .repos .Repository (load ('repo' ),
461
457
self .g )
462
458
i = next (self .g .iter_repo_issues ('sigmavirus24' , 'github3.py' ))
@@ -549,7 +545,7 @@ def test_iter_starred(self):
549
545
github3 .repos .Repository )
550
546
self .mock_assertions ()
551
547
552
- with patch .object (github3 .github .GitHub , 'user' ) as user :
548
+ with mock . patch .object (github3 .github .GitHub , 'user' ) as user :
553
549
user .return_value = github3 .users .User (load ('user' ))
554
550
self .get ('https://api.github.com/users/sigmavirus24/starred' )
555
551
assert isinstance (next (self .g .iter_starred ('sigmavirus24' )),
@@ -566,7 +562,7 @@ def test_iter_subscriptions(self):
566
562
github3 .repos .Repository )
567
563
self .mock_assertions ()
568
564
569
- with patch .object (github3 .github .GitHub , 'user' ) as user :
565
+ with mock . patch .object (github3 .github .GitHub , 'user' ) as user :
570
566
user .return_value = github3 .users .User (load ('user' ))
571
567
self .get ('https://api.github.com/users/sigmavirus24/'
572
568
'subscriptions' )
@@ -666,7 +662,7 @@ def test_pull_request(self):
666
662
'github3.py/pulls/18' )
667
663
pr = None
668
664
669
- with patch .object (github3 .github .GitHub , 'repository' ) as repo :
665
+ with mock . patch .object (github3 .github .GitHub , 'repository' ) as repo :
670
666
repo .return_value = github3 .repos .Repository (load ('repo' ))
671
667
pr = self .g .pull_request ('sigmavirus24' , 'github3.py' , 18 )
672
668
@@ -769,8 +765,8 @@ def test_update_user(self):
769
765
args = ('Ian Cordasco' , 'example@mail.com' , 'www.blog.com' , 'company' ,
770
766
'loc' , True , 'bio' )
771
767
772
- with patch .object (github3 .github .GitHub , 'user' ) as user :
773
- 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 :
774
770
user .return_value = github3 .users .User (load ('user' ), self .g )
775
771
upd .return_value = True
776
772
assert self .g .update_user (* args )
0 commit comments