Skip to content

Commit 4c35d8f

Browse files
committed
verify odfpy does close file handle, pyexcel/pyexcel-xlsx#14
1 parent 8635232 commit 4c35d8f

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

tests/test_bug_fixes.py

+39-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#!/usr/bin/python
22
# -*- encoding: utf-8 -*-
33
import os
4+
import psutil
5+
import pyexcel as pe
46
from pyexcel_ods import get_data, save_data
57
from nose.tools import raises, eq_
68

79

810
def test_bug_fix_for_issue_1():
9-
data = get_data(os.path.join("tests", "fixtures", "repeated.ods"))
11+
data = get_data(get_fixtures("repeated.ods"))
1012
eq_(data["Sheet1"], [['repeated', 'repeated', 'repeated', 'repeated']])
1113

1214

@@ -81,20 +83,53 @@ def test_issue_13():
8183
def test_issue_14():
8284
# pyexcel issue 61
8385
test_file = "issue_61.ods"
84-
data = get_data(os.path.join("tests", "fixtures", test_file),
86+
data = get_data(get_fixtures(test_file),
8587
skip_empty_rows=True)
8688
eq_(data['S-LMC'], [[u'aaa'], [0]])
8789

8890

8991
def test_issue_6():
9092
test_file = "12_day_as_time.ods"
91-
data = get_data(os.path.join("tests", "fixtures", test_file),
93+
data = get_data(get_fixtures(test_file),
9294
skip_empty_rows=True)
9395
eq_(data['Sheet1'][0][0].days, 12)
9496

9597

9698
def test_issue_19():
9799
test_file = "pyexcel_81_ods_19.ods"
98-
data = get_data(os.path.join("tests", "fixtures", test_file),
100+
data = get_data(get_fixtures(test_file),
99101
skip_empty_rows=True)
100102
eq_(data['product.template'][1][1], 'PRODUCT NAME PMP')
103+
104+
105+
def test_issue_83_ods_file_handle():
106+
# this proves that odfpy
107+
# does not leave a file handle open at all
108+
proc = psutil.Process()
109+
test_file = get_fixtures("issue_61.ods")
110+
open_files_l1 = proc.open_files()
111+
112+
# start with a csv file
113+
data = pe.iget_array(file_name=test_file)
114+
open_files_l2 = proc.open_files()
115+
delta = len(open_files_l2) - len(open_files_l1)
116+
# cannot catch open file handle
117+
assert delta == 0
118+
119+
# now the file handle get opened when we run through
120+
# the generator
121+
list(data)
122+
open_files_l3 = proc.open_files()
123+
delta = len(open_files_l3) - len(open_files_l1)
124+
# cannot catch open file handle
125+
assert delta == 0
126+
127+
# free the fish
128+
pe.free_resource()
129+
open_files_l4 = proc.open_files()
130+
# this confirms that no more open file handle
131+
eq_(open_files_l1, open_files_l4)
132+
133+
134+
def get_fixtures(filename):
135+
return os.path.join("tests", "fixtures", filename)

0 commit comments

Comments
 (0)