1996-12-10 00:06:24 +00:00
|
|
|
#! /usr/bin/env python
|
|
|
|
"""Test script for the dbm module
|
|
|
|
Roger E. Masse
|
|
|
|
"""
|
2002-11-02 18:25:08 +00:00
|
|
|
import os
|
1996-12-10 00:06:24 +00:00
|
|
|
import dbm
|
|
|
|
from dbm import error
|
2006-08-25 23:40:32 +00:00
|
|
|
from test.test_support import verbose, verify, TestSkipped, TESTFN
|
1996-12-20 22:36:52 +00:00
|
|
|
|
2002-11-02 18:25:08 +00:00
|
|
|
# make filename unique to allow multiple concurrent tests
|
|
|
|
# and to minimize the likelihood of a problem from an old file
|
2006-08-25 23:40:32 +00:00
|
|
|
filename = TESTFN
|
1996-12-10 00:06:24 +00:00
|
|
|
|
2002-11-02 18:25:08 +00:00
|
|
|
def cleanup():
|
|
|
|
for suffix in ['', '.pag', '.dir', '.db']:
|
|
|
|
try:
|
|
|
|
os.unlink(filename + suffix)
|
2007-01-10 16:19:56 +00:00
|
|
|
except OSError as e:
|
2007-02-27 00:15:55 +00:00
|
|
|
(errno, strerror) = e.errno, e.strerror
|
2002-11-02 18:25:08 +00:00
|
|
|
# if we can't delete the file because of permissions,
|
|
|
|
# nothing will work, so skip the test
|
|
|
|
if errno == 1:
|
2007-08-29 23:37:32 +00:00
|
|
|
raise TestSkipped('unable to remove: ' + filename + suffix)
|
2000-09-18 17:56:58 +00:00
|
|
|
|
2002-11-02 18:25:08 +00:00
|
|
|
def test_keys():
|
|
|
|
d = dbm.open(filename, 'c')
|
|
|
|
verify(d.keys() == [])
|
2007-08-14 15:42:45 +00:00
|
|
|
d[b'a'] = b'b'
|
|
|
|
d[b'12345678910'] = b'019237410982340912840198242'
|
2002-11-02 18:25:08 +00:00
|
|
|
d.keys()
|
2007-08-14 15:42:45 +00:00
|
|
|
if b'a' in d:
|
2002-11-02 18:25:08 +00:00
|
|
|
if verbose:
|
2007-02-09 05:37:30 +00:00
|
|
|
print('Test dbm keys: ', d.keys())
|
1996-12-10 00:06:24 +00:00
|
|
|
|
2002-11-02 18:25:08 +00:00
|
|
|
d.close()
|
|
|
|
|
|
|
|
def test_modes():
|
|
|
|
d = dbm.open(filename, 'r')
|
|
|
|
d.close()
|
|
|
|
d = dbm.open(filename, 'rw')
|
|
|
|
d.close()
|
|
|
|
d = dbm.open(filename, 'w')
|
|
|
|
d.close()
|
|
|
|
d = dbm.open(filename, 'n')
|
|
|
|
d.close()
|
|
|
|
|
Merged revisions 61189-61190,61192,61194-61195,61198-61199 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r61189 | brett.cannon | 2008-03-03 01:38:58 +0100 (Mon, 03 Mar 2008) | 5 lines
Refactor test_logging to use unittest. This should finally solve the flakiness
issues.
Thanks to Antoine Pitrou for the patch.
........
r61190 | jeffrey.yasskin | 2008-03-03 02:27:03 +0100 (Mon, 03 Mar 2008) | 3 lines
compile.c always emits END_FINALLY after WITH_CLEANUP, so predict that in
ceval.c. This is worth about a .03-.04us speedup on a simple with block.
........
r61192 | brett.cannon | 2008-03-03 03:41:40 +0100 (Mon, 03 Mar 2008) | 4 lines
Move test_largefile over to using 'with' statements for open files.
Also rename the driver function to test_main() instead of main_test().
........
r61194 | brett.cannon | 2008-03-03 04:24:48 +0100 (Mon, 03 Mar 2008) | 3 lines
Add a note in the main test class' docstring that the order of execution of the
tests is important.
........
r61195 | brett.cannon | 2008-03-03 04:26:43 +0100 (Mon, 03 Mar 2008) | 3 lines
Add a note in the main test class' docstring that the order of execution of the
tests is important.
........
r61198 | brett.cannon | 2008-03-03 05:19:29 +0100 (Mon, 03 Mar 2008) | 4 lines
Add test_main() functions to various tests where it was simple to do. Done so
that regrtest can execute the test_main() directly instead of relying on import
side-effects.
........
r61199 | neal.norwitz | 2008-03-03 05:37:45 +0100 (Mon, 03 Mar 2008) | 1 line
Only DECREF if ret != NULL
........
2008-03-03 19:15:45 +00:00
|
|
|
def test_main():
|
2002-11-02 18:25:08 +00:00
|
|
|
cleanup()
|
Merged revisions 61189-61190,61192,61194-61195,61198-61199 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r61189 | brett.cannon | 2008-03-03 01:38:58 +0100 (Mon, 03 Mar 2008) | 5 lines
Refactor test_logging to use unittest. This should finally solve the flakiness
issues.
Thanks to Antoine Pitrou for the patch.
........
r61190 | jeffrey.yasskin | 2008-03-03 02:27:03 +0100 (Mon, 03 Mar 2008) | 3 lines
compile.c always emits END_FINALLY after WITH_CLEANUP, so predict that in
ceval.c. This is worth about a .03-.04us speedup on a simple with block.
........
r61192 | brett.cannon | 2008-03-03 03:41:40 +0100 (Mon, 03 Mar 2008) | 4 lines
Move test_largefile over to using 'with' statements for open files.
Also rename the driver function to test_main() instead of main_test().
........
r61194 | brett.cannon | 2008-03-03 04:24:48 +0100 (Mon, 03 Mar 2008) | 3 lines
Add a note in the main test class' docstring that the order of execution of the
tests is important.
........
r61195 | brett.cannon | 2008-03-03 04:26:43 +0100 (Mon, 03 Mar 2008) | 3 lines
Add a note in the main test class' docstring that the order of execution of the
tests is important.
........
r61198 | brett.cannon | 2008-03-03 05:19:29 +0100 (Mon, 03 Mar 2008) | 4 lines
Add test_main() functions to various tests where it was simple to do. Done so
that regrtest can execute the test_main() directly instead of relying on import
side-effects.
........
r61199 | neal.norwitz | 2008-03-03 05:37:45 +0100 (Mon, 03 Mar 2008) | 1 line
Only DECREF if ret != NULL
........
2008-03-03 19:15:45 +00:00
|
|
|
try:
|
|
|
|
test_keys()
|
|
|
|
test_modes()
|
|
|
|
except:
|
|
|
|
cleanup()
|
|
|
|
raise
|
2002-11-02 18:25:08 +00:00
|
|
|
|
Merged revisions 61189-61190,61192,61194-61195,61198-61199 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r61189 | brett.cannon | 2008-03-03 01:38:58 +0100 (Mon, 03 Mar 2008) | 5 lines
Refactor test_logging to use unittest. This should finally solve the flakiness
issues.
Thanks to Antoine Pitrou for the patch.
........
r61190 | jeffrey.yasskin | 2008-03-03 02:27:03 +0100 (Mon, 03 Mar 2008) | 3 lines
compile.c always emits END_FINALLY after WITH_CLEANUP, so predict that in
ceval.c. This is worth about a .03-.04us speedup on a simple with block.
........
r61192 | brett.cannon | 2008-03-03 03:41:40 +0100 (Mon, 03 Mar 2008) | 4 lines
Move test_largefile over to using 'with' statements for open files.
Also rename the driver function to test_main() instead of main_test().
........
r61194 | brett.cannon | 2008-03-03 04:24:48 +0100 (Mon, 03 Mar 2008) | 3 lines
Add a note in the main test class' docstring that the order of execution of the
tests is important.
........
r61195 | brett.cannon | 2008-03-03 04:26:43 +0100 (Mon, 03 Mar 2008) | 3 lines
Add a note in the main test class' docstring that the order of execution of the
tests is important.
........
r61198 | brett.cannon | 2008-03-03 05:19:29 +0100 (Mon, 03 Mar 2008) | 4 lines
Add test_main() functions to various tests where it was simple to do. Done so
that regrtest can execute the test_main() directly instead of relying on import
side-effects.
........
r61199 | neal.norwitz | 2008-03-03 05:37:45 +0100 (Mon, 03 Mar 2008) | 1 line
Only DECREF if ret != NULL
........
2008-03-03 19:15:45 +00:00
|
|
|
cleanup()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
test_main()
|