def test_copy_same_flags(mocked_s3, mocker): """Should open the files with equal settings if the client differs but the flags are the same.""" mocked_s3[0].s3fs.touch("BUCKET/a/b.csv") spies = [mocker.spy(client, "open") for client in mocked_s3] transfer.copy([S3File(client, "a/b.csv") for client in mocked_s3]) spies[0].assert_called_once_with("a/b.csv", "rb") spies[1].assert_called_once_with("a/b.csv", "wb")
def test_copy_same_client(mocked_s3, mocker): """Should use client.copy when the clients are the same.""" mocked_s3[0].s3fs.touch("BUCKET/a/b.csv") spies_copy = [mocker.spy(client, "copy") for client in mocked_s3] spies_open = [mocker.spy(client, "open") for client in mocked_s3] transfer.copy([S3File(client, "a/b.csv") for client in mocked_s3]) [spy.assert_not_called() for spy in spies_open] spies_copy[0].assert_called_once_with("a/b.csv", "a/b.csv") spies_copy[1].assert_not_called()
def test_copy_different_clients(mocked_s3, mocker): """Should pass on flags if the client flags differ.""" mocked_s3[0].s3fs.touch("BUCKET/a/b.csv.gz") spies = [mocker.spy(client, "open") for client in mocked_s3] files = [ S3File(mocked_s3[0], "a/b.csv.gz"), S3File(mocked_s3[1], "a/b.csv") ] transfer.copy(files) spies[0].assert_called_once_with("a/b.csv.gz", "rb", unpack=True) spies[1].assert_called_once_with("a/b.csv", "wb")
def test_copy_same_client(mocked_s3, mocker): """Should use client.copy when the clients are the same.""" mocked_s3[0].s3c.put_object(Bucket='BUCKET', Key='a/b.csv', Body='foo') spies_copy = [mocker.spy(client, "copy") for client in mocked_s3] spies_open = [mocker.spy(client, "open") for client in mocked_s3] transfer.copy([S3File(client, "a/b.csv") for client in mocked_s3]) [spy.assert_not_called() for spy in spies_open] spies_copy[0].assert_called_once_with("BUCKET", "a/b.csv", "BUCKET", "a/b.csv") spies_copy[1].assert_not_called()