Skip to content

Feature/b xzk fix windows test bug #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 1, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions qiniu/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ def put_file(uptoken, key, localfile, extra=None):
"""
if extra is not None and extra.check_crc == 1:
extra.crc32 = _get_file_crc32(localfile)
with open(localfile) as f:
with open(localfile, 'rb') as f:
return put(uptoken, key, f, extra)


_BLOCK_SIZE = 1024 * 1024 * 4

def _get_file_crc32(filepath):
with open(filepath) as f:
with open(filepath, 'rb') as f:
block = f.read(_BLOCK_SIZE)
crc = 0
while len(block) != 0:
Expand Down
2 changes: 1 addition & 1 deletion qiniu/test/io_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def test_get_file_crc32(self):
file_path = '%s' % __file__

data = None
with open(file_path) as f:
with open(file_path, 'rb') as f:
data = f.read()
io._BLOCK_SIZE = 4
assert binascii.crc32(data) & 0xFFFFFFFF == io._get_file_crc32(file_path)
Expand Down
10 changes: 6 additions & 4 deletions qiniu/test/resumable_io_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_block(self):
rets = [0, 0]
data_slice_2 = "\nbye!"
ret, err = resumable_io.mkblock(client, len(data_slice_2), data_slice_2)
assert err is None, err
assert err is None, err
self.assertEqual(ret["crc32"], binascii.crc32(data_slice_2))

extra = resumable_io.PutExtra(bucket)
Expand All @@ -49,10 +49,11 @@ def test_block(self):
assert err is None, err
self.assertEqual(ret["hash"], "FtCFo0mQugW98uaPYgr54Vb1QsO0", "hash not match")
rs.Client().delete(bucket, key)

def test_put(self):
src = urllib.urlopen("http://cheneya.qiniudn.com/hello_jpg")
dst = tempfile.NamedTemporaryFile()
tmpf = os.tmpnam()
dst = open(tmpf, 'wb')
shutil.copyfileobj(src, dst)
src.close()

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

assert err is None, err
self.assertEqual(ret["hash"], "FnyTMUqPNRTdk1Wou7oLqDHkBm_p", "hash not match")
rs.Client().delete(bucket, key)


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