summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_dbm_ndbm.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_dbm_ndbm.py')
-rwxr-xr-xLib/test/test_dbm_ndbm.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/Lib/test/test_dbm_ndbm.py b/Lib/test/test_dbm_ndbm.py
new file mode 100755
index 0000000..74d3238
--- /dev/null
+++ b/Lib/test/test_dbm_ndbm.py
@@ -0,0 +1,40 @@
+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['12345678910'] = '019237410982340912840198242'
+ self.d.keys()
+ self.assert_(b'a' in self.d)
+ 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()