Skip to content
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

Add logic for handling large files in MultipartWriter uploads to s3 #796

Merged
merged 11 commits into from
Feb 22, 2024
35 changes: 22 additions & 13 deletions smart_open/tests/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,21 +456,30 @@ def test_write_02(self):

def test_write_03(self):
"""Does s3 multipart chunking work correctly?"""
# write
smart_open_write = smart_open.s3.MultipartWriter(
BUCKET_NAME, WRITE_KEY_NAME, min_part_size=10
)
with smart_open_write as fout:
fout.write(b"test")
self.assertEqual(fout._buf.tell(), 4)
min_ps = smart_open.s3.MIN_PART_SIZE
max_ps = smart_open.s3.MAX_PART_SIZE

fout.write(b"test\n")
self.assertEqual(fout._buf.tell(), 9)
self.assertEqual(fout._total_parts, 0)
try:
smart_open.s3.MIN_PART_SIZE = 1
smart_open.s3.MAX_PART_SIZE = 100

fout.write(b"test")
self.assertEqual(fout._buf.tell(), 0)
self.assertEqual(fout._total_parts, 1)
smart_open_write = smart_open.s3.MultipartWriter(
BUCKET_NAME, WRITE_KEY_NAME, min_part_size=10
)
with smart_open_write as fout:
fout.write(b"test")
self.assertEqual(fout._buf.tell(), 4)

fout.write(b"test\n")
self.assertEqual(fout._buf.tell(), 9)
self.assertEqual(fout._total_parts, 0)

fout.write(b"test")
self.assertEqual(fout._buf.tell(), 0)
self.assertEqual(fout._total_parts, 1)
finally:
smart_open.s3.MIN_PART_SIZE = min_ps
smart_open.s3.MAX_PART_SIZE = max_ps
mpenkov marked this conversation as resolved.
Show resolved Hide resolved

# read back the same key and check its content
output = list(smart_open.s3.open(BUCKET_NAME, WRITE_KEY_NAME, 'rb'))
Expand Down
Loading