summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_dbm_dumb.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_dbm_dumb.py')
-rw-r--r--Lib/test/test_dbm_dumb.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/Lib/test/test_dbm_dumb.py b/Lib/test/test_dbm_dumb.py
index a481175..672f909 100644
--- a/Lib/test/test_dbm_dumb.py
+++ b/Lib/test/test_dbm_dumb.py
@@ -246,9 +246,27 @@ class DumbDBMTestCase(unittest.TestCase):
_delete_files()
with self.assertRaises(FileNotFoundError):
dumbdbm.open(_fname, value)
+ self.assertFalse(os.path.exists(_fname + '.dat'))
self.assertFalse(os.path.exists(_fname + '.dir'))
self.assertFalse(os.path.exists(_fname + '.bak'))
+ for value in ('c', 'n'):
+ _delete_files()
+ with dumbdbm.open(_fname, value) as f:
+ self.assertTrue(os.path.exists(_fname + '.dat'))
+ self.assertTrue(os.path.exists(_fname + '.dir'))
+ self.assertFalse(os.path.exists(_fname + '.bak'))
+ self.assertFalse(os.path.exists(_fname + '.bak'))
+
+ for value in ('c', 'n'):
+ _delete_files()
+ with dumbdbm.open(_fname, value) as f:
+ f['key'] = 'value'
+ self.assertTrue(os.path.exists(_fname + '.dat'))
+ self.assertTrue(os.path.exists(_fname + '.dir'))
+ self.assertFalse(os.path.exists(_fname + '.bak'))
+ self.assertTrue(os.path.exists(_fname + '.bak'))
+
def test_missing_index(self):
with dumbdbm.open(_fname, 'n') as f:
pass
@@ -259,6 +277,60 @@ class DumbDBMTestCase(unittest.TestCase):
self.assertFalse(os.path.exists(_fname + '.dir'))
self.assertFalse(os.path.exists(_fname + '.bak'))
+ for value in ('c', 'n'):
+ with dumbdbm.open(_fname, value) as f:
+ self.assertTrue(os.path.exists(_fname + '.dir'))
+ self.assertFalse(os.path.exists(_fname + '.bak'))
+ self.assertFalse(os.path.exists(_fname + '.bak'))
+ os.unlink(_fname + '.dir')
+
+ for value in ('c', 'n'):
+ with dumbdbm.open(_fname, value) as f:
+ f['key'] = 'value'
+ self.assertTrue(os.path.exists(_fname + '.dir'))
+ self.assertFalse(os.path.exists(_fname + '.bak'))
+ self.assertTrue(os.path.exists(_fname + '.bak'))
+ os.unlink(_fname + '.dir')
+ os.unlink(_fname + '.bak')
+
+ def test_sync_empty_unmodified(self):
+ with dumbdbm.open(_fname, 'n') as f:
+ pass
+ os.unlink(_fname + '.dir')
+ for value in ('c', 'n'):
+ with dumbdbm.open(_fname, value) as f:
+ self.assertTrue(os.path.exists(_fname + '.dir'))
+ self.assertFalse(os.path.exists(_fname + '.bak'))
+ f.sync()
+ self.assertTrue(os.path.exists(_fname + '.dir'))
+ self.assertFalse(os.path.exists(_fname + '.bak'))
+ os.unlink(_fname + '.dir')
+ f.sync()
+ self.assertFalse(os.path.exists(_fname + '.dir'))
+ self.assertFalse(os.path.exists(_fname + '.bak'))
+ self.assertFalse(os.path.exists(_fname + '.dir'))
+ self.assertFalse(os.path.exists(_fname + '.bak'))
+
+ def test_sync_nonempty_unmodified(self):
+ with dumbdbm.open(_fname, 'n') as f:
+ pass
+ os.unlink(_fname + '.dir')
+ for value in ('c', 'n'):
+ with dumbdbm.open(_fname, value) as f:
+ f['key'] = 'value'
+ self.assertTrue(os.path.exists(_fname + '.dir'))
+ self.assertFalse(os.path.exists(_fname + '.bak'))
+ f.sync()
+ self.assertTrue(os.path.exists(_fname + '.dir'))
+ self.assertTrue(os.path.exists(_fname + '.bak'))
+ os.unlink(_fname + '.dir')
+ os.unlink(_fname + '.bak')
+ f.sync()
+ self.assertFalse(os.path.exists(_fname + '.dir'))
+ self.assertFalse(os.path.exists(_fname + '.bak'))
+ self.assertFalse(os.path.exists(_fname + '.dir'))
+ self.assertFalse(os.path.exists(_fname + '.bak'))
+
def test_invalid_flag(self):
for flag in ('x', 'rf', None):
with self.assertRaisesRegex(ValueError,