MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / ScenarioDict

Class ScenarioDict

test/utils_shared.py:306–326  ·  view source on GitHub ↗

Dict that returns {} for any unknown key, recursively.

Source from the content-addressed store, hash-verified

304
305
306class ScenarioDict(dict):
307 """Dict that returns {} for any unknown key, recursively."""
308
309 def __init__(self, data):
310 def convert(v):
311 if isinstance(v, abc.Mapping):
312 return ScenarioDict(v)
313 if isinstance(v, (str, bytes)):
314 return v
315 if isinstance(v, abc.Sequence):
316 return [convert(item) for item in v]
317 return v
318
319 dict.__init__(self, [(k, convert(v)) for k, v in data.items()])
320
321 def __getitem__(self, item):
322 try:
323 return dict.__getitem__(self, item)
324 except KeyError:
325 # Unlike a defaultdict, don't set the key, just return a dict.
326 return ScenarioDict({})
327
328
329class CompareType:

Callers 4

_create_testsMethod · 0.90
_create_testsMethod · 0.90
convertMethod · 0.85
__getitem__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected