本文整理汇总了Python中unittest.mock.MagicMock.assert_not_called方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.assert_not_called方法的具体用法?Python MagicMock.assert_not_called怎么用?Python MagicMock.assert_not_called使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.assert_not_called方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sm_daemon_receive_message
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_not_called [as 别名]
def test_sm_daemon_receive_message(sm_config, clean_ds_man_mock, delete_queue):
queue_pub = QueuePublisher(sm_config['rabbitmq'], ACTION_QDESC)
msg = {'test': 'message'}
queue_pub.publish(msg)
def callback_side_effect(*args):
print('WITHIN CALLBACK: ', args)
callback = MagicMock()
callback.side_effect = callback_side_effect
on_success = MagicMock()
on_failure = MagicMock()
sm_daemon = SMDaemon(ACTION_QDESC, SMDaemonDatasetManagerMock)
sm_daemon._callback = callback
sm_daemon._on_success = on_success
sm_daemon._on_failure = on_failure
sm_daemon._action_queue_consumer = QueueConsumer(sm_config['rabbitmq'], ACTION_QDESC,
callback, on_success, on_failure,
logger_name='daemon', poll_interval=0.1)
run_sm_daemon(sm_daemon)
callback.assert_called_once_with(msg)
on_success.assert_called_once_with(msg)
on_failure.assert_not_called()
示例2: test_return_immediately_if_scale_is_met
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_not_called [as 别名]
def test_return_immediately_if_scale_is_met(self):
conductr_host = '10.0.0.1'
conductr_host_mock = MagicMock(return_value=conductr_host)
get_events_mock = MagicMock(return_value=[])
get_scale_mock = MagicMock(side_effect=[3])
stdout = MagicMock()
bundle_id = 'a101449418187d92c789d1adc240b6d6'
dcos_mode = False
args = MagicMock(**{
'dcos_mode': dcos_mode,
'wait_timeout': 10,
'conductr_auth': self.conductr_auth,
'server_verification_file': self.server_verification_file
})
with patch('conductr_cli.bundle_scale.get_scale', get_scale_mock), \
patch('conductr_cli.conduct_url.conductr_host', conductr_host_mock), \
patch('conductr_cli.sse_client.get_events', get_events_mock):
logging_setup.configure_logging(args, stdout)
bundle_scale.wait_for_scale(bundle_id, 3, args)
self.assertEqual(get_scale_mock.call_args_list, [
call(bundle_id, args)
])
conductr_host_mock.assert_not_called()
get_events_mock.assert_not_called()
self.assertEqual(strip_margin("""|Bundle a101449418187d92c789d1adc240b6d6 expected scale 3 is met
|"""), self.output(stdout))
示例3: test_multiple
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_not_called [as 别名]
def test_multiple(self):
callback1 = MagicMock(return_value=True)
callback2 = MagicMock(return_value=False)
callback3 = MagicMock(return_value=True)
self.stack.register(callback1)
self.stack.register(callback2)
self.stack(666)
callback1.assert_called_once_with(666)
callback1.reset_mock()
callback2.assert_called_once_with(666)
callback2.reset_mock()
self.stack.register(callback3)
self.stack(666)
callback1.assert_not_called()
callback1.reset_mock()
callback2.assert_not_called()
callback2.reset_mock()
callback3.assert_called_once_with(666)
self.stack.unregister(callback1)
self.stack.unregister(callback3)
self.assertRaises(RuntimeError, self.stack, 666)
callback2.assert_called_once_with(666)
self.stack.unregister(callback2)
self.assertRaises(RuntimeError, self.stack)
示例4: test_vm_type_docker_engine
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_not_called [as 别名]
def test_vm_type_docker_engine(self):
with_docker_machine_mock = MagicMock(return_value="result")
with patch("conductr_cli.host.with_docker_machine", with_docker_machine_mock):
result = host.resolve_ip_by_vm_type(DockerVmType.DOCKER_ENGINE)
self.assertEqual(result, "127.0.0.1")
with_docker_machine_mock.assert_not_called()
示例5: test_bintray_version_found
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_not_called [as 别名]
def test_bintray_version_found(self):
exists_mock = MagicMock(return_value=False)
load_bintray_credentials_mock = MagicMock(return_value=('username', 'password'))
parse_bundle_configuration_mock = MagicMock(return_value=('urn:x-bundle:', 'typesafe', 'bundle-configuration',
'bundle-name', 'v1', 'digest'))
bintray_resolve_version_mock = MagicMock(return_value={
'org': 'typesafe',
'repo': 'bundle-configuration',
'package_name': 'bundle-name',
'compatibility_version': 'v1',
'digest': 'digest',
'path': 'download.zip'
})
load_bundle_from_cache_mock = MagicMock(return_value=(True, 'bundle-name', 'mock bundle file'))
with patch('os.path.exists', exists_mock), \
patch('conductr_cli.resolvers.bintray_resolver.load_bintray_credentials', load_bintray_credentials_mock), \
patch('conductr_cli.bundle_shorthand.parse_bundle_configuration', parse_bundle_configuration_mock), \
patch('conductr_cli.resolvers.bintray_resolver.bintray_resolve_version', bintray_resolve_version_mock), \
patch('conductr_cli.resolvers.bintray_resolver.uri_resolver.load_bundle_from_cache',
load_bundle_from_cache_mock):
is_resolved, bundle_name, bundle_file = bintray_resolver.load_bundle_configuration_from_cache(
'/cache-dir', 'bundle-name:v1')
self.assertTrue(is_resolved)
self.assertEqual('bundle-name', bundle_name)
self.assertEqual('mock bundle file', bundle_file)
exists_mock.assert_not_called()
load_bintray_credentials_mock.assert_called_with()
parse_bundle_configuration_mock.assert_called_with('bundle-name:v1')
bintray_resolve_version_mock.assert_called_with('username', 'password', 'typesafe', 'bundle-configuration',
'bundle-name', 'v1', 'digest')
load_bundle_from_cache_mock.assert_called_with('/cache-dir',
'https://dl.bintray.com/typesafe/bundle-configuration/download.zip')
示例6: test_no_wait
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_not_called [as 别名]
def test_no_wait(self):
stdout = MagicMock()
mock_wait_for_conductr = MagicMock()
with \
patch('conductr_cli.terminal.docker_images', return_value=''), \
patch('conductr_cli.terminal.docker_pull', return_value=''), \
patch('conductr_cli.terminal.docker_ps', return_value=''), \
patch('conductr_cli.terminal.docker_inspect', return_value='10.10.10.10'), \
patch('conductr_cli.terminal.docker_run', return_value='') as mock_docker_run, \
patch('conductr_cli.sandbox_common.resolve_running_docker_containers', return_value=[]), \
patch('conductr_cli.sandbox_run.wait_for_conductr', mock_wait_for_conductr):
args = self.default_args.copy()
args.update({'no_wait': True})
input_args = MagicMock(**args)
logging_setup.configure_logging(input_args, stdout)
sandbox_run.run(input_args)
expected_stdout = strip_margin("""|Pulling down the ConductR development image..
||------------------------------------------------|
|| Starting ConductR |
||------------------------------------------------|
|Starting container cond-0..
|""")
expected_optional_args = self.default_general_args('cond-0') + self.default_env_args + self.default_port_args
expected_image = '{}:{}'.format(CONDUCTR_DEV_IMAGE, LATEST_CONDUCTR_VERSION)
expected_positional_args = self.default_positional_args
self.assertEqual(expected_stdout, self.output(stdout))
mock_docker_run.assert_called_once_with(expected_optional_args, expected_image, expected_positional_args)
mock_wait_for_conductr.assert_not_called()
示例7: test_create_dir
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_not_called [as 别名]
def test_create_dir(self):
args = MagicMock()
stdout = MagicMock()
remove = MagicMock()
makedirs = MagicMock()
symlink = MagicMock()
logging_setup.configure_logging(args, stdout)
with patch('shutil.which', lambda x: '/somefile'), \
patch('os.path.exists', lambda x: False), \
patch('os.remove', remove), \
patch('os.makedirs', makedirs), \
patch('os.symlink', symlink):
result = conduct_dcos.setup(args)
self.assertTrue(result)
remove.assert_not_called()
makedirs.assert_called_with('{}/.dcos/subcommands/conductr/env/bin'.format(os.path.expanduser('~')),
exist_ok=True)
symlink.assert_called_with('/somefile',
'{}/.dcos/subcommands/conductr/env/bin/dcos-conduct'.format(os.path.expanduser('~')))
self.assertEqual(
strip_margin("""|The DC/OS CLI is now configured.
|Prefix \'conduct\' with \'dcos\' when you want to contact ConductR on DC/OS e.g. \'dcos conduct info\'
|"""),
self.output(stdout))
示例8: test_get_credentials_from_storage
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_not_called [as 别名]
def test_get_credentials_from_storage(self):
credentials = Credentials(invalid=False)
self._storage.get = MagicMock(return_value=credentials)
run_flow = MagicMock()
auth = Authenticator(self._storage, run_flow)
assert auth.get_credentials({}) == credentials
run_flow.assert_not_called()
示例9: _test_vertical_bottom
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_not_called [as 别名]
async def _test_vertical_bottom():
now = 0
effector = MagicMock()
there = Path(__file__).parent / "independent_config.yaml"
with open(there) as from_there:
zone_config = yaml.load(from_there)
zone = LightZone(effector, zone_config)
await zone.setup()
effector.assert_called_once()
commands = effector.call_args[0][0]
assert (len(commands) == 3)
assert ({x[0] for x in commands} == {'l'})
assert ({x[1] for x in commands} == {2, 3, 6})
assert ({x[2] for x in commands} == {'on'})
assert ({x[3] for x in commands} == {False})
effector.reset_mock()
#
# bottom sensor sees motion
#
await zone.on_event({
"deviceId": "a20bab2e-a7d0-4c93-8723-27a7bf3299b6",
"attribute": "motion",
"value": "active",
}, now)
effector.assert_called_once()
commands = effector.call_args[0][0]
assert (len(commands) == 2)
assert ({x[0] for x in commands} == {'l'})
assert ({x[1] for x in commands} == {3, 6})
assert ({x[2] for x in commands} == {'on'})
assert ({x[3] for x in commands} == {True})
effector.reset_mock()
await zone.on_tick(25)
effector.assert_not_called()
await zone.on_tick(35)
effector.assert_called_once()
commands = effector.call_args[0][0]
assert (len(commands) == 1)
assert (commands[0] == ('l',3,'on',False))
effector.reset_mock()
await zone.on_event({
"deviceId": "a20bab2e-a7d0-4c93-8723-27a7bf3299b6",
"attribute": "motion",
"value": "inactive",
}, 100)
await zone.on_tick(299)
effector.assert_not_called()
await zone.on_tick(301)
effector.assert_called_once()
commands = effector.call_args[0][0]
assert (len(commands) == 1)
assert (commands[0] == ('l',6,'on',False))
effector.reset_mock()
示例10: test_setup_platform_no_bridge_id
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_not_called [as 别名]
def test_setup_platform_no_bridge_id(self):
"""Test setup_platform without a bridge."""
self.hass.data[hue.DOMAIN] = {}
mock_add_devices = MagicMock()
hue_light.setup_platform(self.hass, {}, mock_add_devices, {})
mock_add_devices.assert_not_called()
示例11: test_setup_platform_no_discovery_info
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_not_called [as 别名]
def test_setup_platform_no_discovery_info(self):
"""Test setup_platform without discovery info."""
self.hass.data[hue.DOMAIN] = {}
mock_add_devices = MagicMock()
hue_light.setup_platform(self.hass, {}, mock_add_devices)
mock_add_devices.assert_not_called()
示例12: test_bundle
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_not_called [as 别名]
def test_bundle(self):
exists_mock = MagicMock(return_value=False)
bintray_download_det_mock = MagicMock(return_value=(None, None))
with patch('os.path.exists', exists_mock), \
patch('conductr_cli.resolvers.bintray_resolver.bintray_download_details', bintray_download_det_mock):
bintray_resolver.load_bundle_from_cache(
'/cache-dir', '/tmp/bundle')
exists_mock.assert_not_called()
示例13: test_unset_credentials
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_not_called [as 别名]
def test_unset_credentials(self):
serializer = MagicMock()
encryption = MagicMock()
storage = MagicMock()
store = Store('name', serializer, encryption, storage)
store.unset_credentials('user')
storage.unset_data.assert_called_with('user')
serializer.assert_not_called()
encryption.assert_not_called()
示例14: test_update_ds__configs_metadata_equal__do_nothing
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_not_called [as 别名]
def test_update_ds__configs_metadata_equal__do_nothing(self, fill_db, sm_config, ds_config):
action_queue_mock = MagicMock(spec=QueuePublisher)
ds_man = create_ds_man(sm_config, action_queue=action_queue_mock, sm_api=True)
ds_id = '2000-01-01'
ds = create_ds(ds_id=ds_id, ds_config=ds_config)
ds_man.update(ds)
action_queue_mock.assert_not_called()
示例15: test_file
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_not_called [as 别名]
def test_file(self):
exists_mock = MagicMock()
with patch('os.path.exists', exists_mock):
is_resolved, bundle_name, bundle_file = uri_resolver.load_bundle_from_cache('/cache-dir', '/tmp/bundle.zip')
self.assertFalse(is_resolved)
self.assertIsNone(bundle_name)
self.assertIsNone(bundle_file)
exists_mock.assert_not_called()