MCPcopy Index your code
hub / github.com/python/cpython / test_keys

Method test_keys

Lib/test/test_dbm_ndbm.py:20–38  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

18 os_helper.unlink(self.filename + suffix)
19
20 def test_keys(self):
21 self.d = dbm.ndbm.open(self.filename, 'c')
22 self.assertEqual(self.d.keys(), [])
23 self.d['a'] = 'b'
24 self.d[b'bytes'] = b'data'
25 self.d['12345678910'] = '019237410982340912840198242'
26 self.d.keys()
27 self.assertIn('a', self.d)
28 self.assertIn(b'a', self.d)
29 self.assertEqual(self.d[b'bytes'], b'data')
30 # get() and setdefault() work as in the dict interface
31 self.assertEqual(self.d.get(b'a'), b'b')
32 self.assertIsNone(self.d.get(b'xxx'))
33 self.assertEqual(self.d.get(b'xxx', b'foo'), b'foo')
34 with self.assertRaises(KeyError):
35 self.d['xxx']
36 self.assertEqual(self.d.setdefault(b'xxx', b'foo'), b'foo')
37 self.assertEqual(self.d[b'xxx'], b'foo')
38 self.d.close()
39
40 def test_empty_value(self):
41 if dbm.ndbm.library == 'Berkeley DB':

Callers

nothing calls this directly

Calls 9

assertInMethod · 0.80
assertIsNoneMethod · 0.80
openMethod · 0.45
assertEqualMethod · 0.45
keysMethod · 0.45
getMethod · 0.45
assertRaisesMethod · 0.45
setdefaultMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected