def _create_client(self): mock = MagicMock(name='client') # we need new mock object for every collection def get_collection(name): try: return self.collections[name] except KeyError: mock = self.collections[name] = MagicMock( name='collection:%s' % name) return mock mock.__getitem__.side_effect = get_collection return mock
def test_loads_DecodeError(self): _loads = Mock(name='_loads') _loads.side_effect = _DecodeError(MagicMock(), MagicMock(), MagicMock()) self.assertEqual(loads(dumps({'x': 'z'}), _loads=_loads), {'x': 'z'})