|
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_ods import get_data, save_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 | eq_(data["Sheet1"], [['repeated', 'repeated', 'repeated', 'repeated']])
|
11 | 13 |
|
12 | 14 |
|
@@ -81,20 +83,53 @@ def test_issue_13():
|
81 | 83 | def test_issue_14():
|
82 | 84 | # pyexcel issue 61
|
83 | 85 | test_file = "issue_61.ods"
|
84 |
| - data = get_data(os.path.join("tests", "fixtures", test_file), |
| 86 | + data = get_data(get_fixtures(test_file), |
85 | 87 | skip_empty_rows=True)
|
86 | 88 | eq_(data['S-LMC'], [[u'aaa'], [0]])
|
87 | 89 |
|
88 | 90 |
|
89 | 91 | def test_issue_6():
|
90 | 92 | 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), |
92 | 94 | skip_empty_rows=True)
|
93 | 95 | eq_(data['Sheet1'][0][0].days, 12)
|
94 | 96 |
|
95 | 97 |
|
96 | 98 | def test_issue_19():
|
97 | 99 | 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), |
99 | 101 | skip_empty_rows=True)
|
100 | 102 | 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