root/lang/python/pytc/tests/testHDB.py @ 1990

Revision 1990, 2.4 kB (checked in by tasuku, 7 years ago)

moved pytc repository from brazil to CodeRepos?

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2# -*- coding:utf-8 -*-
3
4import os, sys
5import unittest
6import pytc
7
8DBNAME = 'test.hdb'
9DBNAME2 = 'test.hdb.copy'
10
11class TestHDB(unittest.TestCase):
12  def setUp(self):
13    if os.path.exists(DBNAME):
14      os.remove(DBNAME)
15
16  def testAll(self):
17    # new
18    db = pytc.HDB()
19    # tune
20    db.tune(100, 32, 64, pytc.HDBTTCBS)
21    # open
22    db.open(DBNAME2, pytc.HDBOWRITER | pytc.HDBOCREAT)
23    # copy
24    db.copy(DBNAME)
25    # close
26    db.close
27    os.remove(DBNAME2)
28
29    # open
30    db = pytc.HDB(DBNAME, pytc.HDBOWRITER)
31
32    # put
33    db.put('hamu', 'ju')
34    db.put('moru', 'pui')
35    db.put('kiki', 'nya-')
36
37    # get
38    self.assertEqual(db.get('hamu'), 'ju')
39    # vsiz
40    self.assertEqual(db.vsiz('hamu'), len('ju'))
41
42    # putkeep
43    self.assertRaises(
44      pytc.Error,
45      db.putkeep, 'moru', 'puipui')
46    db.putkeep('moruta', 'puipui')
47    self.assertEqual(db.get('moruta'), 'puipui')
48
49    # putcat
50    db.putcat('kiki', 'nya-nya-')
51    self.assertEqual(db.get('kiki'), 'nya-nya-nya-')
52
53    # putasync
54    db.putasync('gunya', 'darari')
55    # sync
56    db.sync
57    self.assertEqual(db.get('gunya'), 'darari')
58
59    # out
60    db.out('gunya')
61    self.assertRaises(
62      pytc.Error,
63      db.get, 'gunya')
64    # optimize
65    db.optimize(100, 32, 64, pytc.HDBTTCBS)
66
67    # path
68    self.assertEqual(db.path(), DBNAME)
69    # rnum
70    self.assertEqual(db.rnum(), 4)
71    # fsiz
72    self.assertNotEqual(db.fsiz(), 0)
73
74    # iterinit
75    db.iterinit()
76    # iternext
77    self.assertEqual(db.iternext(), 'hamu')
78    db.iterinit()
79    self.assertEqual(db.iternext(), 'hamu')
80
81    # dict like interfaces
82    result = []
83    for key in db:
84      result.append(key)
85    self.assertEqual(sorted(result), ['hamu', 'kiki', 'moru', 'moruta'])
86
87    self.assertEqual(sorted(db.keys()), ['hamu', 'kiki', 'moru', 'moruta'])
88    self.assertEqual(sorted(db.values()), ['ju', 'nya-nya-nya-', 'pui', 'puipui'])
89    self.assertEqual(sorted(db.items()),[
90      ('hamu', 'ju'), ('kiki', 'nya-nya-nya-'), ('moru', 'pui'), ('moruta', 'puipui')])
91
92    db['gunya'] = 'tekito'
93    self.assertEqual(db['gunya'], 'tekito')
94    del db['gunya']
95    self.assertRaises(
96      pytc.Error,
97      db.get, 'gunya')
98
99    self.assert_('hamu' in db)
100    self.assert_('python' not in db)
101
102    # vanish
103    db.vanish()
104    self.assertEqual(db.rnum(), 0)
105
106    # remove
107    os.remove(DBNAME)
108
109if __name__=='__main__': unittest.main()
Note: See TracBrowser for help on using the browser.