本文整理汇总了Python中mockito.any函数的典型用法代码示例。如果您正苦于以下问题:Python any函数的具体用法?Python any怎么用?Python any使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了any函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_skip_song_if_any_filter_should_filter
def test_skip_song_if_any_filter_should_filter(self):
self.create_file_in(self.SOURCE_PATH)
f = mock()
when(f).should_filter(any()).thenReturn(True)
self.ms.filters = [f]
self.ms.sync()
verify(self.file_operator_mock, never).copyfile(any(), any())
示例2: test_backup_incremental_metadata
def test_backup_incremental_metadata(self):
when(backupagent).get_storage_strategy(any(), any()).thenReturn(
MockSwift)
MockStorage.save_metadata = Mock()
when(MockSwift).load_metadata(any(), any()).thenReturn(
{'lsn': '54321'})
meta = {
'lsn': '12345',
'parent_location': 'fake',
'parent_checksum': 'md5',
}
when(mysql_impl.InnoBackupExIncremental).metadata().thenReturn(meta)
when(mysql_impl.InnoBackupExIncremental).check_process().thenReturn(
True)
agent = backupagent.BackupAgent()
bkup_info = {'id': '123',
'location': 'fake-location',
'type': 'InnoBackupEx',
'checksum': 'fake-checksum',
'parent': {'location': 'fake', 'checksum': 'md5'}
}
agent.execute_backup(TroveContext(), bkup_info, '/var/lib/mysql')
self.assertTrue(MockStorage.save_metadata.called_once_with(
any(),
meta))
示例3: test_random_walk_classical
def test_random_walk_classical(self):
methods = RandomWalkMethods()
#given
graph = mockito.mock(nx.MultiGraph)
edgesData, nodes, nodeList = utils.prepareNodesAndEdges()
edgesList = utils.prepareEdgesList(edgesData, nodeList)
class_mat = utils.prepareTestClassMatWithUnknownNodes()
default_class_mat = utils.prepareTestClassMat()
mockito.when(graph).edges_iter(mockito.any(), data=True)\
.thenReturn(utils.generateEdges(10, nodeList, edgesData))\
.thenReturn(utils.generateEdges(10, nodeList, edgesData))\
.thenReturn(utils.generateEdges(10, nodeList, edgesData))\
.thenReturn(utils.generateEdges(10, nodeList, edgesData))\
.thenReturn(utils.generateEdges(10, nodeList, edgesData))
mockito.when(graph).edges_iter(mockito.any())\
.thenReturn(utils.generateEdges(10, nodeList, edgesData))\
.thenReturn(utils.generateEdges(10, nodeList, edgesData))\
.thenReturn(utils.generateEdges(10, nodeList, edgesData))\
.thenReturn(utils.generateEdges(10, nodeList, edgesData))\
.thenReturn(utils.generateEdges(10, nodeList, edgesData))
mockito.when(graph).edges(data=True).thenReturn(edgesList)
mockito.when(graph).nodes().thenReturn(nodes)
result = methods.random_walk_classical(graph, default_class_mat, [1, 2], 5, 1)
assert result.__len__() == 5
示例4: test_check_for_heartbeat_negative
def test_check_for_heartbeat_negative(self):
# TODO (juice) maybe it would be ok to extend the test to validate
# the is_active method on the heartbeat
when(db_models.DatabaseModelBase).find_by(
instance_id=any()).thenReturn('agent')
when(agent_models.AgentHeartBeat).is_active(any()).thenReturn(False)
self.assertRaises(exception.GuestTimeout, self.api._check_for_hearbeat)
示例5: test_ensure_after_action_teardown_is_executed_and_suppresses
def test_ensure_after_action_teardown_is_executed_and_suppresses(self):
task = mock(name="task", dependencies=[])
when(task).execute(any(), {}).thenRaise(ValueError("simulated task error"))
action_teardown1 = mock(name="action_teardown1", execute_before=[], execute_after=["task"], teardown=True,
source="task")
when(action_teardown1).execute({}).thenRaise(ValueError("simulated action error teardown1"))
action_teardown2 = mock(name="action_teardown2", execute_before=[], execute_after=["task"], teardown=True,
source="task")
self.execution_manager.register_action(action_teardown1)
self.execution_manager.register_action(action_teardown2)
self.execution_manager.register_task(task)
self.execution_manager.resolve_dependencies()
try:
self.execution_manager.execute_task(task)
self.assertTrue(False, "should not have reached here")
except Exception as e:
self.assertEquals(type(e), ValueError)
self.assertEquals(str(e), "simulated task error")
verify(task).execute(any(), {})
verify(action_teardown1).execute({})
verify(action_teardown2).execute({})
verify(self.execution_manager.logger).error(
"Executing action '%s' from '%s' resulted in an error that was suppressed:\n%s", "action_teardown1",
"task", any())
示例6: test_RunlistRemoveAction
def test_RunlistRemoveAction(self):
storage = mock()
action = runlist.Remove(storage, **{'name': 'RunlistName'})
when(storage).remove(any(str), any(str)).thenReturn(Chain([lambda: 'Ok']))
action.execute().get()
verify(storage).remove('runlists', 'RunlistName')
示例7: test_public_exists_events
def test_public_exists_events(self):
status = ServiceStatuses.BUILDING.api_status
db_instance = DBInstance(
InstanceTasks.BUILDING,
created="xyz",
name="test_name",
id="1",
flavor_id="flavor_1",
compute_instance_id="compute_id_1",
server_id="server_id_1",
tenant_id="tenant_id_1",
server_status=status,
)
server = mock(Server)
server.user_id = "test_user_id"
mgmt_instance = SimpleMgmtInstance(self.context, db_instance, server, None)
when(mgmtmodels).load_mgmt_instances(self.context, deleted=False, client=self.client).thenReturn(
[mgmt_instance, mgmt_instance]
)
flavor = mock(Flavor)
flavor.name = "db.small"
when(self.flavor_mgr).get("flavor_1").thenReturn(flavor)
self.assertThat(self.context.auth_token, Is("some_secret_password"))
when(notifier).notify(self.context, any(str), "trove.instance.exists", "INFO", any(dict)).thenReturn(None)
# invocation
mgmtmodels.publish_exist_events(NovaNotificationTransformer(context=self.context), self.context)
# assertion
verify(notifier, times=2).notify(self.context, any(str), "trove.instance.exists", "INFO", any(dict))
self.assertThat(self.context.auth_token, Is(None))
示例8: test_RunlistViewAction
def test_RunlistViewAction(self):
storage = mock()
action = RunlistViewAction(storage, **{'name': 'RunlistName'})
when(storage).read(any(str), any(str)).thenReturn(ChainFactory([lambda: 'Ok']))
action.execute().get()
verify(storage).read('runlists', 'RunlistName')
示例9: test_CrashlogListAction
def test_CrashlogListAction(self):
storage = mock()
action = CrashlogListAction(storage, **{'name': 'CrashlogName'})
when(storage).find(any(str), any(tuple)).thenReturn(ChainFactory([lambda: 'Ok']))
action.execute().get()
verify(storage).find('crashlogs', ('CrashlogName', ))
示例10: _when_connection_timeouts_for_first_time
def _when_connection_timeouts_for_first_time(self):
when_connect = when(self._ssh).connect(any(), username=any(),
key_filename=any(),
timeout=any())
first_timeout = when_connect.thenRaise(socket.timeout)
second_timeout = first_timeout.thenRaise(socket.timeout)
second_timeout.thenReturn(None)
示例11: test_ProfileViewAction
def test_ProfileViewAction(self):
storage = mock()
action = ProfileViewAction(storage, **{'name': 'ProfileName'})
when(storage).read(any(str), any(str)).thenReturn(ChainFactory([lambda: 'Ok']))
action.execute().get()
verify(storage).read('profiles', 'ProfileName')
示例12: testS3FileWriter
def testS3FileWriter(self):
mock_s3_client = mock()
writer = S3FileWriter(mock_s3_client)
writer.write(mock(), {'bucket': 'test bucket', 'key': 'test key'})
verify(mock_s3_client).connect()
verify(mock_s3_client).write_key(any(), any(), any(), any())
verify(mock_s3_client).disconnect()
示例13: testFtpFileWriter
def testFtpFileWriter(self):
mock_ftp_client = mock()
writer = FtpFileWriter(mock_ftp_client)
writer.write(mock(), {'filename': 'test'})
verify(mock_ftp_client).connect()
verify(mock_ftp_client).write_file(any(), any())
verify(mock_ftp_client).disconnect()
示例14: test_ornamentation_rate_can_be_controlled
def test_ornamentation_rate_can_be_controlled(self):
"""
There should be way to control how frequently walls are ornamented
"""
wall_tile(self.level, (2, 2), self.wall)
wall_tile(self.level, (3, 2), self.wall)
wall_tile(self.level, (4, 2), self.wall)
rng = mock()
when(rng).randint(any(), any()).thenReturn(0).thenReturn(100).thenReturn(0)
when(rng).choice(any()).thenReturn(self.ornamentation)
self.config = WallOrnamentDecoratorConfig(
['any level'],
wall_tile = self.wall,
ornamentation = [self.ornamentation],
rng = rng,
rate = 50)
self.decorator = WallOrnamentDecorator(self.config)
self.decorator.decorate_level(self.level)
candle_count = 0
for location, tile in get_tiles(self.level):
if self.ornamentation in tile['\ufdd0:ornamentation']:
candle_count = candle_count + 1
assert_that(candle_count, is_(equal_to(2)))
示例15: test_RunlistListAction
def test_RunlistListAction(self):
storage = mock()
action = runlist.List(storage)
when(storage).find(any(str), any(tuple)).thenReturn(Chain([lambda: 'Ok']))
action.execute().get()
verify(storage).find('runlists', RUNLISTS_TAGS)