3
3
import os
4
4
5
5
import psutil
6
+ import pytest
6
7
import pyexcel as pe
7
8
from pyexcel_ods import get_data , save_data
8
9
from pyexcel_io .exceptions import IntegerAccuracyLossError
9
10
10
- from nose import SkipTest
11
- from nose .tools import eq_ , raises
12
-
13
11
IN_TRAVIS = "TRAVIS" in os .environ
14
12
15
13
16
14
def test_bug_fix_for_issue_1 ():
17
15
data = get_data (get_fixtures ("repeated.ods" ))
18
- eq_ ( data ["Sheet1" ], [["repeated" , "repeated" , "repeated" , "repeated" ]])
16
+ assert data ["Sheet1" ] == [["repeated" , "repeated" , "repeated" , "repeated" ]]
19
17
20
18
21
19
def test_bug_fix_for_issue_2 ():
22
20
data = {}
23
21
data .update ({"Sheet 1" : [[1 , 2 , 3 ], [4 , 5 , 6 ]]})
24
- data .update ({"Sheet 2" : [[u "row 1" , u "Héllô!" , u "HolÁ!" ]]})
22
+ data .update ({"Sheet 2" : [["row 1" , "Héllô!" , "HolÁ!" ]]})
25
23
save_data ("your_file.ods" , data )
26
24
new_data = get_data ("your_file.ods" )
27
- assert new_data ["Sheet 2" ] == [[u "row 1" , u "H\xe9 ll\xf4 !" , u "Hol\xc1 !" ]]
25
+ assert new_data ["Sheet 2" ] == [["row 1" , "H\xe9 ll\xf4 !" , "Hol\xc1 !" ]]
28
26
29
27
30
- @raises (Exception )
31
28
def test_invalid_date ():
32
- from pyexcel_ods .ods import date_value
33
-
34
- value = "2015-08-"
35
- date_value (value )
29
+ with pytest .raises (Exception ):
30
+ from pyexcel_ods .ods import date_value
36
31
32
+ value = "2015-08-"
33
+ date_value (value )
37
34
38
- @raises (Exception )
39
- def test_fake_date_time_10 ():
40
- from pyexcel_ods .ods import date_value
35
+ with pytest .raises (Exception ):
36
+ from pyexcel_ods .ods import date_value
41
37
42
- date_value ("1234567890" )
38
+ date_value ("1234567890" )
43
39
44
40
45
- @raises (Exception )
46
41
def test_fake_date_time_19 ():
47
- from pyexcel_ods .ods import date_value
42
+ with pytest .raises (Exception ):
43
+ from pyexcel_ods .ods import date_value
48
44
49
- date_value ("1234567890123456789" )
45
+ date_value ("1234567890123456789" )
50
46
51
47
52
- @raises (Exception )
53
48
def test_fake_date_time_20 ():
54
- from pyexcel_ods .ods import date_value
49
+ with pytest .raises (Exception ):
50
+ from pyexcel_ods .ods import date_value
55
51
56
- date_value ("12345678901234567890" )
52
+ date_value ("12345678901234567890" )
57
53
58
54
59
55
def test_issue_13 ():
60
56
test_file = "test_issue_13.ods"
61
57
data = [[1 , 2 ], [], [], [], [3 , 4 ]]
62
58
save_data (test_file , {test_file : data })
63
59
written_data = get_data (test_file , skip_empty_rows = False )
64
- eq_ ( data , written_data [test_file ])
60
+ assert data == written_data [test_file ]
65
61
os .unlink (test_file )
66
62
67
63
68
64
def test_issue_14 ():
69
65
# pyexcel issue 61
70
66
test_file = "issue_61.ods"
71
67
data = get_data (get_fixtures (test_file ), skip_empty_rows = True )
72
- eq_ ( data ["S-LMC" ], [[ u "aaa" ], [0 ]])
68
+ assert data ["S-LMC" ] == [[ "aaa" ], [0 ]]
73
69
74
70
75
71
def test_issue_6 ():
76
72
test_file = "12_day_as_time.ods"
77
73
data = get_data (get_fixtures (test_file ), skip_empty_rows = True )
78
- eq_ ( data ["Sheet1" ][0 ][0 ].days , 12 )
74
+ assert data ["Sheet1" ][0 ][0 ].days == 12
79
75
80
76
81
77
def test_issue_19 ():
82
78
test_file = "pyexcel_81_ods_19.ods"
83
79
data = get_data (get_fixtures (test_file ), skip_empty_rows = True )
84
- eq_ ( data ["product.template" ][1 ][1 ], "PRODUCT NAME PMP" )
80
+ assert data ["product.template" ][1 ][1 ] == "PRODUCT NAME PMP"
85
81
86
82
87
83
def test_issue_83_ods_file_handle ():
@@ -110,18 +106,20 @@ def test_issue_83_ods_file_handle():
110
106
pe .free_resources ()
111
107
open_files_l4 = proc .open_files ()
112
108
# this confirms that no more open file handle
113
- eq_ ( open_files_l1 , open_files_l4 )
109
+ assert open_files_l1 == open_files_l4
114
110
115
111
116
112
def test_pr_22 ():
117
113
test_file = get_fixtures ("white_space.ods" )
118
114
data = get_data (test_file )
119
- eq_ (data ["Sheet1" ][0 ][0 ], "paragraph with tab(\t ), space, \n new line" )
115
+ assert (
116
+ data ["Sheet1" ][0 ][0 ] == "paragraph with tab(\t ), space, \n new line"
117
+ )
120
118
121
119
122
120
def test_issue_23 ():
123
121
if not IN_TRAVIS :
124
- raise SkipTest ( )
122
+ pytest . skip ( "Need to be in Travis CI to run this test." )
125
123
pe .get_book (
126
124
url = (
127
125
"https://github.com/pyexcel/pyexcel-ods/"
@@ -133,13 +131,13 @@ def test_issue_23():
133
131
def test_issue_24 ():
134
132
test_file = get_fixtures ("comment-in-cell.ods" )
135
133
data = get_data (test_file )
136
- eq_ ( data ["Sheet1" ], [["test" ]])
134
+ assert data ["Sheet1" ] == [["test" ]]
137
135
138
136
139
137
def test_issue_27 ():
140
138
test_file = get_fixtures ("issue_27.ods" )
141
139
data = get_data (test_file , skip_empty_rows = True )
142
- eq_ ( data ["VGPMX" ], [["" , "Cost Basis" , "0" ]])
140
+ assert data ["VGPMX" ] == [["" , "Cost Basis" , "0" ]]
143
141
144
142
145
143
def test_issue_30 ():
@@ -148,16 +146,16 @@ def test_issue_30():
148
146
sheet [0 , 0 ] = 999999999999999
149
147
sheet .save_as (test_file )
150
148
sheet2 = pe .get_sheet (file_name = test_file )
151
- eq_ ( sheet [0 , 0 ], sheet2 [0 , 0 ])
149
+ assert sheet [0 , 0 ] == sheet2 [0 , 0 ]
152
150
os .unlink (test_file )
153
151
154
152
155
- @raises (IntegerAccuracyLossError )
156
153
def test_issue_30_precision_loss ():
157
- test_file = "issue_30_2.ods"
158
- sheet = pe .Sheet ()
159
- sheet [0 , 0 ] = 9999999999999999
160
- sheet .save_as (test_file )
154
+ with pytest .raises (IntegerAccuracyLossError ):
155
+ test_file = "issue_30_2.ods"
156
+ sheet = pe .Sheet ()
157
+ sheet [0 , 0 ] = 9999999999999999
158
+ sheet .save_as (test_file )
161
159
162
160
163
161
def get_fixtures (filename ):
0 commit comments