Skip to content

Commit 28bb779

Browse files
committed
make sure ods3 close ods file, pyexcel/pyexcel-xlsx#14
1 parent c4fc421 commit 28bb779

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/test_bug_fixes.py

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

68

@@ -92,3 +94,36 @@ def test_issue_8_1():
9294
from pyexcel_ods3.converter import time_value
9395
result = time_value('PT1111')
9496
eq_(result, None)
97+
98+
99+
def test_issue_83_ods_file_handle():
100+
# this proves that odfpy
101+
# does not leave a file handle open at all
102+
proc = psutil.Process()
103+
test_file = get_fixtures("12_day_as_time.ods")
104+
open_files_l1 = proc.open_files()
105+
106+
# start with a csv file
107+
data = pe.iget_array(file_name=test_file, library='pyexcel-ods3')
108+
open_files_l2 = proc.open_files()
109+
delta = len(open_files_l2) - len(open_files_l1)
110+
# cannot catch open file handle
111+
assert delta == 0
112+
113+
# now the file handle get opened when we run through
114+
# the generator
115+
list(data)
116+
open_files_l3 = proc.open_files()
117+
delta = len(open_files_l3) - len(open_files_l1)
118+
# cannot catch open file handle
119+
assert delta == 0
120+
121+
# free the fish
122+
pe.free_resource()
123+
open_files_l4 = proc.open_files()
124+
# this confirms that no more open file handle
125+
eq_(open_files_l1, open_files_l4)
126+
127+
128+
def get_fixtures(filename):
129+
return os.path.join("tests", "fixtures", filename)

0 commit comments

Comments
 (0)