mirror of
https://github.com/python/cpython.git
synced 2024-11-29 12:54:02 +08:00
7317c1ef7a
former they are converted to bytes before being written to the DB. Closes issue 3799. Reviewed by Skip Montanaro.
43 lines
1.1 KiB
Python
Executable File
43 lines
1.1 KiB
Python
Executable File
from test import support
|
|
import unittest
|
|
import os
|
|
import random
|
|
import dbm.ndbm
|
|
from dbm.ndbm import error
|
|
|
|
class DbmTestCase(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
self.filename = support.TESTFN
|
|
self.d = dbm.ndbm.open(self.filename, 'c')
|
|
self.d.close()
|
|
|
|
def tearDown(self):
|
|
for suffix in ['', '.pag', '.dir', '.db']:
|
|
support.unlink(self.filename + suffix)
|
|
|
|
def test_keys(self):
|
|
self.d = dbm.ndbm.open(self.filename, 'c')
|
|
self.assert_(self.d.keys() == [])
|
|
self.d['a'] = 'b'
|
|
self.d[b'bytes'] = b'data'
|
|
self.d['12345678910'] = '019237410982340912840198242'
|
|
self.d.keys()
|
|
self.assert_(b'a' in self.d)
|
|
self.assertEqual(self.d[b'bytes'], b'data')
|
|
self.d.close()
|
|
|
|
def test_modes(self):
|
|
for mode in ['r', 'rw', 'w', 'n']:
|
|
try:
|
|
self.d = dbm.ndbm.open(self.filename, mode)
|
|
self.d.close()
|
|
except error:
|
|
self.fail()
|
|
|
|
def test_main():
|
|
support.run_unittest(DbmTestCase)
|
|
|
|
if __name__ == '__main__':
|
|
test_main()
|