7
# from numarray import *
9
# import numarray.records as records
10
4
from tables import *
12
from test_all import verbose
7
from test_all import verbose, cleanup, allequal
8
# To delete the internal attributes automagically
9
unittest.TestCase.tearDown = cleanup
14
11
# Check read Tables from pytables version 0.5 (ucl-nrv2e), and 0.7 (ucl-nvr2d)
15
class BackCompatTestCase(unittest.TestCase):
12
class BackCompatTablesTestCase(unittest.TestCase):
17
14
#----------------------------------------
19
16
def test01_readTable(self):
20
"""Checking backward compatibility of old formats"""
17
"""Checking backward compatibility of old formats of tables"""
23
20
print '\n', '-=' * 30
24
21
print "Running %s.test01_readTable..." % self.__class__.__name__
26
23
# Create an instance of an HDF5 Table
24
warnings.filterwarnings("ignore", category=UserWarning)
27
25
self.fileh = openFile(self.file, "r")
26
warnings.filterwarnings("default", category=UserWarning)
28
28
table = self.fileh.getNode("/tuple0")
30
30
# Read the 100 records
35
35
print "Total selected records in table ==> ", len(result)
37
37
assert len(result) == 100
39
class Table1_0UCL(BackCompatTestCase):
40
class Table1_0UCL(BackCompatTablesTestCase):
40
41
file = "Table1_0_ucl_nrv2e.h5" # pytables 0.5.1 and before
42
class Table2_0UCL(BackCompatTestCase):
43
class Table2_0UCL(BackCompatTablesTestCase):
43
44
file = "Table2_0_ucl_nrv2d.h5" # pytables 0.7.x versions
45
class Table2_1UCL(BackCompatTestCase):
46
class Table2_1UCL(BackCompatTablesTestCase):
46
47
file = "Table2_1_ucl_nrv2e_shuffle.h5" # pytables 0.8.x versions and after
49
class Tables_LZO1(BackCompatTablesTestCase):
50
file = "Tables_lzo1.h5" # files compressed with LZO1
52
class Tables_LZO1_shuffle(BackCompatTablesTestCase):
53
file = "Tables_lzo1_shuffle.h5" # files compressed with LZO1 and shuffle
55
class Tables_LZO2(BackCompatTablesTestCase):
56
file = "Tables_lzo2.h5" # files compressed with LZO2
58
class Tables_LZO2_shuffle(BackCompatTablesTestCase):
59
file = "Tables_lzo2_shuffle.h5" # files compressed with LZO2 and shuffle
61
# Check read attributes from PyTables >= 1.0 properly
62
class BackCompatAttrsTestCase(unittest.TestCase):
63
file = "zerodim-attrs-%s.h5"
65
def test01_readAttr(self):
66
"""Checking backward compatibility of old formats for attributes"""
70
print "Running %s.test01_readAttr..." % self.__class__.__name__
73
self.fileh = openFile(self.file % self.format, "r")
74
a = self.fileh.getNode("/a")
75
scalar = numarray.array(1, type="Int32")
76
vector = numarray.array([1], type="Int32")
77
if self.format == "1.3":
78
assert allequal(a.attrs.arrdim1, vector)
79
assert allequal(a.attrs.arrscalar, scalar)
80
assert a.attrs.pythonscalar == 1
81
elif self.format == "1.4":
82
assert allequal(a.attrs.arrdim1, vector)
83
assert allequal(a.attrs.arrscalar, scalar)
84
assert allequal(a.attrs.pythonscalar, scalar)
88
class Attrs_1_3(BackCompatAttrsTestCase):
89
format = "1.3" # pytables 1.0.x versions and earlier
91
class Attrs_1_4(BackCompatAttrsTestCase):
92
format = "1.4" # pytables 1.1.x versions and later
49
95
#----------------------------------------------------------------------
56
102
#theSuite.addTest(unittest.makeSuite(Table2_0UCL))
57
103
#theSuite.addTest(unittest.makeSuite(Table2_1UCL))
59
ucl_avail = whichLibVersion("ucl")[0]
105
ucl_avail = whichLibVersion("ucl") is not None
60
106
for n in range(niter):
62
108
theSuite.addTest(unittest.makeSuite(Table1_0UCL))
63
109
theSuite.addTest(unittest.makeSuite(Table2_0UCL))
64
110
theSuite.addTest(unittest.makeSuite(Table2_1UCL))
111
theSuite.addTest(unittest.makeSuite(Tables_LZO1))
112
theSuite.addTest(unittest.makeSuite(Tables_LZO1_shuffle))
113
theSuite.addTest(unittest.makeSuite(Tables_LZO2))
114
theSuite.addTest(unittest.makeSuite(Tables_LZO2_shuffle))
115
theSuite.addTest(unittest.makeSuite(Attrs_1_3))
116
theSuite.addTest(unittest.makeSuite(Attrs_1_4))