mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
This test left a new set of 3 junk files behind each time it was run.
This commit is contained in:
parent
c48a3ca161
commit
d9fbf353a1
1 changed files with 18 additions and 11 deletions
|
@ -9,8 +9,16 @@ import unittest
|
||||||
import dumbdbm
|
import dumbdbm
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
|
_fname = tempfile.mktemp()
|
||||||
|
|
||||||
|
def _delete_files():
|
||||||
|
for ext in [".dir", ".dat", ".bak"]:
|
||||||
|
try:
|
||||||
|
os.unlink(_fname + ext)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
class DumbDBMTestCase(unittest.TestCase):
|
class DumbDBMTestCase(unittest.TestCase):
|
||||||
_fname = tempfile.mktemp()
|
|
||||||
_dict = {'0': '',
|
_dict = {'0': '',
|
||||||
'a': 'Python:',
|
'a': 'Python:',
|
||||||
'b': 'Programming',
|
'b': 'Programming',
|
||||||
|
@ -26,11 +34,8 @@ class DumbDBMTestCase(unittest.TestCase):
|
||||||
self._dkeys.sort()
|
self._dkeys.sort()
|
||||||
|
|
||||||
def test_dumbdbm_creation(self):
|
def test_dumbdbm_creation(self):
|
||||||
for ext in [".dir", ".dat", ".bak"]:
|
_delete_files()
|
||||||
try: os.unlink(self._fname+ext)
|
f = dumbdbm.open(_fname, 'c')
|
||||||
except OSError: pass
|
|
||||||
|
|
||||||
f = dumbdbm.open(self._fname, 'c')
|
|
||||||
self.assertEqual(f.keys(), [])
|
self.assertEqual(f.keys(), [])
|
||||||
for key in self._dict:
|
for key in self._dict:
|
||||||
f[key] = self._dict[key]
|
f[key] = self._dict[key]
|
||||||
|
@ -38,18 +43,18 @@ class DumbDBMTestCase(unittest.TestCase):
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
def test_dumbdbm_modification(self):
|
def test_dumbdbm_modification(self):
|
||||||
f = dumbdbm.open(self._fname, 'w')
|
f = dumbdbm.open(_fname, 'w')
|
||||||
self._dict['g'] = f['g'] = "indented"
|
self._dict['g'] = f['g'] = "indented"
|
||||||
self.read_helper(f)
|
self.read_helper(f)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
def test_dumbdbm_read(self):
|
def test_dumbdbm_read(self):
|
||||||
f = dumbdbm.open(self._fname, 'r')
|
f = dumbdbm.open(_fname, 'r')
|
||||||
self.read_helper(f)
|
self.read_helper(f)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
def test_dumbdbm_keys(self):
|
def test_dumbdbm_keys(self):
|
||||||
f = dumbdbm.open(self._fname)
|
f = dumbdbm.open(_fname)
|
||||||
keys = self.keys_helper(f)
|
keys = self.keys_helper(f)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
@ -65,8 +70,10 @@ class DumbDBMTestCase(unittest.TestCase):
|
||||||
return keys
|
return keys
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
|
try:
|
||||||
test_support.run_unittest(DumbDBMTestCase)
|
test_support.run_unittest(DumbDBMTestCase)
|
||||||
|
finally:
|
||||||
|
_delete_files()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_main()
|
test_main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue