[Python-checkins] python/dist/src/Lib/test test_shelve.py,NONE,1.1

montanaro@users.sourceforge.net montanaro@users.sourceforge.net
2002年12月08日 10:36:26 -0800


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv2668/Lib/test
Added Files:
	test_shelve.py 
Log Message:
Add support for binary pickles to the shelve module. In some situations
this can result in significantly smaller files. All classes as well as the
open function now accept an optional binary parameter, which defaults to
False for backward compatibility. Added a small test suite, updated the
libref documentation (including documenting the exported classes and fixing
a few other nits) and added a note about the change to Misc/NEWS.
--- NEW FILE: test_shelve.py ---
import os
import unittest
import shelve
import glob
from test import test_support
class TestCase(unittest.TestCase):
 fn = "shelftemp.db"
 
 def test_ascii_file_shelf(self):
 try:
 s = shelve.open(self.fn, binary=False)
 s['key1'] = (1,2,3,4)
 self.assertEqual(s['key1'], (1,2,3,4))
 s.close()
 finally:
 for f in glob.glob(self.fn+"*"):
 os.unlink(f)
 def test_binary_file_shelf(self):
 try:
 s = shelve.open(self.fn, binary=True)
 s['key1'] = (1,2,3,4)
 self.assertEqual(s['key1'], (1,2,3,4))
 s.close()
 finally:
 for f in glob.glob(self.fn+"*"):
 os.unlink(f)
 def test_in_memory_shelf(self):
 d1 = {}
 s = shelve.Shelf(d1, binary=False)
 s['key1'] = (1,2,3,4)
 self.assertEqual(s['key1'], (1,2,3,4))
 s.close()
 d2 = {}
 s = shelve.Shelf(d2, binary=True)
 s['key1'] = (1,2,3,4)
 self.assertEqual(s['key1'], (1,2,3,4))
 s.close()
 self.assertEqual(len(d1), 1)
 self.assertNotEqual(d1, d2)
def test_main():
 test_support.run_unittest(TestCase)
if __name__ == "__main__":
 test_main()

AltStyle によって変換されたページ (->オリジナル) /