Skip to content

Commit 08301cb

Browse files
committed
fix #5, explicitly seeking at 0 for incoming file handle
1 parent 2ab7b57 commit 08301cb

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

pyexcel_webio/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ def get_params(self, field_name=None, **keywords):
233233
"""
234234
file_type, file_handle = self.get_file_tuple(field_name)
235235
if file_type is not None and file_handle is not None:
236+
file_handle.seek(0)
236237
content = file_handle.read()
237238
if content:
238239
params = {

tests/test_webio.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def tearDown(self):
143143
os.unlink(self.testfile)
144144

145145

146-
class TestExcelInput2:
146+
class TestExcelInputInMultiDict:
147147
def setUp(self):
148148
self.data = [
149149
["X", "Y", "Z"],
@@ -164,12 +164,23 @@ def test_get_sheet(self):
164164
assert sheet.to_array() == self.data
165165
f.close()
166166

167-
@raises(IOError)
168-
def test_get_sheet_in_exception(self):
167+
def test_a_consumed_file_handle(self):
169168
myinput = TestExtendedInput()
170169
f = open(self.testfile, 'rb')
171170
f.read()
171+
sheet = myinput.get_sheet(field_name=('xls', f))
172+
assert sheet.to_array() == self.data
173+
f.close()
174+
175+
@raises(IOError)
176+
def test_get_sheet_in_exception(self):
177+
myinput = TestExtendedInput()
178+
empty_file = 'empty_file'
179+
with open(empty_file, 'w') as f:
180+
f.write('')
181+
f = open(empty_file, 'rb')
172182
myinput.get_sheet(field_name=('xls', f))
183+
os.unlink(empty_file)
173184

174185
@raises(Exception)
175186
def test_wrong_file_tuple_returned(self):

0 commit comments

Comments
 (0)