Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
877dbbc7
Commit
877dbbc7
authored
Jun 06, 2005
by
Gregory P. Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test DB.associate using transactions. somewhat related to SF pybsddb
bug #1215432
parent
d68c41f0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
12 deletions
+46
-12
Lib/bsddb/test/test_associate.py
Lib/bsddb/test/test_associate.py
+46
-12
No files found.
Lib/bsddb/test/test_associate.py
View file @
877dbbc7
...
@@ -91,6 +91,8 @@ musicdata = {
...
@@ -91,6 +91,8 @@ musicdata = {
class
AssociateTestCase
(
unittest
.
TestCase
):
class
AssociateTestCase
(
unittest
.
TestCase
):
keytype
=
''
keytype
=
''
envFlags
=
0
dbFlags
=
0
def
setUp
(
self
):
def
setUp
(
self
):
self
.
filename
=
self
.
__class__
.
__name__
+
'.db'
self
.
filename
=
self
.
__class__
.
__name__
+
'.db'
...
@@ -100,7 +102,7 @@ class AssociateTestCase(unittest.TestCase):
...
@@ -100,7 +102,7 @@ class AssociateTestCase(unittest.TestCase):
except
os
.
error
:
pass
except
os
.
error
:
pass
self
.
env
=
db
.
DBEnv
()
self
.
env
=
db
.
DBEnv
()
self
.
env
.
open
(
homeDir
,
db
.
DB_CREATE
|
db
.
DB_INIT_MPOOL
|
self
.
env
.
open
(
homeDir
,
db
.
DB_CREATE
|
db
.
DB_INIT_MPOOL
|
db
.
DB_INIT_LOCK
|
db
.
DB_THREAD
)
db
.
DB_INIT_LOCK
|
db
.
DB_THREAD
|
self
.
envFlags
)
def
tearDown
(
self
):
def
tearDown
(
self
):
self
.
closeDB
()
self
.
closeDB
()
...
@@ -110,17 +112,17 @@ class AssociateTestCase(unittest.TestCase):
...
@@ -110,17 +112,17 @@ class AssociateTestCase(unittest.TestCase):
for
file
in
files
:
for
file
in
files
:
os
.
remove
(
file
)
os
.
remove
(
file
)
def
addDataToDB
(
self
,
d
):
def
addDataToDB
(
self
,
d
,
txn
=
None
):
for
key
,
value
in
musicdata
.
items
():
for
key
,
value
in
musicdata
.
items
():
if
type
(
self
.
keytype
)
==
type
(
''
):
if
type
(
self
.
keytype
)
==
type
(
''
):
key
=
"%02d"
%
key
key
=
"%02d"
%
key
d
.
put
(
key
,
string
.
join
(
value
,
'|'
))
d
.
put
(
key
,
string
.
join
(
value
,
'|'
)
,
txn
=
txn
)
def
createDB
(
self
):
def
createDB
(
self
,
txn
=
None
):
self
.
primary
=
db
.
DB
(
self
.
env
)
self
.
primary
=
db
.
DB
(
self
.
env
)
self
.
primary
.
set_get_returns_none
(
2
)
self
.
primary
.
set_get_returns_none
(
2
)
self
.
primary
.
open
(
self
.
filename
,
"primary"
,
self
.
dbtype
,
self
.
primary
.
open
(
self
.
filename
,
"primary"
,
self
.
dbtype
,
db
.
DB_CREATE
|
db
.
DB_THREAD
)
db
.
DB_CREATE
|
db
.
DB_THREAD
|
self
.
dbFlags
,
txn
=
txn
)
def
closeDB
(
self
):
def
closeDB
(
self
):
self
.
primary
.
close
()
self
.
primary
.
close
()
...
@@ -128,6 +130,7 @@ class AssociateTestCase(unittest.TestCase):
...
@@ -128,6 +130,7 @@ class AssociateTestCase(unittest.TestCase):
def
getDB
(
self
):
def
getDB
(
self
):
return
self
.
primary
return
self
.
primary
def
test01_associateWithDB
(
self
):
def
test01_associateWithDB
(
self
):
if
verbose
:
if
verbose
:
print
'
\
n
'
,
'-='
*
30
print
'
\
n
'
,
'-='
*
30
...
@@ -140,7 +143,7 @@ class AssociateTestCase(unittest.TestCase):
...
@@ -140,7 +143,7 @@ class AssociateTestCase(unittest.TestCase):
secDB
.
set_flags
(
db
.
DB_DUP
)
secDB
.
set_flags
(
db
.
DB_DUP
)
secDB
.
set_get_returns_none
(
2
)
secDB
.
set_get_returns_none
(
2
)
secDB
.
open
(
self
.
filename
,
"secondary"
,
db
.
DB_BTREE
,
secDB
.
open
(
self
.
filename
,
"secondary"
,
db
.
DB_BTREE
,
db
.
DB_CREATE
|
db
.
DB_THREAD
)
db
.
DB_CREATE
|
db
.
DB_THREAD
|
self
.
dbFlags
)
self
.
getDB
().
associate
(
secDB
,
self
.
getGenre
)
self
.
getDB
().
associate
(
secDB
,
self
.
getGenre
)
self
.
addDataToDB
(
self
.
getDB
())
self
.
addDataToDB
(
self
.
getDB
())
...
@@ -160,7 +163,7 @@ class AssociateTestCase(unittest.TestCase):
...
@@ -160,7 +163,7 @@ class AssociateTestCase(unittest.TestCase):
secDB
=
db
.
DB
(
self
.
env
)
secDB
=
db
.
DB
(
self
.
env
)
secDB
.
set_flags
(
db
.
DB_DUP
)
secDB
.
set_flags
(
db
.
DB_DUP
)
secDB
.
open
(
self
.
filename
,
"secondary"
,
db
.
DB_BTREE
,
secDB
.
open
(
self
.
filename
,
"secondary"
,
db
.
DB_BTREE
,
db
.
DB_CREATE
|
db
.
DB_THREAD
)
db
.
DB_CREATE
|
db
.
DB_THREAD
|
self
.
dbFlags
)
# adding the DB_CREATE flag will cause it to index existing records
# adding the DB_CREATE flag will cause it to index existing records
self
.
getDB
().
associate
(
secDB
,
self
.
getGenre
,
db
.
DB_CREATE
)
self
.
getDB
().
associate
(
secDB
,
self
.
getGenre
,
db
.
DB_CREATE
)
...
@@ -168,12 +171,12 @@ class AssociateTestCase(unittest.TestCase):
...
@@ -168,12 +171,12 @@ class AssociateTestCase(unittest.TestCase):
self
.
finish_test
(
secDB
)
self
.
finish_test
(
secDB
)
def
finish_test
(
self
,
secDB
):
def
finish_test
(
self
,
secDB
,
txn
=
None
):
# 'Blues' should not be in the secondary database
# 'Blues' should not be in the secondary database
vals
=
secDB
.
pget
(
'Blues'
)
vals
=
secDB
.
pget
(
'Blues'
,
txn
=
txn
)
assert
vals
==
None
,
vals
assert
vals
==
None
,
vals
vals
=
secDB
.
pget
(
'Unknown'
)
vals
=
secDB
.
pget
(
'Unknown'
,
txn
=
txn
)
assert
vals
[
0
]
==
99
or
vals
[
0
]
==
'99'
,
vals
assert
vals
[
0
]
==
99
or
vals
[
0
]
==
'99'
,
vals
vals
[
1
].
index
(
'Unknown'
)
vals
[
1
].
index
(
'Unknown'
)
vals
[
1
].
index
(
'Unnamed'
)
vals
[
1
].
index
(
'Unnamed'
)
...
@@ -181,7 +184,7 @@ class AssociateTestCase(unittest.TestCase):
...
@@ -181,7 +184,7 @@ class AssociateTestCase(unittest.TestCase):
if
verbose
:
if
verbose
:
print
"Primary key traversal:"
print
"Primary key traversal:"
c
=
self
.
getDB
().
cursor
()
c
=
self
.
getDB
().
cursor
(
txn
)
count
=
0
count
=
0
rec
=
c
.
first
()
rec
=
c
.
first
()
while
rec
is
not
None
:
while
rec
is
not
None
:
...
@@ -198,7 +201,7 @@ class AssociateTestCase(unittest.TestCase):
...
@@ -198,7 +201,7 @@ class AssociateTestCase(unittest.TestCase):
if
verbose
:
if
verbose
:
print
"Secondary key traversal:"
print
"Secondary key traversal:"
c
=
secDB
.
cursor
()
c
=
secDB
.
cursor
(
txn
)
count
=
0
count
=
0
# test cursor pget
# test cursor pget
...
@@ -246,6 +249,35 @@ class AssociateRecnoTestCase(AssociateTestCase):
...
@@ -246,6 +249,35 @@ class AssociateRecnoTestCase(AssociateTestCase):
dbtype
=
db
.
DB_RECNO
dbtype
=
db
.
DB_RECNO
keytype
=
0
keytype
=
0
#----------------------------------------------------------------------
class
AssociateBTreeTxnTestCase
(
AssociateBTreeTestCase
):
envFlags
=
db
.
DB_INIT_TXN
dbFlags
=
0
def
test13_associateAutoCommit
(
self
):
if
verbose
:
print
'
\
n
'
,
'-='
*
30
print
"Running %s.test13_associateAutoCommit..."
%
\
self
.
__class__
.
__name__
txn
=
self
.
env
.
txn_begin
()
try
:
self
.
createDB
(
txn
=
txn
)
secDB
=
db
.
DB
(
self
.
env
)
secDB
.
set_flags
(
db
.
DB_DUP
)
secDB
.
set_get_returns_none
(
2
)
secDB
.
open
(
self
.
filename
,
"secondary"
,
db
.
DB_BTREE
,
db
.
DB_CREATE
|
db
.
DB_THREAD
,
txn
=
txn
)
self
.
getDB
().
associate
(
secDB
,
self
.
getGenre
,
txn
=
txn
)
self
.
addDataToDB
(
self
.
getDB
(),
txn
=
txn
)
self
.
finish_test
(
secDB
,
txn
=
txn
)
finally
:
txn
.
commit
()
#----------------------------------------------------------------------
#----------------------------------------------------------------------
...
@@ -335,6 +367,8 @@ def test_suite():
...
@@ -335,6 +367,8 @@ def test_suite():
suite
.
addTest
(
unittest
.
makeSuite
(
AssociateBTreeTestCase
))
suite
.
addTest
(
unittest
.
makeSuite
(
AssociateBTreeTestCase
))
suite
.
addTest
(
unittest
.
makeSuite
(
AssociateRecnoTestCase
))
suite
.
addTest
(
unittest
.
makeSuite
(
AssociateRecnoTestCase
))
suite
.
addTest
(
unittest
.
makeSuite
(
AssociateBTreeTxnTestCase
))
suite
.
addTest
(
unittest
.
makeSuite
(
ShelveAssociateHashTestCase
))
suite
.
addTest
(
unittest
.
makeSuite
(
ShelveAssociateHashTestCase
))
suite
.
addTest
(
unittest
.
makeSuite
(
ShelveAssociateBTreeTestCase
))
suite
.
addTest
(
unittest
.
makeSuite
(
ShelveAssociateBTreeTestCase
))
suite
.
addTest
(
unittest
.
makeSuite
(
ShelveAssociateRecnoTestCase
))
suite
.
addTest
(
unittest
.
makeSuite
(
ShelveAssociateRecnoTestCase
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment