~pythonregexp2.7/python/issue2636-09-01+10

« back to all changes in this revision

Viewing changes to Lib/bsddb/test/test_misc.py

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-09-22 21:39:45 UTC
  • mfrom: (39055.1.33 Regexp-2.7)
  • Revision ID: darklord@timehorse.com-20080922213945-23717m5eiqpamcyn
Merged in changes from the Single-Loop Engine branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
import os
5
5
import unittest
6
6
 
7
 
try:
8
 
    # For Pythons w/distutils pybsddb
9
 
    from bsddb3 import db, dbshelve, hashopen
10
 
except ImportError:
11
 
    # For Python 2.3
12
 
    from bsddb import db, dbshelve, hashopen
13
 
 
14
 
from test_all import get_new_environment_path, get_new_database_path
15
 
 
16
 
try:
17
 
    from bsddb3 import test_support
18
 
except ImportError:
19
 
    from test import test_support
 
7
from test_all import db, dbshelve, hashopen, test_support, get_new_environment_path, get_new_database_path
20
8
 
21
9
#----------------------------------------------------------------------
22
10
 
39
27
        # check for crash fixed when db_home is used before open()
40
28
        self.assert_(env.db_home is None)
41
29
        env.open(self.homeDir, db.DB_CREATE)
42
 
        self.assertEqual(self.homeDir, env.db_home)
 
30
        import sys
 
31
        if sys.version_info[0] < 3 :
 
32
            self.assertEqual(self.homeDir, env.db_home)
 
33
        else :
 
34
            self.assertEqual(bytes(self.homeDir, "ascii"), env.db_home)
43
35
 
44
36
    def test03_repr_closed_db(self):
45
37
        db = hashopen(self.filename)
47
39
        rp = repr(db)
48
40
        self.assertEquals(rp, "{}")
49
41
 
 
42
    def test04_repr_db(self) :
 
43
        db = hashopen(self.filename)
 
44
        d = {}
 
45
        for i in xrange(100) :
 
46
            db[repr(i)] = repr(100*i)
 
47
            d[repr(i)] = repr(100*i)
 
48
        db.close()
 
49
        db = hashopen(self.filename)
 
50
        rp = repr(db)
 
51
        self.assertEquals(rp, repr(d))
 
52
        db.close()
 
53
 
50
54
    # http://sourceforge.net/tracker/index.php?func=detail&aid=1708868&group_id=13900&atid=313900
51
55
    #
52
56
    # See the bug report for details.
54
58
    # The problem was that make_key_dbt() was not allocating a copy of
55
59
    # string keys but FREE_DBT() was always being told to free it when the
56
60
    # database was opened with DB_THREAD.
57
 
    def test04_double_free_make_key_dbt(self):
 
61
    def test05_double_free_make_key_dbt(self):
58
62
        try:
59
63
            db1 = db.DB()
60
64
            db1.open(self.filename, None, db.DB_BTREE,
65
69
            # double free happened during exit from DBC_get
66
70
        finally:
67
71
            db1.close()
68
 
            os.unlink(self.filename)
 
72
            test_support.unlink(self.filename)
69
73
 
70
 
    def test05_key_with_null_bytes(self):
 
74
    def test06_key_with_null_bytes(self):
71
75
        try:
72
76
            db1 = db.DB()
73
77
            db1.open(self.filename, None, db.DB_HASH, db.DB_CREATE)
84
88
            self.assertEqual(db1['aaa'], 'eh eh eh!')
85
89
        finally:
86
90
            db1.close()
87
 
            os.unlink(self.filename)
 
91
            test_support.unlink(self.filename)
88
92
 
89
 
    def test_DB_set_flags_persists(self):
 
93
    def test07_DB_set_flags_persists(self):
90
94
        if db.version() < (4,2):
91
95
            # The get_flags API required for this to work is only available
92
96
            # in Berkeley DB >= 4.2
112
116
            self.assertEqual([('a', 'new A')], db1.items())
113
117
        finally:
114
118
            db1.close()
115
 
            os.unlink(self.filename)
 
119
            test_support.unlink(self.filename)
116
120
 
117
121
 
118
122
#----------------------------------------------------------------------