本文整理汇总了Python中mockito.mock函数的典型用法代码示例。如果您正苦于以下问题:Python mock函数的具体用法?Python mock怎么用?Python mock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mock函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_dual_wielding_two_handed_weapons
def test_dual_wielding_two_handed_weapons(self): #pylint: disable=C0103
"""
Test that character can not dual wield two-handed weapon
"""
item1 = (ItemBuilder()
.with_name('longspear')
.with_tag('two-handed weapon')
.with_tag('weapon')
.build())
item2 = (ItemBuilder()
.with_name('sickle')
.with_tag('light weapon')
.with_tag('weapon')
.build())
assert_that(item1, is_not(is_in(self.character.weapons)))
assert_that(item2, is_not(is_in(self.character.weapons)))
pyherc.rules.items.wield(mock(), self.character, item2)
pyherc.rules.items.wield(mock(), self.character,
item1,
dual_wield = True)
assert_that(item1, is_not(is_in(self.character.weapons)))
assert_that(item2, is_in(self.character.weapons))
开发者ID:briguy47,项目名称:pyherc,代码行数:26,代码来源:test_item.py
示例2: test_process_should_receive_dependencies_process_results_as_context
def test_process_should_receive_dependencies_process_results_as_context(self):
registration = mock()
symbol = 'symbol'
start = None
end = None
expected_a = pandas.DataFrame([1, 2, 3])
expected_b = pandas.DataFrame([9, 8, 7])
class DatasourceMock():
def evaluate(self, context, s, ds, de):
assert isinstance(context, task.DatasourceContext)
deps = context.dependencies()
assert isinstance(deps, dict)
assert len(deps) is 2
assert (deps['a'].values == expected_a.values).all()
assert (deps['b'].values == expected_b.values).all()
assert s == symbol
assert ds == start
assert de == end
dependencies = {
'a': mock(task.DataFrameDatasourceTask),
'b': mock(task.DataFrameDatasourceTask),
}
when(dependencies['a']).process(symbol, start, end).thenReturn(expected_a)
when(dependencies['b']).process(symbol, start, end).thenReturn(expected_b)
task.DataFrameDatasourceTask(DatasourceMock(), registration, dependencies).process(symbol, start, end)
开发者ID:rhlobo,项目名称:bigtempo,代码行数:31,代码来源:dataframe_task_tests.py
示例3: test_level_generator_is_created
def test_level_generator_is_created(self):
"""
Test that portal adder has level generator set to it
"""
portal_config = [PortalAdderConfiguration(icons = (1, 2),
level_type = 'catacombs',
location_type = 'room',
chance = 100,
new_level = 'upper crypt',
unique = False)]
level_generator_factory = mock(LevelGeneratorFactory)
level_generator = mock(LevelGenerator)
when(level_generator_factory).get_generator(any()).thenReturn(level_generator)
factory = PortalAdderFactory(portal_config,
self.rng)
factory.level_generator_factory = level_generator_factory
portal_adders = factory.create_portal_adders('catacombs')
portal_adder = portal_adders[0]
assert_that(portal_adder.level_generator,
is_(same_instance(level_generator)))
开发者ID:briguy47,项目名称:pyherc,代码行数:26,代码来源:test_portaladder.py
示例4: __init__
def __init__(self):
"""
Default constructor
"""
super(CharacterBuilder, self).__init__()
self.hit_points = 10
self.max_hp = 10
self.model = mock()
self.action_factory = mock()
self.rng = Random()
self.speed = 1
self.tick = 0
self.attack = 1
self.body = 1
self.mind = 1
self.name = 'prototype'
self.level = None
self.location = ()
self.effect_handles = []
self.effects = []
self.effects_collection = EffectsCollection()
self.player_character = False
self.listeners = []
开发者ID:briguy47,项目名称:pyherc,代码行数:28,代码来源:character.py
示例5: start_client
def start_client(self):
soledad_test_folder = self._generate_soledad_test_folder_name()
SearchEngine.DEFAULT_INDEX_HOME = soledad_test_folder
self.cleanup = lambda: shutil.rmtree(soledad_test_folder)
self.soledad = yield initialize_soledad(tempdir=soledad_test_folder)
self.keymanager = mock()
self.search_engine = SearchEngine(self.INDEX_KEY, agent_home=soledad_test_folder)
self.mail_sender = self._create_mail_sender()
self.mail_store = SearchableMailStore(LeapMailStore(self.soledad), self.search_engine)
account_ready_cb = defer.Deferred()
self.account = IMAPAccount(self.ACCOUNT, self.soledad, account_ready_cb)
yield account_ready_cb
self.draft_service = DraftService(self.mail_store)
self.leap_session = mock()
self.feedback_service = FeedbackService(self.leap_session)
self.mail_service = self._create_mail_service(self.mail_sender, self.mail_store, self.search_engine)
mails = yield self.mail_service.all_mails()
self.search_engine.index_mails(mails)
self.resource = RootResource()
self.resource.initialize(
self.keymanager, self.search_engine, self.mail_service, self.draft_service, self.feedback_service
)
开发者ID:kaeff,项目名称:pixelated-user-agent,代码行数:30,代码来源:app_test_client.py
示例6: test_should_throw_exception_when_node_is_not_up_and_running
def test_should_throw_exception_when_node_is_not_up_and_running(self):
mock_connection_provider = mock()
tags = {
'services' : """
'apache' :
80: 80""",
'credentials_name': 'test',
'env_name' : 'test',
'env_def_name' : 'Single-AZ Deployment',
}
fake_boto_instance1 = mock()
fake_boto_instance1.tags = tags
stub_region = mock()
stub_region.name = 'eu-west'
fake_boto_instance1.region = stub_region
fake_boto_instance1.id = 'id1234'
fake_boto_instance1.ip_address = 'test_ip'
fake_boto_instance1.state = 'running'
fake_boto_instance1.placement='us-east-1'
aws_node = AWSRunningNode(fake_boto_instance1, None, mock_connection_provider)
when(mock_connection_provider).connected_to_node('test_ip', 22).thenReturn(False)
with self.assertRaisesRegexp(Exception, "Node id1234 is not running"):
aws_node.wait_for_ready(lambda : None, 5)
开发者ID:ThoughtWorksInc,项目名称:Phoenix,代码行数:25,代码来源:aws_provider_tests.py
示例7: test_create_incremental
def test_create_incremental(self):
instance = mock(instance_models.Instance)
parent = mock(models.DBBackup)
when(instance_models.BuiltInstance).load(any(), any()).thenReturn(
instance)
when(instance).validate_can_perform_action().thenReturn(None)
when(models.Backup).verify_swift_auth_token(any()).thenReturn(
None)
when(api.API).create_backup(any()).thenReturn(None)
when(models.Backup).get_by_id(any(), any()).thenReturn(
parent)
incremental = models.Backup.create(self.context, self.instance_id,
BACKUP_NAME, BACKUP_DESC,
parent_id='parent_uuid')
self.created = True
db_record = models.DBBackup.find_by(id=incremental.id)
self.assertEqual(incremental.id, db_record['id'])
self.assertEqual(BACKUP_NAME, db_record['name'])
self.assertEqual(BACKUP_DESC, db_record['description'])
self.assertEqual(self.instance_id, db_record['instance_id'])
self.assertEqual(models.BackupState.NEW, db_record['state'])
self.assertEqual('parent_uuid', db_record['parent_id'])
开发者ID:NeCTAR-RC,项目名称:trove,代码行数:25,代码来源:test_backup_models.py
示例8: test_image_name
def test_image_name(self):
res = mock(requests.Response)
url = 'https://example.com/scheduler/jobs/search?name=example_team-app'
image_data = [{'container':{'image':'place-robot-simpleapp-2345643lkjfkdajurakdsfoweifa/v0.1.0'}}]
data = {'environments':{'dev':{'chronos_endpoint':'https://example.com'}}}
os.environ['ROGER_CONFIG_DIR'] = '/vagrant/config'
username = 'first.first'
password = 'last.last'
config_dir = '/vagrant/config'
config_file = 'test.yml'
app_config_object = mock(AppConfig)
when(app_config_object).getRogerEnv(config_dir).thenReturn(data)
when(requests).get(url, auth=(username, password)).thenReturn(res)
when(res).json().thenReturn(image_data)
c = Chronos()
img = c.get_image_name(
username,
password,
'dev',
'example_team-app',
config_dir,
config_file,
app_config_object
)
assert img == image_data[0]['container']['image']
开发者ID:seomoz,项目名称:roger-mesos-tools,代码行数:27,代码来源:test_chronos.py
示例9: setUp
def setUp(self):
self.transaction = mock()
self.transaction._map = {}
self.cursor = mock()
self.connection = mock()
self.transaction.cursor = self.cursor
when(self.cursor).getconnection().thenReturn(self.connection)
开发者ID:cadrian,项目名称:pyceed,代码行数:7,代码来源:test_internals.py
示例10: mock
def test_register_should_call_listener_for_each_late_combination_of_references_when_there_are_multiple_selectors(self):
reference1a = 'REFERENCE1a'
reference2a = 'REFERENCE2a'
reference1b = 'REFERENCE1b'
reference2b = 'REFERENCE2b'
selection_a = mock()
(when(selection_a).__iter__()
.thenReturn([reference1a].__iter__())
.thenReturn([reference1a, reference2a].__iter__())
.thenReturn([reference1a, reference2a].__iter__()))
when(selection_a).is_elegible(reference2a).thenReturn(True)
selection_b = mock()
(when(selection_b).__iter__()
.thenReturn([reference1b].__iter__())
.thenReturn([reference1b].__iter__())
.thenReturn([reference1b, reference2b].__iter__()))
when(selection_b).is_elegible(reference2b).thenReturn(True)
self.manager.register(self.listener_callable_mock, utils.IterableMock(selection_a), utils.IterableMock(selection_b))
verify(self.listener_mock, times=1).__call__(reference1a, reference1b)
verifyNoMoreInteractions(self.listener_mock)
self.manager.evaluate_new_candidate(reference2a)
verify(self.listener_mock, times=1).__call__(reference2a, reference1b)
verifyNoMoreInteractions(self.listener_mock)
self.manager.evaluate_new_candidate(reference2b)
verify(self.listener_mock, times=1).__call__(reference1a, reference2b)
verify(self.listener_mock, times=1).__call__(reference2a, reference2b)
verifyNoMoreInteractions(self.listener_mock)
开发者ID:rhlobo,项目名称:bigtempo,代码行数:32,代码来源:tagselection_tests.py
示例11: setup
def setup(self):
"""
Setup the test case
"""
model = mock()
action_factory = mock()
rng = mock()
self.creature1 = (CharacterBuilder()
.with_tick(5)
.with_speed(1)
.with_name('creature 1')
.build())
self.creature2 = (CharacterBuilder()
.with_tick(0)
.with_speed(2)
.with_name('creature 2')
.build())
self.creature3 = (CharacterBuilder()
.with_tick(3)
.with_speed(0.5)
.with_name('creature 3')
.build())
self.model = Model()
self.model.dungeon = Dungeon()
self.model.dungeon.levels = Level((20, 20), 0, 0)
self.model.dungeon.levels.add_creature(self.creature1)
self.model.dungeon.levels.add_creature(self.creature2)
self.model.player = self.creature3
self.model.dungeon.levels.add_creature(self.creature3)
开发者ID:briguy47,项目名称:pyherc,代码行数:34,代码来源:test_time.py
示例12: test_find_by_name_parent_is_webelement
def test_find_by_name_parent_is_webelement(self):
webelement = mock()
when(self.finder)._is_webelement(webelement).thenReturn(True)
when(self.finder)._is_webelement('name=value').thenReturn(False)
when(webelement).find_elements_by_name('value').thenReturn([mock()])
self.finder.find('name=value', parent=webelement)
verify(webelement).find_elements_by_name("value")
开发者ID:ponkar,项目名称:robotframework-selenium2library,代码行数:7,代码来源:test_elementfinder.py
示例13: test_find_by_xpath_parent_is_webelement
def test_find_by_xpath_parent_is_webelement(self):
webelement = mock()
when(self.finder)._is_webelement(webelement).thenReturn(True)
when(self.finder)._is_webelement('//div').thenReturn(False)
when(webelement).find_elements_by_xpath('//div').thenReturn([mock()])
self.finder.find('//div', parent=webelement)
verify(webelement).find_elements_by_xpath('//div')
开发者ID:ponkar,项目名称:robotframework-selenium2library,代码行数:7,代码来源:test_elementfinder.py
示例14: test_dual_wielding
def test_dual_wielding(self):
"""
Test that character can wield two weapons
"""
item1 = (ItemBuilder()
.with_name('dagger')
.with_tag('light weapon')
.with_damage(1)
.build())
item2 = (ItemBuilder()
.with_name('sickle')
.with_tag('light weapon')
.with_damage(2)
.build())
assert_that(item1, is_not(is_in(self.character.weapons)))
assert_that(item2, is_not(is_in(self.character.weapons)))
pyherc.rules.items.wield(mock(), self.character, item1)
pyherc.rules.items.wield(mock(),
self.character,
item2,
dual_wield = True)
assert_that(item1, is_in(self.character.weapons))
assert_that(item2, is_in(self.character.weapons))
开发者ID:briguy47,项目名称:pyherc,代码行数:27,代码来源:test_item.py
示例15: test_tranformer_flavor_cache
def test_tranformer_flavor_cache(self):
status = rd_instance.ServiceStatuses.BUILDING.api_status
db_instance = MockMgmtInstanceTest.build_db_instance(
status, InstanceTasks.BUILDING)
server = mock(Server)
server.user_id = 'test_user_id'
mgmt_instance = mgmtmodels.SimpleMgmtInstance(self.context,
db_instance,
server,
None)
when(mgmtmodels).load_mgmt_instances(
self.context,
deleted=False,
client=self.client).thenReturn(
[mgmt_instance])
flavor = mock(Flavor)
flavor.name = 'db.small'
when(self.flavor_mgr).get('flavor_1').thenReturn(flavor)
transformer = mgmtmodels.NovaNotificationTransformer(
context=self.context)
transformer()
# call twice ensure client.flavor invoked once
payloads = transformer()
self.assertIsNotNone(payloads)
self.assertThat(len(payloads), Equals(1))
payload = payloads[0]
self.assertThat(payload['audit_period_beginning'], Not(Is(None)))
self.assertThat(payload['audit_period_ending'], Not(Is(None)))
self.assertThat(payload['state'], Equals(status.lower()))
self.assertThat(payload['instance_type'], Equals('db.small'))
self.assertThat(payload['instance_type_id'], Equals('flavor_1'))
self.assertThat(payload['user_id'], Equals('test_user_id'))
# ensure cache was used to get flavor second time
verify(self.flavor_mgr).get('flavor_1')
开发者ID:NeCTAR-RC,项目名称:trove,代码行数:35,代码来源:test_models.py
示例16: make_edge_with_mock_vehicles
def make_edge_with_mock_vehicles(self):
edge, lane_1, lane_2 = self.make_edge_without_vehicles()
first = mock()
second = mock()
lane_1.add_vehicle(first)
lane_2.add_vehicle(second)
return edge, first, second
开发者ID:wanderanimrod,项目名称:Utraffik-Simulator,代码行数:7,代码来源:translator_test.py
示例17: test_should_return_empty_running_environment_if_nothing_is_running
def test_should_return_empty_running_environment_if_nothing_is_running(self):
fake_boto_instance = mock()
tags = {
'services' : """
apache :
80: 80""",
'credentials_name': 'test',
'env_name' : 'my_environment',
'env_def_name' : 'Single-AZ Deployment',
}
fake_boto_instance.tags = tags
stub_region = mock()
stub_region.name = 'eu-west'
fake_boto_instance.region = stub_region
fake_boto_instance.image_id = '1234'
fake_boto_instance.instance_type = 'large'
mock_connection_provider = mock()
when(mock_connection_provider).ec2_connection_for_region("eu-west", None, None).thenReturn(None)
when(mock_connection_provider).get_all_boto_instances(None, None).thenReturn([fake_boto_instance])
provider = AWSNodeProvider(None, None, mock_connection_provider)
environment = provider.get_running_environment("test","test", all_credentials)
self.assertIsNotNone(environment)
self.assertEqual(0, len(environment.get_locations()))
开发者ID:ThoughtWorksInc,项目名称:Phoenix,代码行数:27,代码来源:aws_provider_tests.py
示例18: mock_sql_connection
def mock_sql_connection():
mock_engine = mock()
when(sqlalchemy).create_engine("mysql://root:@localhost:3306", echo=True).thenReturn(mock_engine)
mock_conn = mock()
when(dbaas.LocalSqlClient).__enter__().thenReturn(mock_conn)
when(dbaas.LocalSqlClient).__exit__(any(), any(), any()).thenReturn(None)
return mock_conn
开发者ID:ReVolly,项目名称:trove,代码行数:7,代码来源:test_dbaas.py
示例19: setup
def setup(self):
"""
Setup the test case
"""
self.rng = Random()
self.model = mock()
self.effect_factory = mock()
drink_factory = DrinkFactory(self.effect_factory)
self.action_factory = ActionFactory(self.model,
drink_factory)
self.character = (CharacterBuilder()
.with_action_factory(self.action_factory)
.with_hit_points(1)
.with_max_hp(5)
.build())
effect = Heal(duration = 0,
frequency = 0,
tick = 0,
healing = 5,
target = self.character)
when(self.effect_factory).create_effect(any(),
target = any()).thenReturn(effect)
self.potion = (ItemBuilder()
.with_name('healing potion')
.with_effect(
EffectHandleBuilder()
.with_trigger('on drink')
.with_effect('heal'))
.build())
self.character.inventory.append(self.potion)
开发者ID:briguy47,项目名称:pyherc,代码行数:35,代码来源:test_potions.py
示例20: test_ProfileUploadActionRethrowsExceptions
def test_ProfileUploadActionRethrowsExceptions(self):
storage = mock()
jsonEncoder = mock()
action = profile.Upload(storage, **{'name': 'ProfileName', 'profile': 'p.json'})
action.jsonEncoder = jsonEncoder
when(jsonEncoder).encode('p.json').thenRaise(ValueError)
self.assertRaises(ValueError, action.execute)
开发者ID:nexusriot,项目名称:cocaine-framework-python,代码行数:7,代码来源:test_tools.py
注:本文中的mockito.mock函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论