summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2013-07-07 11:16:05 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2013-07-07 11:16:05 (GMT)
commit9f96789cdcb4548ecb9708fe78ffabedecd2d14c (patch)
tree07d8d9504ea7882990731799164e80c6c732e0f1 /Lib/test
parent74a146d3acaa07c7176f3fa41607cc8224acdbcd (diff)
parentb08495bbcfea7440f56bbc786b64cbaadaeb604f (diff)
downloadcpython-9f96789cdcb4548ecb9708fe78ffabedecd2d14c.zip
cpython-9f96789cdcb4548ecb9708fe78ffabedecd2d14c.tar.gz
cpython-9f96789cdcb4548ecb9708fe78ffabedecd2d14c.tar.bz2
#17198: merge with 3.3.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_dbm.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/Lib/test/test_dbm.py b/Lib/test/test_dbm.py
index e02fa75..1c57770 100644
--- a/Lib/test/test_dbm.py
+++ b/Lib/test/test_dbm.py
@@ -9,6 +9,11 @@ import test.support
# Skip tests if dbm module doesn't exist.
dbm = test.support.import_module('dbm')
+try:
+ from dbm import ndbm
+except ImportError:
+ ndbm = None
+
_fname = test.support.TESTFN
#
@@ -130,7 +135,7 @@ class WhichDBTestCase(unittest.TestCase):
delete_files()
f = module.open(_fname, 'c')
f.close()
- self.assertEqual(name, dbm.whichdb(_fname))
+ self.assertEqual(name, self.dbm.whichdb(_fname))
# Now add a key
f = module.open(_fname, 'w')
f[b"1"] = b"1"
@@ -139,7 +144,15 @@ class WhichDBTestCase(unittest.TestCase):
# and read it
self.assertTrue(f[b"1"] == b"1")
f.close()
- self.assertEqual(name, dbm.whichdb(_fname))
+ self.assertEqual(name, self.dbm.whichdb(_fname))
+
+ @unittest.skipUnless(ndbm, reason='Test requires ndbm')
+ def test_whichdb_ndbm(self):
+ # Issue 17198: check that ndbm which is referenced in whichdb is defined
+ db_file = '{}_ndbm.db'.format(_fname)
+ with open(db_file, 'w'):
+ self.addCleanup(test.support.unlink, db_file)
+ self.assertIsNone(self.dbm.whichdb(db_file[:-3]))
def tearDown(self):
delete_files()
@@ -149,6 +162,7 @@ class WhichDBTestCase(unittest.TestCase):
self.filename = test.support.TESTFN
self.d = dbm.open(self.filename, 'c')
self.d.close()
+ self.dbm = test.support.import_fresh_module('dbm')
def test_keys(self):
self.d = dbm.open(self.filename, 'c')