widetree2.py :  » Database » PyTables » tables-2.1.2 » bench » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Database » PyTables 
PyTables » tables 2.1.2 » bench » widetree2.py
import sys
import unittest
import os
import tempfile

from tables import *
# Next imports are only necessary for this test suite
#from tables import Group, Leaf, Table, Array

verbose = 0

class Test(IsDescription):
    ngroup = Int32Col(pos=1)
    ntable = Int32Col(pos=2)
    nrow = Int32Col(pos=3)
    #string = StringCol(itemsize=500, pos=4)

class WideTreeTestCase(unittest.TestCase):
    def test00_Leafs(self):

        import time
        # Open a new empty HDF5 file
        filename = "test_widetree.h5"
        ngroups = 10
        ntables = 300
        nrows = 10
        complevel = 0
        complib = "lzo"

        print "Writing..."
        # Open a file in "w"rite mode
        fileh = openFile(filename, mode="w", title="PyTables Stress Test")

        for k in range(ngroups):
            # Create the group
            group = fileh.createGroup("/", 'group%04d'% k, "Group %d" % k)

        fileh.close()

        # Now, create the tables
        rowswritten = 0
        for k in range(ngroups):
            print "Filling tables in group:", k
            fileh = openFile(filename, mode="a", rootUEP='group%04d'% k)
            # Get the group
            group = fileh.root
            for j in range(ntables):
                # Create a table
                table = fileh.createTable(group, 'table%04d'% j, Test,
                                          'Table%04d'%j,
                                          Filters(complevel, complib), nrows)
                # Get the row object associated with the new table
                row = table.row
                # Fill the table
                for i in xrange(nrows):
                    row['ngroup'] = k
                    row['ntable'] = j
                    row['nrow'] = i
                    row.append()

                rowswritten += nrows
                table.flush()

            # Close the file
            fileh.close()


        # read the file
        print "Reading..."
        rowsread = 0
        for ngroup in range(ngroups):
            fileh = openFile(filename, mode="r", rootUEP='group%04d'% ngroup)
            # Get the group
            group = fileh.root
            ntable = 0
            if verbose:
                print "Group ==>", group
            for table in fileh.listNodes(group, 'Table'):
                rowsize = table.rowsize
                buffersize=table.rowsize * table.nrowsinbuf
                if verbose > 1:
                    print "Table ==>", table
                    print "Max rows in buf:", table.nrowsinbuf
                    print "Rows in", table._v_pathname, ":", table.nrows
                    print "Buffersize:", table.rowsize * table.nrowsinbuf
                    print "MaxTuples:", table.nrowsinbuf

                nrow = 0
                for row in table:
                    try:
                        assert row["ngroup"] == ngroup
                        assert row["ntable"] == ntable
                        assert row["nrow"] == nrow
                    except:
                        print "Error in group: %d, table: %d, row: %d" % \
                              (ngroup, ntable, nrow)
                        print "Record ==>", row
                    nrow += 1

                assert nrow == table.nrows
                rowsread += table.nrows
                ntable += 1

            # Close the file (eventually destroy the extended type)
            fileh.close()



#----------------------------------------------------------------------

def suite():
    theSuite = unittest.TestSuite()
    theSuite.addTest(unittest.makeSuite(WideTreeTestCase))

    return theSuite


if __name__ == '__main__':
    unittest.main(defaultTest='suite')
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.