Пример #1
0
def test_get_put(s3):
    with tmpfile() as fn:
        s3.get(test_bucket_name+'/test/accounts.1.json', fn)
        data = files['test/accounts.1.json']
        assert open(fn, 'rb').read() == data
        s3.put(fn, test_bucket_name+'/temp')
        assert s3.du(test_bucket_name+'/temp')[test_bucket_name+'/temp'] == len(data)
        assert s3.cat(test_bucket_name+'/temp') == data
Пример #2
0
def test_get_put(s3):
    with tmpfile() as fn:
        s3.get(test_bucket_name+'/test/accounts.1.json', fn)
        data = files['test/accounts.1.json']
        assert open(fn, 'rb').read() == data
        s3.put(fn, test_bucket_name+'/temp')
        assert s3.du(test_bucket_name+'/temp')[test_bucket_name+'/temp'] == len(data)
        assert s3.cat(test_bucket_name+'/temp') == data
Пример #3
0
def test_multipart_upload_blocksize(s3):
    blocksize = 5 * (2 ** 20)
    expected_parts = 3
    with tmpfile() as fn:
        # Create a tempfile of size `3 * blocksize`
        with open(fn, 'wb') as f:
            f.write(b'b' * expected_parts * blocksize)

        # Write the file in chunks of size `blocksize`
        # This is the same as `S3FileSystem.put`, but `put` doesn't give
        # access to the S3File for testing
        with open(fn, 'rb') as f:
            with s3.open(a, 'wb', block_size=blocksize) as s3f:
                while True:
                    data = f.read(blocksize)
                    if len(data) == 0:
                        break
                    s3f.write(data)

        # Ensure that the multipart upload consists of only 3 parts
        assert len(s3f.parts) == expected_parts
Пример #4
0
def test_tempfile():
    with tmpfile() as fn:
        with open(fn, 'w'):
            pass
        assert os.path.exists(fn)
    assert not os.path.exists(fn)
Пример #5
0
def test_tempfile():
    with tmpfile() as fn:
        with open(fn, 'w'):
            pass
        assert os.path.exists(fn)
    assert not os.path.exists(fn)