~ubuntu-branches/ubuntu/quantal/pytables/quantal

« back to all changes in this revision

Viewing changes to test/test_backcompat.py

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2005-11-27 20:25:34 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20051127202534-l8jzyd8357krw40h
Tags: 1.1.1-1ubuntu1
* Sync with Debian:
  + Use python 2.4 as default

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#import sys
 
2
import warnings
2
3
import unittest
3
 
#import os
4
 
#import tempfile
5
 
 
6
 
# import numarray
7
 
# from numarray import *
8
 
# #import recarray
9
 
# import numarray.records as records
10
4
from tables import *
 
5
import numarray
11
6
 
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
13
10
 
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):
16
13
 
17
14
    #----------------------------------------
18
15
 
19
16
    def test01_readTable(self):
20
 
        """Checking backward compatibility of old formats"""
 
17
        """Checking backward compatibility of old formats of tables"""
21
18
 
22
19
        if verbose:
23
20
            print '\n', '-=' * 30
24
21
            print "Running %s.test01_readTable..." % self.__class__.__name__
25
22
 
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)
 
27
 
28
28
        table = self.fileh.getNode("/tuple0")
29
29
 
30
30
        # Read the 100 records
35
35
            print "Total selected records in table ==> ", len(result)
36
36
 
37
37
        assert len(result) == 100
38
 
        
39
 
class Table1_0UCL(BackCompatTestCase):
 
38
        self.fileh.close()
 
39
 
 
40
class Table1_0UCL(BackCompatTablesTestCase):
40
41
    file = "Table1_0_ucl_nrv2e.h5"  # pytables 0.5.1 and before
41
42
 
42
 
class Table2_0UCL(BackCompatTestCase):
 
43
class Table2_0UCL(BackCompatTablesTestCase):
43
44
    file = "Table2_0_ucl_nrv2d.h5"  # pytables 0.7.x versions
44
45
 
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
47
48
 
 
49
class Tables_LZO1(BackCompatTablesTestCase):
 
50
    file = "Tables_lzo1.h5"  # files compressed with LZO1
 
51
 
 
52
class Tables_LZO1_shuffle(BackCompatTablesTestCase):
 
53
    file = "Tables_lzo1_shuffle.h5"  # files compressed with LZO1 and shuffle
 
54
 
 
55
class Tables_LZO2(BackCompatTablesTestCase):
 
56
    file = "Tables_lzo2.h5"  # files compressed with LZO2
 
57
 
 
58
class Tables_LZO2_shuffle(BackCompatTablesTestCase):
 
59
    file = "Tables_lzo2_shuffle.h5"  # files compressed with LZO2 and shuffle
 
60
 
 
61
# Check read attributes from PyTables >= 1.0 properly
 
62
class BackCompatAttrsTestCase(unittest.TestCase):
 
63
    file = "zerodim-attrs-%s.h5"
 
64
 
 
65
    def test01_readAttr(self):
 
66
        """Checking backward compatibility of old formats for attributes"""
 
67
 
 
68
        if verbose:
 
69
            print '\n', '-=' * 30
 
70
            print "Running %s.test01_readAttr..." % self.__class__.__name__
 
71
 
 
72
        # Read old formats
 
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)
 
85
 
 
86
        self.fileh.close()
 
87
 
 
88
class Attrs_1_3(BackCompatAttrsTestCase):
 
89
    format = "1.3"    # pytables 1.0.x versions and earlier
 
90
 
 
91
class Attrs_1_4(BackCompatAttrsTestCase):
 
92
    format = "1.4"    # pytables 1.1.x versions and later
 
93
 
48
94
 
49
95
#----------------------------------------------------------------------
50
96
 
56
102
    #theSuite.addTest(unittest.makeSuite(Table2_0UCL))
57
103
    #theSuite.addTest(unittest.makeSuite(Table2_1UCL))
58
104
 
59
 
    ucl_avail = whichLibVersion("ucl")[0]
 
105
    ucl_avail = whichLibVersion("ucl") is not None
60
106
    for n in range(niter):
61
107
        if ucl_avail:
62
108
            theSuite.addTest(unittest.makeSuite(Table1_0UCL))
63
109
            theSuite.addTest(unittest.makeSuite(Table2_0UCL))
64
110
            theSuite.addTest(unittest.makeSuite(Table2_1UCL))
65
 
            
 
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))
 
117
 
66
118
    return theSuite
67
119
 
68
120