本文整理汇总了Python中mock.MagicMock.assert_not_called方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.assert_not_called方法的具体用法?Python MagicMock.assert_not_called怎么用?Python MagicMock.assert_not_called使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.assert_not_called方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ensure_webhook_notouch
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_not_called [as 别名]
def test_ensure_webhook_notouch(self):
testee = self.get_testee()
dest=MagicMock()
def replacement_api(path,form_data={},method=None,request_type=None):
if path.endswith('/hooks') and (method=='GET' or method is None):
return [
{
"id": 1,
"url": "https://api.github.com/repos/octocat/Hello-World/hooks/1",
"test_url": "https://api.github.com/repos/octocat/Hello-World/hooks/1/test",
"ping_url": "https://api.github.com/repos/octocat/Hello-World/hooks/1/pings",
"name": "web",
"events": [
"push",
"issue_comment"
],
"active": True,
"config": {
"url": "http://me.com",
"content_type": "json"
},
"updated_at": "2011-09-06T20:39:23Z",
"created_at": "2011-09-06T17:26:27Z"
}
]
else:
return dest(path,form_data=form_data,method=method,request_type=request_type)
testee.api = replacement_api
testee.ensure_webhook('octocat','Hello-World','http://me.com')
dest.assert_not_called()
示例2: TestLocalFileSystem
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_not_called [as 别名]
class TestLocalFileSystem(LogTestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.first_receiver = MagicMock(spec=ActorRef)
self.second_receiver = MagicMock(spec=ActorRef)
self.lfs = LocalFileSystem.start([self.first_receiver, self.second_receiver],
self.tmpdir, TEST_RELOAD_LOCAL_FILES_SEC)
def tearDown(self):
self.lfs.stop()
shutil.rmtree(self.tmpdir)
def addFile(self, filenames):
for filename in filenames:
with open(self.tmpdir + "/" + filename, "w") as f:
f.write("FOOBAR")
def test_add_one_file_in_folder(self):
self.first_receiver.assert_not_called()
self.second_receiver.assert_not_called()
new_file = ['some_file_test1.txt']
self.addFile(new_file)
sleep(TEST_WAIT)
self.first_receiver.tell.assert_called_once_with(local_files_message(new_file))
self.second_receiver.tell.assert_called_once_with(local_files_message(new_file))
def test_add_three_files_in_folder(self):
new_files = ['some_file_test2.txt', 'some_file2_test2.txt', 'some_file3_test2.txt']
self.addFile(new_files)
sleep(TEST_WAIT)
self.first_receiver.tell.assert_called_with(local_files_message(AllItemsIn(new_files)))
self.second_receiver.tell.assert_called_with(local_files_message(AllItemsIn(new_files)))
示例3: test_missing_collection_harvest
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_not_called [as 别名]
def test_missing_collection_harvest(self, mock_rabbit_worker_class):
mock_rabbit_worker = MagicMock(spec=RabbitWorker)
mock_rabbit_worker_class.side_effect = [mock_rabbit_worker]
# Error should be logged and nothing happens
collection_harvest(1234567)
mock_rabbit_worker.assert_not_called()
示例4: test_packet_action
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_not_called [as 别名]
def test_packet_action(self):
# Callback must be callable
with self.assertRaises(TypeError):
self.environment.add_packet_action("waypoint_add", "no_function")
mock_callback = MagicMock()
self.environment.add_packet_action("waypoint_add", mock_callback)
# Not allowed to add more than one callback for a packet specification.
with self.assertRaises(KeyError):
self.environment.add_packet_action("waypoint_add", MagicMock())
# Callback is called for correct specification.
packet = Packet()
packet.set("specification", "waypoint_add")
packet.set("latitude", 12.345)
packet.set("longitude", 32.109)
packet.set("to_id", 1)
self.environment.receive_packet(packet)
mock_callback.assert_called_once_with(packet)
# Callback is not called for another specification.
mock_callback.reset_mock()
packet = Packet()
packet.set("specification", "waypoint_clear")
packet.set("to_id", 1)
self.environment.receive_packet(packet)
mock_callback.assert_not_called()
示例5: test_skip_send_after_void
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_not_called [as 别名]
def test_skip_send_after_void(self, mock_rabbit_worker_class):
collection = Collection.objects.create(
collection_set=self.collection_set,
credential=self.credential,
harvest_type=Collection.TWITTER_SAMPLE,
name="test_collection",
harvest_options=json.dumps(self.harvest_options),
is_active=True,
)
Harvest.objects.create(
collection=collection,
historical_collection=collection.history.all()[0],
historical_credential=self.credential.history.all()[0],
status=Harvest.VOIDED,
)
mock_rabbit_worker = MagicMock(spec=RabbitWorker)
mock_rabbit_worker_class.side_effect = [mock_rabbit_worker]
collection_harvest(collection.id)
# Last harvest voided, so this one should be sent.
# Harvest start message sent
mock_rabbit_worker.assert_not_called()
# Harvest start message sent
name, args, kwargs = mock_rabbit_worker.mock_calls[0]
self.assertEqual("send_message", name)
message = args[0]
# Harvest model object created
harvest = Harvest.objects.get(harvest_id=message["id"])
self.assertEqual(Harvest.REQUESTED, harvest.status)
示例6: test_discover
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_not_called [as 别名]
def test_discover(self, bind_mock):
bind_mock.configure_mock(side_effect=socket.error(errno.EADDRINUSE, "port in use"))
callback_mock = MagicMock()
self.rf_sensor.discover(callback_mock)
bind_calls = bind_mock.call_args_list
callback_calls = callback_mock.call_args_list
self.assertEqual(len(bind_calls), self.rf_sensor.number_of_sensors)
self.assertEqual(len(callback_calls), self.rf_sensor.number_of_sensors)
# Each vehicle must be checked whether its port is in use, and
# successfully report the identity of its RF sensor in order.
for vehicle_id in xrange(1, self.rf_sensor.number_of_sensors + 1):
expected_address = (self.rf_sensor._ip,
self.rf_sensor._port + vehicle_id)
address = bind_calls.pop(0)[0][0]
self.assertEqual(address, expected_address)
response = callback_calls.pop(0)[0][0]
self.assertEqual(response, {
"id": vehicle_id,
"address": "{}:{}".format(*expected_address)
})
callback_mock.reset_mock()
bind_mock.reset_mock()
bind_mock.configure_mock(side_effect=None)
self.rf_sensor.discover(callback_mock, required_sensors=set([1]))
bind_mock.assert_called_once_with((self.rf_sensor._ip, self.rf_sensor._port + 1))
callback_mock.assert_not_called()
示例7: test_aws_relationship_external
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_not_called [as 别名]
def test_aws_relationship_external(self):
fake_class_instance = MagicMock()
FakeClass = MagicMock(return_value=fake_class_instance)
mock_func = MagicMock()
@decorators.aws_relationship(class_decl=FakeClass)
def test_with_mock(*args, **kwargs):
mock_func(*args, **kwargs)
_ctx = self._gen_decorators_realation_context(test_properties={
'use_external_resource': True
})
test_with_mock(ctx=_ctx)
mock_func.assert_not_called()
# force run
test_with_mock(ctx=_ctx, force_operation=True)
mock_func.assert_called_with(
ctx=_ctx,
iface=fake_class_instance, resource_config={},
force_operation=True, resource_type='AWS Resource')
示例8: test_skip_send
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_not_called [as 别名]
def test_skip_send(self, mock_rabbit_worker_class):
collection = Collection.objects.create(
collection_set=self.collection_set,
credential=self.credential,
harvest_type=Collection.TWITTER_SAMPLE,
name="test_collection",
harvest_options=json.dumps(self.harvest_options),
is_active=True,
)
Harvest.objects.create(
collection=collection,
historical_collection=collection.history.all()[0],
historical_credential=self.credential.history.all()[0],
)
mock_rabbit_worker = MagicMock(spec=RabbitWorker)
mock_rabbit_worker_class.side_effect = [mock_rabbit_worker]
collection_harvest(collection.id)
# Last harvest isn't done, so skip this harvest.
# Harvest start message not sent
mock_rabbit_worker.assert_not_called()
# Harvest model object created
harvest = collection.last_harvest(include_skipped=True)
self.assertEqual(Harvest.SKIPPED, harvest.status)
示例9: test_main
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_not_called [as 别名]
def test_main(self):
init1_call = MagicMock()
init2_call = MagicMock()
class SomeClass(object):
__metaclass__ = MutexInitMeta
@subinit
def init1(self, param1, param2):
init1_call()
@subinit
def init2(self, param2, param3):
init2_call()
obj = SomeClass(param1=0, param2=0)
init1_call.assert_called_once_with()
init2_call.assert_not_called()
obj = SomeClass(param2=0, param3=0)
init1_call.assert_called_once_with() # This is the previous call
init2_call.assert_called_once_with()
self.assertRaises(AttributeError, SomeClass, blablabla=0)
init1_call.assert_called_once_with() # This is the previous call again
init2_call.assert_called_once_with() # This is the previous call
self.assertRaises(AttributeError, SomeClass, param1=None, param2=0)
init1_call.assert_called_once_with() # This is the previous call
init2_call.assert_called_once_with() # This is the previous call
示例10: AttachVersionArgumentUnitTests
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_not_called [as 别名]
class AttachVersionArgumentUnitTests(SubcommandTestCase):
COLOR = MagicMock()
def setUp(self):
SubcommandTestCase.setUp(self)
color_output_patcher = patch(
'gitflow_easyrelease.subcommand.ColorOutput',
return_value=self.COLOR
)
self.mock_color_output = color_output_patcher.start()
self.addCleanup(color_output_patcher.stop)
self.mock_add = MagicMock()
self.parser = MagicMock(add_argument=self.mock_add)
def test_color_output(self):
self.mock_color_output.assert_not_called()
Subcommand.attach_version_argument(
self.parser,
self.subcommand.version_optional
)
self.mock_color_output.assert_called_once_with()
def test_add_call(self):
self.mock_add.assert_not_called()
Subcommand.attach_version_argument(
self.parser,
self.subcommand.version_optional
)
self.mock_add.assert_called_once()
示例11: OnCompleteDone_NoActionIfNotDone_test
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_not_called [as 别名]
def OnCompleteDone_NoActionIfNotDone_test( *args ):
request = CompletionRequest( None )
request.Done = MagicMock( return_value = False )
action = MagicMock()
request._complete_done_hooks[ 'ycmtest' ] = action
request.OnCompleteDone()
action.assert_not_called()
示例12: test_check_jobs
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_not_called [as 别名]
def test_check_jobs(jobResetAgent):
"""Test for checkJobs function."""
jobIDs = [1, 2]
dummy_treatJobWithNoReq = MagicMock()
dummy_treatJobWithReq = MagicMock()
# if the readRequestsForJobs func returns error than checkJobs should exit and return an error
jobResetAgent.reqClient.readRequestsForJobs.return_value = S_ERROR()
res = jobResetAgent.checkJobs(jobIDs, treatJobWithNoReq=dummy_treatJobWithNoReq,
treatJobWithReq=dummy_treatJobWithReq)
assert not res["OK"]
# test if correct treatment functions are called
jobResetAgent.reqClient.readRequestsForJobs.return_value = S_OK({'Successful': {},
'Failed': {jobIDs[0]: 'Request not found'}})
jobResetAgent.checkJobs(jobIDs, treatJobWithNoReq=dummy_treatJobWithNoReq,
treatJobWithReq=dummy_treatJobWithReq)
dummy_treatJobWithNoReq.assert_has_calls([call(jobIDs[0]), call(jobIDs[1])])
dummy_treatJobWithReq.assert_not_called()
dummy_treatJobWithNoReq.reset_mock()
req1 = Request({"RequestID": 1})
req2 = Request({"RequestID": 2})
jobResetAgent.reqClient.readRequestsForJobs.return_value = S_OK({'Successful': {jobIDs[0]: req1,
jobIDs[1]: req2},
'Failed': {}})
jobResetAgent.checkJobs(jobIDs, treatJobWithNoReq=dummy_treatJobWithNoReq,
treatJobWithReq=dummy_treatJobWithReq)
dummy_treatJobWithNoReq.assert_not_called()
dummy_treatJobWithReq.assert_has_calls([call(jobIDs[0], req1), call(jobIDs[1], req2)])
示例13: test_disabled
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_not_called [as 别名]
def test_disabled(self, mock_django_timezone: mock.MagicMock,
mock_queue_digest_recipient: mock.MagicMock) -> None:
cutoff = timezone_now()
# A Tuesday
mock_django_timezone.return_value = datetime.datetime(year=2016, month=1, day=5)
enqueue_emails(cutoff)
mock_queue_digest_recipient.assert_not_called()
示例14: test_stop_bofore_execute
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_not_called [as 别名]
def test_stop_bofore_execute(self):
execute_mock = MagicMock()
self.trackers_manager.execute = execute_mock
self.create_runner()
self.stop_runner()
execute_mock.assert_not_called()
示例15: test_add_exists_without_force
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_not_called [as 别名]
def test_add_exists_without_force():
fs = test_add_success()
dummy_uploader = MagicMock(return_value=MagicMock(ids=hashIds2, size=327))
adder = add.AddController(fs, dummy_uploader)
with assert_raises(add.FileExistsError):
adder("Movies/midsummer.mp4", mtime=0)
dummy_uploader.assert_not_called()
assert_equal(adder.added, set())