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

Always close open files in test_multiple_encoder.py #268

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
47 changes: 29 additions & 18 deletions tests/test_multipart_encoder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import contextlib
import unittest
import io

Expand Down Expand Up @@ -233,24 +234,34 @@ def test_regresion_1(self):
"test": "t" * 100
}

for x in range(30):
fields['f%d' % x] = (
'test', open('tests/test_multipart_encoder.py', 'rb')
)

m = MultipartEncoder(fields=fields)
total_size = m.len

blocksize = 8192
read_so_far = 0

while True:
data = m.read(blocksize)
if not data:
break
read_so_far += len(data)

assert read_so_far == total_size
@contextlib.contextmanager
def open_many():
files = []
try:
for x in range(30):
fp = open(__file__, 'rb')
files.append(fp)
fields['f%d' % x] = ('test', fp)
yield
finally:
while files:
fp = files.pop()
fp.close()

with open_many():
m = MultipartEncoder(fields=fields)
total_size = m.len

blocksize = 8192
read_so_far = 0

while True:
data = m.read(blocksize)
if not data:
break
read_so_far += len(data)

assert read_so_far == total_size

def test_regression_2(self):
"""Ensure issue #31 doesn't ever happen again."""
Expand Down