Back to index

python3.2  3.2.2
Public Member Functions | Static Public Attributes
test.test_shelve.TestCase Class Reference
Collaboration diagram for test.test_shelve.TestCase:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def tearDown
def test_close
def test_ascii_file_shelf
def test_binary_file_shelf
def test_proto2_file_shelf
def test_in_memory_shelf
def test_mutable_entry
def test_keyencoding
def test_writeback_also_writes_immediately

Static Public Attributes

string fn = "shelftemp.db"

Detailed Description

Definition at line 42 of file test_shelve.py.


Member Function Documentation

Definition at line 46 of file test_shelve.py.

00046 
00047     def tearDown(self):
00048         for f in glob.glob(self.fn+"*"):
00049             support.unlink(f)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 65 of file test_shelve.py.

00065 
00066     def test_ascii_file_shelf(self):
00067         s = shelve.open(self.fn, protocol=0)
00068         try:
00069             s['key1'] = (1,2,3,4)
00070             self.assertEqual(s['key1'], (1,2,3,4))
00071         finally:
00072             s.close()

Here is the call graph for this function:

Definition at line 73 of file test_shelve.py.

00073 
00074     def test_binary_file_shelf(self):
00075         s = shelve.open(self.fn, protocol=1)
00076         try:
00077             s['key1'] = (1,2,3,4)
00078             self.assertEqual(s['key1'], (1,2,3,4))
00079         finally:
00080             s.close()

Here is the call graph for this function:

Definition at line 50 of file test_shelve.py.

00050 
00051     def test_close(self):
00052         d1 = {}
00053         s = shelve.Shelf(d1, protocol=2, writeback=False)
00054         s['key1'] = [1,2,3,4]
00055         self.assertEqual(s['key1'], [1,2,3,4])
00056         self.assertEqual(len(s), 1)
00057         s.close()
00058         self.assertRaises(ValueError, len, s)
00059         try:
00060             s['key1']
00061         except ValueError:
00062             pass
00063         else:
00064             self.fail('Closed shelf should not find a key')

Here is the call graph for this function:

Definition at line 89 of file test_shelve.py.

00089 
00090     def test_in_memory_shelf(self):
00091         d1 = byteskeydict()
00092         s = shelve.Shelf(d1, protocol=0)
00093         s['key1'] = (1,2,3,4)
00094         self.assertEqual(s['key1'], (1,2,3,4))
00095         s.close()
00096         d2 = byteskeydict()
00097         s = shelve.Shelf(d2, protocol=1)
00098         s['key1'] = (1,2,3,4)
00099         self.assertEqual(s['key1'], (1,2,3,4))
00100         s.close()
00101 
00102         self.assertEqual(len(d1), 1)
00103         self.assertEqual(len(d2), 1)
00104         self.assertNotEqual(d1.items(), d2.items())

Here is the call graph for this function:

Definition at line 125 of file test_shelve.py.

00125 
00126     def test_keyencoding(self):
00127         d = {}
00128         key = 'Pöp'
00129         # the default keyencoding is utf-8
00130         shelve.Shelf(d)[key] = [1]
00131         self.assertIn(key.encode('utf-8'), d)
00132         # but a different one can be given
00133         shelve.Shelf(d, keyencoding='latin1')[key] = [1]
00134         self.assertIn(key.encode('latin1'), d)
00135         # with all consequences
00136         s = shelve.Shelf(d, keyencoding='ascii')
00137         self.assertRaises(UnicodeEncodeError, s.__setitem__, key, [1])

Here is the call graph for this function:

Definition at line 105 of file test_shelve.py.

00105 
00106     def test_mutable_entry(self):
00107         d1 = byteskeydict()
00108         s = shelve.Shelf(d1, protocol=2, writeback=False)
00109         s['key1'] = [1,2,3,4]
00110         self.assertEqual(s['key1'], [1,2,3,4])
00111         s['key1'].append(5)
00112         self.assertEqual(s['key1'], [1,2,3,4])
00113         s.close()
00114 
00115         d2 = byteskeydict()
00116         s = shelve.Shelf(d2, protocol=2, writeback=True)
00117         s['key1'] = [1,2,3,4]
00118         self.assertEqual(s['key1'], [1,2,3,4])
00119         s['key1'].append(5)
00120         self.assertEqual(s['key1'], [1,2,3,4,5])
00121         s.close()
00122 
00123         self.assertEqual(len(d1), 1)
00124         self.assertEqual(len(d2), 1)

Here is the call graph for this function:

Definition at line 81 of file test_shelve.py.

00081 
00082     def test_proto2_file_shelf(self):
00083         s = shelve.open(self.fn, protocol=2)
00084         try:
00085             s['key1'] = (1,2,3,4)
00086             self.assertEqual(s['key1'], (1,2,3,4))
00087         finally:
00088             s.close()

Here is the call graph for this function:

Definition at line 138 of file test_shelve.py.

00138 
00139     def test_writeback_also_writes_immediately(self):
00140         # Issue 5754
00141         d = {}
00142         key = 'key'
00143         encodedkey = key.encode('utf-8')
00144         s = shelve.Shelf(d, writeback=True)
00145         s[key] = [1]
00146         p1 = d[encodedkey]  # Will give a KeyError if backing store not updated
00147         s['key'].append(2)
00148         s.close()
00149         p2 = d[encodedkey]
00150         self.assertNotEqual(p1, p2)  # Write creates new object in store
00151 

Here is the call graph for this function:


Member Data Documentation

string test.test_shelve.TestCase.fn = "shelftemp.db" [static]

Definition at line 44 of file test_shelve.py.


The documentation for this class was generated from the following file: