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

Method test_random

Lib/test/test_dbm_dumb.py:173–193  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

171 # Perform randomized operations. This doesn't make assumptions about
172 # what *might* fail.
173 def test_random(self):
174 import random
175 d = {} # mirror the database
176 for dummy in range(5):
177 with contextlib.closing(dumbdbm.open(_fname)) as f:
178 for dummy in range(100):
179 k = random.choice('abcdefghijklm')
180 if random.random() < 0.2:
181 if k in d:
182 del d[k]
183 del f[k]
184 else:
185 v = random.choice((b'a', b'b', b'c')) * random.randrange(10000)
186 d[k] = v
187 f[k] = v
188 self.assertEqual(f[k], v)
189
190 with contextlib.closing(dumbdbm.open(_fname)) as f:
191 expected = sorted((k.encode("latin-1"), v) for k, v in d.items())
192 got = sorted(f.items())
193 self.assertEqual(expected, got)
194
195 def test_context_manager(self):
196 with dumbdbm.open(_fname, 'c') as db:

Callers

nothing calls this directly

Calls 7

choiceMethod · 0.80
randrangeMethod · 0.80
openMethod · 0.45
randomMethod · 0.45
assertEqualMethod · 0.45
encodeMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected