<
8000
div class="d-none">
File tree Expand file tree Collapse file tree 5 files changed +48
-9
lines changed Expand file tree Collapse file tree 5 files changed +48
-9
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ language: python
2
2
python :
3
3
- 2.6
4
4
- 2.7
5
+ - 3.1
5
6
- 3.2
6
7
- pypy
7
8
# command to install dependencies, e.g. pip install -r requirements.txt
@@ -17,3 +18,7 @@ notifications:
17
18
branches :
18
19
except :
19
20
- uricore
21
+
22
+ matrix :
23
+ allow_failures :
24
+ - python : 3.1
Original file line number Diff line number Diff line change 8
8
9
9
from base64 import b64decode
10
10
from requests import post
11
+ from collections import Callable
11
12
from github3 .events import Event
12
13
from github3 .issues import Issue , IssueEvent , Label , Milestone , issue_params
13
14
from github3 .git import Blob , Commit , Reference , Tag , Tree
@@ -158,12 +159,12 @@ def archive(self, format, path='', ref='master'):
158
159
url = self ._build_url (format , ref , base_url = self ._api )
159
160
resp = self ._get (url , allow_redirects = True , prefetch = False )
160
161
161
- fd = None
162
- file_like = False
163
- if resp and resp . ok :
162
+ pre_opened = False
163
+ if resp and self . _boolean ( resp , 200 , 404 ):
164
+ fd = None
164
165
if path :
165
- if callable (getattr (path , 'write' , None )):
166
- file_like = True
166
+ if isinstance (getattr (path , 'write' , None ), Callable ):
167
+ pre_opened = True
167
168
fd = path
168
169
else :
169
170
fd = open (path , 'wb' )
@@ -174,7 +175,7 @@ def archive(self, format, path='', ref='master'):
174
175
for chunk in resp .iter_content ():
175
176
fd .write (chunk )
176
177
177
- if not file_like :
178
+ if not pre_opened :
178
179
fd .close ()
179
180
180
181
written = True
@@ -1411,7 +1412,7 @@ def saveas(self, path=''):
1411
1412
1412
1413
resp = self ._get (self .html_url , allow_redirects = True , prefetch = False )
1413
1414
if self ._boolean (resp , 200 , 404 ):
1414
- if callable (getattr (path , 'write' , None )):
1415
+ if isinstance (getattr (path , 'write' , None ), Callable ):
1415
1416
file_like = True
1416
1417
fd = path
1417
1418
else :
Original file line number Diff line number Diff line change
1
+ archive_data
Original file line number Diff line number Diff line change
1
+ import os
1
2
import github3
2
3
from tests .utils import (generate_response , expect , BaseCase , load )
3
4
@@ -26,7 +27,34 @@ def test_add_collaborator(self):
26
27
self .mock_assertions ()
27
28
28
29
def test_archive (self ):
29
- pass
30
+ headers = {'content-disposition' : 'filename=foo' }
31
+ self .request .return_value = generate_response ('archive' , 200 ,
32
+ ** headers )
33
+ self .args = ('get' , self .api + 'tarball/master' )
34
+ self .conf .update ({'prefetch' : False })
35
+
36
+ expect (self .repo .archive (None )).is_False ()
37
+
38
+ expect (os .path .isfile ('foo' )).is_False ()
39
+ expect (self .repo .archive ('tarball' )).is_True ()
40
+ expect (os .path .isfile ('foo' )).is_True ()
41
+ os .unlink ('foo' )
42
+ self .mock_assertions ()
43
+
44
+ self .request .return_value .raw .seek (0 )
45
+ self .request .return_value ._content_consumed = False
46
+
47
+ expect (os .path .isfile ('path_to_file' )).is_False ()
48
+ expect (self .repo .archive ('tarball' , 'path_to_file' )).is_True ()
49
+ expect (os .path .isfile ('path_to_file' )).is_True ()
50
+ os .unlink ('path_to_file' )
51
+
52
+ self .request .return_value .raw .seek (0 )
53
+ self .request .return_value ._content_consumed = False
54
+
55
+ self .args = ('get' , self .api + 'zipball/randomref' )
56
+ expect (self .repo .archive ('zipball' , ref = 'randomref' )).is_True ()
57
+ os .unlink ('foo' )
30
58
31
59
def test_blob (self ):
32
60
self .request .return_value = generate_response ('blob' )
Original file line number Diff line number Diff line change 2
2
import github3
3
3
import expecter
4
4
import json
5
+ import sys
5
6
from mock import patch , call
6
7
from io import BytesIO
7
8
from unittest import TestCase
@@ -17,7 +18,10 @@ def generate_response(path_name, status_code=200, enc='utf-8', _iter=False,
17
18
if _iter :
18
19
content = path (path_name ).read ().strip ()
19
20
content = '[{0}]' .format (content )
20
- r .raw = BytesIO (content .encode ('utf-8' ))
21
+ r .raw = BytesIO (content .encode ())
22
+ elif sys .version_info > (3 , 0 ):
23
+ content = path (path_name ).read ().strip ()
24
+ r .raw = BytesIO (content .encode ())
21
25
else :
22
26
r .raw = path (path_name )
23
27
else :
0 commit comments