1
1
#!/usr/bin/python
2
2
# -*- encoding: utf-8 -*-
3
3
import os
4
+ import psutil
5
+ import pyexcel as pe
4
6
from pyexcel_odsr import get_data
5
7
from nose .tools import raises , eq_
6
8
7
9
8
10
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" ),
10
12
library = 'pyexcel-odsr' )
11
13
eq_ (data ["Sheet1" ], [['repeated' , 'repeated' , 'repeated' , 'repeated' ]])
12
14
@@ -58,14 +60,14 @@ def test_fake_date_time_20():
58
60
def test_issue_14 ():
59
61
# pyexcel issue 61
60
62
test_file = "issue_61.ods"
61
- data = get_data (os . path . join ( "tests" , "fixtures" , test_file ),
63
+ data = get_data (get_fixtures ( test_file ),
62
64
skip_empty_rows = True , library = 'pyexcel-odsr' )
63
65
eq_ (data ['S-LMC' ], [[u'aaa' ], [0 ]])
64
66
65
67
66
68
def test_issue_1 ():
67
69
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 ),
69
71
skip_empty_rows = True , library = 'pyexcel-odsr' )
70
72
eq_ (data ['Sheet1' ][0 ][0 ].days , 12 )
71
73
@@ -78,6 +80,39 @@ def test_issue_1_error():
78
80
79
81
def test_issue_2 ():
80
82
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 ),
82
84
skip_empty_rows = True , library = 'pyexcel-odsr' )
83
85
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