Skip to content

Commit e406430

Browse files
committed
Merge pull request #63 from coaku/feature/b_xzk_fix_windows_test_bug
Feature/b xzk fix windows test bug
2 parents ed3fd3d + 5dc98e7 commit e406430

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

qiniu/io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ def put_file(uptoken, key, localfile, extra=None):
6161
"""
6262
if extra is not None and extra.check_crc == 1:
6363
extra.crc32 = _get_file_crc32(localfile)
64-
with open(localfile) as f:
64+
with open(localfile, 'rb') as f:
6565
return put(uptoken, key, f, extra)
6666

6767

6868
_BLOCK_SIZE = 1024 * 1024 * 4
6969

7070
def _get_file_crc32(filepath):
71-
with open(filepath) as f:
71+
with open(filepath, 'rb') as f:
7272
block = f.read(_BLOCK_SIZE)
7373
crc = 0
7474
while len(block) != 0:

qiniu/test/io_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def test_get_file_crc32(self):
171171
file_path = '%s' % __file__
172172

173173
data = None
174-
with open(file_path) as f:
174+
with open(file_path, 'rb') as f:
175175
data = f.read()
176176
io._BLOCK_SIZE = 4
177177
assert binascii.crc32(data) & 0xFFFFFFFF == io._get_file_crc32(file_path)

qiniu/test/resumable_io_test.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_block(self):
3434
rets = [0, 0]
3535
data_slice_2 = "\nbye!"
3636
ret, err = resumable_io.mkblock(client, len(data_slice_2), data_slice_2)
37-
assert err is None, err
37+
assert err is None, err
3838
self.assertEqual(ret["crc32"], binascii.crc32(data_slice_2))
3939

4040
extra = resumable_io.PutExtra(bucket)
@@ -49,10 +49,11 @@ def test_block(self):
4949
assert err is None, err
5050
self.assertEqual(ret["hash"], "FtCFo0mQugW98uaPYgr54Vb1QsO0", "hash not match")
5151
rs.Client().delete(bucket, key)
52-
52+
5353
def test_put(self):
5454
src = urllib.urlopen("http://cheneya.qiniudn.com/hello_jpg")
55-
dst = tempfile.NamedTemporaryFile()
55+
tmpf = os.tmpnam()
56+
dst = open(tmpf, 'wb')
5657
shutil.copyfileobj(src, dst)
5758
src.close()
5859

@@ -63,11 +64,12 @@ def test_put(self):
6364
localfile = dst.name
6465
ret, err = resumable_io.put_file(policy.token(), key, localfile, extra)
6566
dst.close()
67+
os.remove(tmpf)
6668

6769
assert err is None, err
6870
self.assertEqual(ret["hash"], "FnyTMUqPNRTdk1Wou7oLqDHkBm_p", "hash not match")
6971
rs.Client().delete(bucket, key)
70-
72+
7173

7274
if __name__ == "__main__":
7375
unittest.main()

0 commit comments

Comments
 (0)