Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _save_expectation(self, name, return_value=None):
if name in [x.name for x in
FlexmockContainer.flexmock_objects[self]]:
expectation = [x for x in FlexmockContainer.flexmock_objects[self]
if x.name == name][0]
expectation = Expectation(
self._object, name=name, return_value=return_value,
original=expectation.__dict__.get('original'))
else:
expectation = Expectation(
self._object, name=name, return_value=return_value)
return expectation
def _retrieve_or_create_expectation(self, method, return_value=None):
if method in [x.method for x in FlexmockContainer.flexmock_objects[self]]:
expectation = [x for x in FlexmockContainer.flexmock_objects[self]
if x.method == method][0]
expectation = Expectation(
self._object, name=method, return_value=return_value,
original_method=expectation.original_method)
else:
expectation = Expectation(
self._object, name=method, return_value=return_value)
return expectation
def _create_placeholder_mock_for_proper_teardown(self, obj, name, original):
"""Ensures that the given function is replaced on teardown."""
mock = Mock()
mock._object = obj
expectation = Expectation(obj, name=name, original=original)
FlexmockContainer.add_expectation(mock, expectation)
def _save_expectation(self, name, return_value=None):
if name in [x.name for x in
FlexmockContainer.flexmock_objects[self]]:
expectation = [x for x in FlexmockContainer.flexmock_objects[self]
if x.name == name][0]
expectation = Expectation(
self._object, name=name, return_value=return_value,
original=expectation.__dict__.get('original'))
else:
expectation = Expectation(
self._object, name=name, return_value=return_value)
return expectation
def _retrieve_or_create_expectation(self, method, return_value=None):
if method in [x.method for x in FlexmockContainer.flexmock_objects[self]]:
expectation = [x for x in FlexmockContainer.flexmock_objects[self]
if x.method == method][0]
expectation = Expectation(
self._object, name=method, return_value=return_value,
original_method=expectation.original_method)
else:
expectation = Expectation(
self._object, name=method, return_value=return_value)
return expectation