Skip to content

Commit a435913

Browse files
committed
test and verify the xlsx file handle is really closed #14
1 parent 76499a6 commit a435913

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

Diff for: tests/test_bug_fixes.py

+42
Original file line numberDiff line numberDiff line change
@@ -136,5 +136,47 @@ def test_issue_8_hidden_sheet_2():
136136
eq_(book_dict['hidden'], [['a', 'b']])
137137

138138

139+
def test_issue_14_xlsx_file_handle():
140+
proc = psutil.Process()
141+
test_file = os.path.join("tests", "fixtures", "hidden_sheets.xlsx")
142+
open_files_l1 = proc.open_files()
143+
144+
# start with a csv file
145+
data = pe.iget_array(file_name=test_file, library='pyexcel-xlsx')
146+
open_files_l2 = proc.open_files()
147+
delta = len(open_files_l2) - len(open_files_l1)
148+
# interestingly, file is already open :)
149+
assert delta == 1
150+
151+
# now the file handle get opened when we run through
152+
# the generator
153+
list(data)
154+
open_files_l3 = proc.open_files()
155+
delta = len(open_files_l3) - len(open_files_l1)
156+
# caught an open file handle, the "fish" finally
157+
assert delta == 1
158+
159+
# free the fish
160+
pe.free_resource()
161+
open_files_l4 = proc.open_files()
162+
# this confirms that no more open file handle
163+
eq_(open_files_l1, open_files_l4)
164+
165+
166+
def test_issue_83_file_handle_no_generator():
167+
proc = psutil.Process()
168+
test_files = [
169+
os.path.join("tests", "fixtures", "hidden_sheets.xlsx")
170+
]
171+
for test_file in test_files:
172+
open_files_l1 = proc.open_files()
173+
# start with a csv file
174+
pe.get_array(file_name=test_file)
175+
open_files_l2 = proc.open_files()
176+
delta = len(open_files_l2) - len(open_files_l1)
177+
# no open file handle should be left
178+
assert delta == 0
179+
180+
139181
def get_fixtures(file_name):
140182
return os.path.join("tests", "fixtures", file_name)

0 commit comments

Comments
 (0)