Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(13402)

Side by Side Diff: Lib/test/test_bsddb185.py

Issue 5178: Add context manager for temporary directory
Patch Set: Created 9 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/tempfile.py ('k') | Lib/test/test_bsddb3.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Tests for the bsddb185 module. 1 """Tests for the bsddb185 module.
2 2
3 The file 185test.db found in Lib/test/ is for testing purposes with this 3 The file 185test.db found in Lib/test/ is for testing purposes with this
4 testing suite. 4 testing suite.
5 5
6 """ 6 """
7 from test.test_support import run_unittest, findfile, import_module 7 from test.test_support import run_unittest, findfile, import_module
8 import unittest 8 import unittest
9 bsddb185 = import_module('bsddb185', deprecated=True) 9 bsddb185 = import_module('bsddb185', deprecated=True)
10 import anydbm 10 import anydbm
11 import whichdb 11 import whichdb
12 import os 12 import os
13 import tempfile 13 import tempfile
14 import shutil
15 14
16 class Bsddb185Tests(unittest.TestCase): 15 class Bsddb185Tests(unittest.TestCase):
17 16
18 def test_open_existing_hash(self): 17 def test_open_existing_hash(self):
19 # Verify we can open a file known to be a hash v2 file 18 # Verify we can open a file known to be a hash v2 file
20 db = bsddb185.hashopen(findfile("185test.db")) 19 db = bsddb185.hashopen(findfile("185test.db"))
21 self.assertEqual(db["1"], "1") 20 self.assertEqual(db["1"], "1")
22 db.close() 21 db.close()
23 22
24 def test_whichdb(self): 23 def test_whichdb(self):
25 # Verify that whichdb correctly sniffs the known hash v2 file 24 # Verify that whichdb correctly sniffs the known hash v2 file
26 self.assertEqual(whichdb.whichdb(findfile("185test.db")), "bsddb185") 25 self.assertEqual(whichdb.whichdb(findfile("185test.db")), "bsddb185")
27 26
28 def test_anydbm_create(self): 27 def test_anydbm_create(self):
29 # Verify that anydbm.open does *not* create a bsddb185 file 28 # Verify that anydbm.open does *not* create a bsddb185 file
30 tmpdir = tempfile.mkdtemp() 29 with tempfile.TemporaryDirectory() as tmpdir:
31 try:
32 dbfile = os.path.join(tmpdir, "foo.db") 30 dbfile = os.path.join(tmpdir, "foo.db")
33 anydbm.open(dbfile, "c").close() 31 anydbm.open(dbfile, "c").close()
34 ftype = whichdb.whichdb(dbfile) 32 ftype = whichdb.whichdb(dbfile)
35 self.assertNotEqual(ftype, "bsddb185") 33 self.assertNotEqual(ftype, "bsddb185")
36 finally:
37 shutil.rmtree(tmpdir)
38 34
39 def test_main(): 35 def test_main():
40 run_unittest(Bsddb185Tests) 36 run_unittest(Bsddb185Tests)
41 37
42 if __name__ == "__main__": 38 if __name__ == "__main__":
43 test_main() 39 test_main()
OLDNEW
« no previous file with comments | « Lib/tempfile.py ('k') | Lib/test/test_bsddb3.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+