Esempio n. 1
0
class HDBTest(unittest.TestCase):

    def setUp(self):
        self.path = os.path.join(tempfile.gettempdir(), "tmp_tc_test.tch")
        self.db = HDB()
        self.db.open(self.path, HDBOWRITER | HDBOCREAT)

    def tearDown(self):
        self.db.close()
        os.remove(self.path)
        self.db = None
Esempio n. 2
0
 def test_copy(self):
     self.db[b"a"] = b"1"
     self.db[b"b"] = b"2"
     path = os.path.join(tempfile.gettempdir(), "tmp_tc_test2.tch")
     self.db.copy(path)
     db = HDB()
     db.open(path, HDBOREADER)
     self.assertEqual(len(self.db), len(db))
     self.assertEqual(self.db.size, db.size)
     db.close()
     os.remove(path)
Esempio n. 3
0
    def test_reducer(self):
        red = TokyoCabinetReducer()
        output = red(zip('abcde', '12345'))

        fn = mkstemp()[1]
        fo = open(fn, 'wb')
        fo.writelines(v for k, v in output)
        fo.close()
        db = HDB()
        db.open(fn, HDBOREADER)
        self.assertEqual(list(db.iteritems()),
                [('a', '1'), ('b', '2'), ('c', '3'), ('d', '4'), ('e', '5')])
        db.close()
        os.remove(fn)
Esempio n. 4
0
    def test_reducer(self):
        red = TokyoCabinetReducer()
        output = red(zip('abcde', '12345'))

        fn = mkstemp()[1]
        fo = open(fn, 'wb')
        fo.writelines(v for k, v in output)
        fo.close()
        db = HDB()
        db.open(fn, HDBOREADER)
        self.assertEqual(list(db.iteritems()), [('a', '1'), ('b', '2'),
                                                ('c', '3'), ('d', '4'),
                                                ('e', '5')])
        db.close()
        os.remove(fn)
Esempio n. 5
0
    def test_default(self):
        proc = TokyoCabinetFactory()
        self.assertEqual(proc('k1', ['v1']), None)
        self.assertEqual(proc('k2', ['v2', 'v3']), None)
        chunks = proc.close()
        fn = mkstemp()[1]
        fo = open(fn, 'wb')
        for chk in chunks:
            self.assertTrue(len(chk) <= proc.chunksize)
            fo.write(chk)
        fo.close()

        db = HDB()
        db.open(fn, HDBOREADER)
        self.assertEqual(list(db.iteritems()), [('k1', 'v1'), ('k2', 'v3')])
        db.close()
        os.remove(fn)
Esempio n. 6
0
    def test_default(self):
        proc = TokyoCabinetFactory()
        self.assertEqual(proc('k1', ['v1']), None)
        self.assertEqual(proc('k2', ['v2', 'v3']), None)
        chunks = proc.close()
        fn = mkstemp()[1]
        fo = open(fn, 'wb')
        for chk in chunks:
            self.assertTrue(len(chk) <= proc.chunksize)
            fo.write(chk)
        fo.close()

        db = HDB()
        db.open(fn, HDBOREADER)
        self.assertEqual(list(db.iteritems()), [('k1', 'v1'), ('k2', 'v3')])
        db.close()
        os.remove(fn)