Skip to content

Commit fccfc27

Browse files
committed
make sure pyexcel-odsr close ods file, pyexcel/pyexcel-xlsx#14
1 parent 37f2c33 commit fccfc27

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

Diff for: 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_odsr import get_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
library='pyexcel-odsr')
1113
eq_(data["Sheet1"], [['repeated', 'repeated', 'repeated', 'repeated']])
1214

@@ -58,14 +60,14 @@ def test_fake_date_time_20():
5860
def test_issue_14():
5961
# pyexcel issue 61
6062
test_file = "issue_61.ods"
61-
data = get_data(os.path.join("tests", "fixtures", test_file),
63+
data = get_data(get_fixtures(test_file),
6264
skip_empty_rows=True, library='pyexcel-odsr')
6365
eq_(data['S-LMC'], [[u'aaa'], [0]])
6466

6567

6668
def test_issue_1():
6769
test_file = "12_day_as_time.ods"
68-
data = get_data(os.path.join("tests", "fixtures", test_file),
70+
data = get_data(get_fixtures(test_file),
6971
skip_empty_rows=True, library='pyexcel-odsr')
7072
eq_(data['Sheet1'][0][0].days, 12)
7173

@@ -78,6 +80,39 @@ def test_issue_1_error():
7880

7981
def test_issue_2():
8082
test_file = "multinode-in-a-p.ods"
81-
data = get_data(os.path.join("tests", "fixtures", test_file),
83+
data = get_data(get_fixtures(test_file),
8284
skip_empty_rows=True, library='pyexcel-odsr')
8385
eq_(data['product.template'][1][1], 'PRODUCT NAME PMP')
86+
87+
88+
def test_issue_83_ods_file_handle():
89+
# this proves that odfpy
90+
# does not leave a file handle open at all
91+
proc = psutil.Process()
92+
test_file = get_fixtures("multinode-in-a-p.ods")
93+
open_files_l1 = proc.open_files()
94+
95+
# start with a csv file
96+
data = pe.iget_array(file_name=test_file, library='pyexcel-odsr')
97+
open_files_l2 = proc.open_files()
98+
delta = len(open_files_l2) - len(open_files_l1)
99+
# cannot catch open file handle
100+
assert delta == 0
101+
102+
# now the file handle get opened when we run through
103+
# the generator
104+
list(data)
105+
open_files_l3 = proc.open_files()
106+
delta = len(open_files_l3) - len(open_files_l1)
107+
# cannot catch open file handle
108+
assert delta == 0
109+
110+
# free the fish
111+
pe.free_resource()
112+
open_files_l4 = proc.open_files()
113+
# this confirms that no more open file handle
114+
eq_(open_files_l1, open_files_l4)
115+
116+
117+
def get_fixtures(filename):
118+
return os.path.join("tests", "fixtures", filename)

0 commit comments

Comments
 (0)