Beispiel #1
0
    def runTest(self):
        print "------------------ Test4  DB persistence ---------"

        ppdb = XMDCTBDB('NonPersistentMPdb.db', persistent=False)
        self.assertTrue(os.path.exists('./NonPersistentMPdb.db'))
        del ppdb
        self.assertFalse(os.path.exists('./NonPersistentMPdb.db'))

        ppdb = XMDCTBDB('PersistentMPdb.db', persistent=True)
        self.assertTrue(os.path.exists('./PersistentMPdb.db'))
        del ppdb
        self.assertTrue(os.path.exists('./PersistentMPdb.db'))

        # now add something in the base
        ppdb = XMDCTBDB('./PersistentMPdb.db', load=True)
        ppdb.keyformat = None
        self.assertTrue(ppdb.persistent)
        ppdb.add(zip((440, ), (1.45, )), 4)

        # delete the base and reload it
        del ppdb

        ppdb = XMDCTBDB('./PersistentMPdb.db', load=True)
        ppdb.keyformat = None
        T, fi = ppdb.get(440)
        self.assertTrue(abs(T[0] - 1.45) < 0.01)
        self.assertEqual(fi[0], 4)
Beispiel #2
0
    def runTest(self):
        print "------------------ Test 8  different formattings ---------"
        dbFormat1 = XMDCTBDB('format1.db', load=False, persistent=False)
        dbFormat0 = XMDCTBDB('format2.db', load=False, persistent=False)
        dbFormat1.keyformat = None
        key1 = [0, 12]
        data = 13.0

        dbFormat1.add(zip((key1[1], ), (data, )), 2)
        dbFormat0.add(zip((key1, ), (data, )), 2)

        T, fi = dbFormat0.get(key1)
        print fi
Beispiel #3
0
    def runTest(self):
        ''' what happens when the same key is used with a different value? we should be able to retrieve
        a list of possible songs
        '''
        print "------------------ Test 7  handling uniqueness ---------"
        dummyDb = XMDCTBDB('dummyDb.db', load=False, persistent=False)
        dummyDb.keyformat = None
        dummyDb.add(zip((440, 128, 440), (12.0, 16.0, 45.0)), 1)
        dummyDb.add(zip((512, 320, 440), (54.0, 16.0, 11.0)), 2)

        #        print dummyDb.get_stats()
        self.assertEqual(6, dummyDb.get_stats()['ndata'])

        T, fileIndex = dummyDb.get(440)
        print zip(T, fileIndex)
Beispiel #4
0
    def runTest(self):
        print "------------------ Test2  DB Handle ---------"
        print 'Creating a hash table using Berkeley DB'
        dbName = 'dummy.db'

        ppbdb = XMDCTBDB(dbName, load=False, persistent=False)
        ppbdb.keyformat = None
        print 'populating with a key from MP'
        F = 128
        T = 125.0
        FileIdx = 104

        ppbdb.add(zip((F, ), (T, )), FileIdx)
        estT, estFileI = ppbdb.get(F)

        # refactoring, renvoi une liste de candidats

        self.assertEqual(estFileI[0], FileIdx)
        self.assertTrue(abs(estT[0] - T) < 0.01)

        print ppbdb.get_stats()
        print ppbdb
        del ppbdb