18
18
from pandas .util .misc import is_little_endian
19
19
import pandas
20
20
21
- class TestPickle (tm .TestCase ):
21
+ class TestPickle ():
22
+ """
23
+ How to add pickle tests:
24
+
25
+ 1. Install pandas version intended to output the pickle.
26
+
27
+ 2. Execute "generate_legacy_pkcles.py" to create the pickle.
28
+ $ python generate_legacy_pickles.py <version> <output_dir>
29
+
30
+ 3. Move the created pickle to "data/legacy_pickle/<version>" directory.
31
+
32
+ NOTE: TestPickle can't be a subclass of tm.Testcase to use test generator.
33
+ http://stackoverflow.com/questions/6689537/nose-test-generators-inside-class
34
+ """
22
35
_multiprocess_can_split_ = True
23
36
24
37
def setUp (self ):
@@ -28,7 +41,7 @@ def setUp(self):
28
41
29
42
def compare_element (self , typ , result , expected ):
30
43
if isinstance (expected ,Index ):
31
- self . assertTrue (expected . equals ( result ) )
44
+ tm . assert_index_equal (expected , result )
32
45
return
33
46
34
47
if typ .startswith ('sp_' ):
@@ -65,8 +78,9 @@ def read_pickles(self, version):
65
78
raise nose .SkipTest ("known failure on non-little endian" )
66
79
67
80
pth = tm .get_data_path ('legacy_pickle/{0}' .format (str (version )))
81
+ n = 0
68
82
for f in os .listdir (pth ):
69
- vf = os .path .join (pth ,f )
83
+ vf = os .path .join (pth , f )
70
84
data = self .compare (vf )
71
85
72
86
if data is None :
@@ -76,21 +90,18 @@ def read_pickles(self, version):
76
90
if 'ts' in data ['series' ]:
77
91
self ._validate_timeseries (data ['series' ]['ts' ], self .data ['series' ]['ts' ])
78
92
self ._validate_frequency (data ['series' ]['ts' ])
79
-
80
- def test_read_pickles_0_10_1 (self ):
81
- self .read_pickles ('0.10.1' )
82
-
83
- def test_read_pickles_0_11_0 (self ):
84
- self .read_pickles ('0.11.0' )
85
-
86
- def test_read_pickles_0_12_0 (self ):
87
- self .read_pickles ('0.12.0' )
88
-
89
- def test_read_pickles_0_13_0 (self ):
90
- self .read_pickles ('0.13.0' )
91
-
92
- def test_read_pickles_0_14_0 (self ):
93
- self .read_pickles ('0.14.0' )
93
+ n += 1
94
+ assert n > 0 , 'Pickle files are not tested'
95
+
96
+ def test_pickles (self ):
97
+ pickle_path = tm .get_data_path ('legacy_pickle' )
98
+ n = 0
99
+ for v in os .listdir (pickle_path ):
100
+ pth = os .path .join (pickle_path , v )
101
+ if os .path .isdir (pth ):
102
+ yield self .read_pickles , v
103
+ n += 1
104
+ assert n > 0 , 'Pickle files are not tested'
94
105
95
106
def test_round_trip_current (self ):
96
107
@@ -145,24 +156,24 @@ def python_unpickler(path):
145
156
def _validate_timeseries (self , pickled , current ):
146
157
# GH 7748
147
158
tm .assert_series_equal (pickled , current )
148
- self . assertEqual (pickled .index .freq , current .index .freq )
149
- self . assertEqual (pickled .index .freq .normalize , False )
150
- self .assert_numpy_array_equal (pickled > 0 , current > 0 )
159
+ tm . assert_equal (pickled .index .freq , current .index .freq )
160
+ tm . assert_equal (pickled .index .freq .normalize , False )
161
+ tm .assert_numpy_array_equal (pickled > 0 , current > 0 )
151
162
152
163
def _validate_frequency (self , pickled ):
153
164
# GH 9291
154
165
from pandas .tseries .offsets import Day
155
166
freq = pickled .index .freq
156
167
result = freq + Day (1 )
157
- self . assertTrue (result , Day (2 ))
168
+ tm . assert_equal (result , Day (2 ))
158
169
159
170
result = freq + pandas .Timedelta (hours = 1 )
160
- self . assertTrue (isinstance (result , pandas .Timedelta ))
161
- self . assertEqual (result , pandas .Timedelta (days = 1 , hours = 1 ))
171
+ tm . assert_equal (isinstance (result , pandas .Timedelta ), True )
172
+ tm . assert_equal (result , pandas .Timedelta (days = 1 , hours = 1 ))
162
173
163
174
result = freq + pandas .Timedelta (nanoseconds = 1 )
164
- self . assertTrue (isinstance (result , pandas .Timedelta ))
165
- self . assertEqual (result , pandas .Timedelta (days = 1 , nanoseconds = 1 ))
175
+ tm . assert_equal (isinstance (result , pandas .Timedelta ), True )
176
+ tm . assert_equal (result , pandas .Timedelta (days = 1 , nanoseconds = 1 ))
166
177
167
178
168
179
if __name__ == '__main__' :
0 commit comments