|
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 nose.tools import raises, eq_
|
5 | 7 |
|
6 | 8 |
|
@@ -92,3 +94,36 @@ def test_issue_8_1():
|
92 | 94 | from pyexcel_ods3.converter import time_value
|
93 | 95 | result = time_value('PT1111')
|
94 | 96 | 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