Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
7f986acb
Kaydet (Commit)
7f986acb
authored
May 26, 2008
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Rename test file to its proper module name.
üst
0a7ac7d7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
147 additions
and
0 deletions
+147
-0
test_dbm.py
Lib/test/test_dbm.py
+147
-0
No files found.
Lib/test/test_dbm.py
0 → 100644
Dosyayı görüntüle @
7f986acb
#! /usr/bin/env python
"""Test script for the dbm.open function based on testdumbdbm.py"""
import
os
import
unittest
import
dbm
import
glob
import
test.support
_fname
=
test
.
support
.
TESTFN
#
# Iterates over every database module supported by dbm currently available,
# setting dbm to use each in turn, and yielding that module
#
def
dbm_iterator
():
old_default
=
dbm
.
_defaultmod
for
module
in
dbm
.
_modules
.
values
():
dbm
.
_defaultmod
=
module
yield
module
dbm
.
_defaultmod
=
old_default
#
# Clean up all scratch databases we might have created during testing
#
def
delete_files
():
# we don't know the precise name the underlying database uses
# so we use glob to locate all names
for
f
in
glob
.
glob
(
_fname
+
"*"
):
test
.
support
.
unlink
(
f
)
class
AnyDBMTestCase
(
unittest
.
TestCase
):
_dict
=
{
'0'
:
b
''
,
'a'
:
b
'Python:'
,
'b'
:
b
'Programming'
,
'c'
:
b
'the'
,
'd'
:
b
'way'
,
'f'
:
b
'Guido'
,
'g'
:
b
'intended'
,
}
def
__init__
(
self
,
*
args
):
unittest
.
TestCase
.
__init__
(
self
,
*
args
)
def
test_anydbm_creation
(
self
):
f
=
dbm
.
open
(
_fname
,
'c'
)
self
.
assertEqual
(
list
(
f
.
keys
()),
[])
for
key
in
self
.
_dict
:
f
[
key
.
encode
(
"ascii"
)]
=
self
.
_dict
[
key
]
self
.
read_helper
(
f
)
f
.
close
()
def
test_anydbm_modification
(
self
):
self
.
init_db
()
f
=
dbm
.
open
(
_fname
,
'c'
)
self
.
_dict
[
'g'
]
=
f
[
b
'g'
]
=
b
"indented"
self
.
read_helper
(
f
)
f
.
close
()
def
test_anydbm_read
(
self
):
self
.
init_db
()
f
=
dbm
.
open
(
_fname
,
'r'
)
self
.
read_helper
(
f
)
f
.
close
()
def
test_anydbm_keys
(
self
):
self
.
init_db
()
f
=
dbm
.
open
(
_fname
,
'r'
)
keys
=
self
.
keys_helper
(
f
)
f
.
close
()
def
test_anydbm_access
(
self
):
self
.
init_db
()
f
=
dbm
.
open
(
_fname
,
'r'
)
key
=
"a"
.
encode
(
"ascii"
)
assert
(
key
in
f
)
assert
(
f
[
key
]
==
b
"Python:"
)
f
.
close
()
def
read_helper
(
self
,
f
):
keys
=
self
.
keys_helper
(
f
)
for
key
in
self
.
_dict
:
self
.
assertEqual
(
self
.
_dict
[
key
],
f
[
key
.
encode
(
"ascii"
)])
def
init_db
(
self
):
f
=
dbm
.
open
(
_fname
,
'n'
)
for
k
in
self
.
_dict
:
f
[
k
.
encode
(
"ascii"
)]
=
self
.
_dict
[
k
]
f
.
close
()
def
keys_helper
(
self
,
f
):
keys
=
sorted
(
k
.
decode
(
"ascii"
)
for
k
in
f
.
keys
())
dkeys
=
sorted
(
self
.
_dict
.
keys
())
self
.
assertEqual
(
keys
,
dkeys
)
return
keys
def
tearDown
(
self
):
delete_files
()
def
setUp
(
self
):
delete_files
()
class
WhichDBTestCase
(
unittest
.
TestCase
):
# Actual test methods are added to namespace after class definition.
def
__init__
(
self
,
*
args
):
unittest
.
TestCase
.
__init__
(
self
,
*
args
)
def
test_whichdb
(
self
):
for
module
in
dbm_iterator
():
# Check whether whichdb correctly guesses module name
# for databases opened with "module" module.
# Try with empty files first
name
=
module
.
__name__
if
name
==
'dbm.dumb'
:
continue
# whichdb can't support dbm.dumb
test
.
support
.
unlink
(
_fname
)
f
=
module
.
open
(
_fname
,
'c'
)
f
.
close
()
self
.
assertEqual
(
name
,
dbm
.
whichdb
(
_fname
))
# Now add a key
f
=
module
.
open
(
_fname
,
'w'
)
f
[
b
"1"
]
=
b
"1"
# and test that we can find it
self
.
assertTrue
(
b
"1"
in
f
)
# and read it
self
.
assertTrue
(
f
[
b
"1"
]
==
b
"1"
)
f
.
close
()
self
.
assertEqual
(
name
,
dbm
.
whichdb
(
_fname
))
def
tearDown
(
self
):
delete_files
()
def
setUp
(
self
):
delete_files
()
def
test_main
():
try
:
for
module
in
dbm_iterator
():
test
.
support
.
run_unittest
(
AnyDBMTestCase
,
WhichDBTestCase
)
finally
:
delete_files
()
if
__name__
==
"__main__"
:
test_main
()
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