本文整理汇总了Python中unittest.mock.Mock.type方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.type方法的具体用法?Python Mock.type怎么用?Python Mock.type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.Mock
的用法示例。
在下文中一共展示了Mock.type方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_gamestate_handle_events_pause_quit
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import type [as 别名]
def test_gamestate_handle_events_pause_quit(Dungeon, event_get, fontinit):
waves = MagicMock()
waves.__len__.return_value = 2
def event_get_called():
return cur_events
event_get.side_effect = event_get_called
d = Mock()
d.walls = []
Dungeon.load.return_value = d
gs = gamestate.GameState()
assert not gs.paused
assert gs.running
# No events, no changes.
cur_events = []
gs.handle_events()
assert not gs.paused
assert gs.running
assert event_get.call_count == 1
# 'quit' -- q -> not-running
event_key_q = Mock()
event_key_q.type = pygame.KEYDOWN
event_key_q.key = pygame.K_q
cur_events = [event_key_q]
gs.handle_events()
assert not gs.paused
assert not gs.running
assert event_get.call_count == 2
# 'pause' -- p -> paused, p -> unpaused
gs = gamestate.GameState()
event_key_p = Mock()
event_key_p.type = pygame.KEYDOWN
event_key_p.key = pygame.K_p
cur_events = [event_key_p]
gs.handle_events()
assert gs.paused
assert gs.running
# (toggle-unpaused)
gs.handle_events()
assert not gs.paused
assert gs.running
# (toggle-paused, then quit while paused)
gs.handle_events()
assert gs.paused
assert gs.running
cur_events = [event_key_q]
gs.handle_events()
assert gs.paused
assert not gs.running
示例2: test_finalize_transfer_to_remote
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import type [as 别名]
def test_finalize_transfer_to_remote(self):
transfer = Mock()
transfer.type = syncall.transfers.FileTransfer.TO_REMOTE
transfer.file_name = 'file1'
transfer.get_remote_uuid.return_value = 'uuid2'
transfer.timestamp = 1250
self.directory.last_update = 123
self.directory.save_index = Mock()
self.directory.index_updated = Mock()
self.directory._index['file1'] = {
'last_update': 1234,
'sync_log': {
'my_uuid': 1234,
'uuid1': 1200,
'uuid2': 1000
}
}
self.directory.finalize_transfer(transfer)
self.assertGreater(self.directory.last_update, 123)
self.assertEqual(self.directory._index['file1'], {
'last_update': 1234,
'sync_log': {
'my_uuid': 1234,
'uuid1': 1200,
'uuid2': 1250
}
})
self.directory.index_updated.notify.assert_called_once_with(
{'file1'}
)
self.assertTrue(self.directory.save_index.called)
示例3: test_no_listed_version_reviewer
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import type [as 别名]
def test_no_listed_version_reviewer(self):
user = user_factory()
self.grant_permission(user, 'Addons:Review')
obj = Mock(spec=[])
obj.type = amo.ADDON_EXTENSION
obj.has_listed_versions = lambda: False
for method in self.safe_methods:
request = getattr(self.request_factory, method)('/')
request.user = user
# When not checking the object, we have permission because we're
# authenticated.
assert self.permission.has_permission(request, myview)
# It doesn't work with the object though, since
# has_listed_versions() is returning False, we don't have enough
# permissions, being a "simple" reviewer.
assert not self.permission.has_object_permission(
request, myview, obj)
for method in self.unsafe_methods:
request = getattr(self.request_factory, method)('/')
request.user = user
# When not checking the object, we have permission because we're
# authenticated.
assert self.permission.has_permission(request, myview)
# As above it doesn't work with the object though.
assert not self.permission.has_object_permission(
request, myview, obj)
示例4: test_finalize_transfer_from_remote_old
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import type [as 别名]
def test_finalize_transfer_from_remote_old(self, compare_file):
transfer = Mock()
transfer.type = syncall.transfers.FileTransfer.FROM_REMOTE
transfer.file_name = 'file1'
compare_file.return_value = syncall.index.CONFLICT
self.directory.get_file_path = Mock()
self.directory.get_file_path.return_value = '/dir/file1'
self.directory.last_update = 123
self.directory.save_index = Mock()
self.directory.index_updated = Mock()
self.directory._index['file1'] = {
'last_update': 1234,
'sync_log': {
'my_uuid': 1234,
'uuid1': 1200,
'uuid2': 1000
}
}
self.directory.finalize_transfer(transfer)
self.assertEqual(self.directory.last_update, 123)
self.assertEqual(self.directory._index['file1'], {
'last_update': 1234,
'sync_log': {
'my_uuid': 1234,
'uuid1': 1200,
'uuid2': 1000
}
})
self.assertFalse(self.directory.index_updated.notify.called)
self.assertTrue(self.directory.save_index.called)
示例5: create_mock_plugin
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import type [as 别名]
def create_mock_plugin():
from unittest.mock import Mock
from coalaip.plugin import AbstractPlugin
mock_plugin = Mock(
name="mock_ledger_plugin",
spec_set=AbstractPlugin)
mock_plugin.type = 'mock'
return mock_plugin
示例6: test_authenticated_but_not_reviewer
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import type [as 别名]
def test_authenticated_but_not_reviewer(self):
request = self.request_factory.get('/')
request.user = user_factory()
obj = Mock(spec=[])
obj.type = amo.ADDON_EXTENSION
obj.has_listed_versions = lambda: True
assert self.permission.has_permission(request, myview)
assert not self.permission.has_object_permission(
request, myview, obj)
示例7: mock_workflow
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import type [as 别名]
def mock_workflow() -> Mock:
"""Mock :class:`adhocracy_core.workflows.AdhocracyACLWorkflow`."""
from adhocracy_core.workflows import ACLLocalRolesWorkflow
mock = Mock(spec=ACLLocalRolesWorkflow)
mock._states = {}
mock.get_next_states.return_value = []
mock.state_of.return_value = None
mock.type = 'sample'
mock._initial_state = 'draft'
return mock
示例8: test_add_new_climate_device
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import type [as 别名]
async def test_add_new_climate_device(hass):
"""Test successful creation of climate entities."""
await setup_gateway(hass, {})
sensor = Mock()
sensor.name = 'name'
sensor.type = 'ZHAThermostat'
sensor.register_async_callback = Mock()
async_dispatcher_send(hass, 'deconz_new_sensor', [sensor])
await hass.async_block_till_done()
assert "climate.name" in hass.data[deconz.DOMAIN].deconz_ids
示例9: test_do_not_allow_clipsensor
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import type [as 别名]
async def test_do_not_allow_clipsensor(hass):
"""Test that clip sensors can be ignored."""
await setup_gateway(hass, {}, allow_clip_sensor=False)
sensor = Mock()
sensor.name = 'name'
sensor.type = 'CLIPThermostat'
sensor.register_async_callback = Mock()
async_dispatcher_send(hass, 'deconz_new_sensor', [sensor])
await hass.async_block_till_done()
assert len(hass.data[deconz.DOMAIN].deconz_ids) == 0
示例10: test_add_new_switch
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import type [as 别名]
async def test_add_new_switch(hass):
"""Test successful creation of switch entity."""
await setup_gateway(hass, {})
switch = Mock()
switch.name = 'name'
switch.type = "Smart plug"
switch.register_async_callback = Mock()
async_dispatcher_send(hass, 'deconz_new_light', [switch])
await hass.async_block_till_done()
assert "switch.name" in hass.data[deconz.DOMAIN].deconz_ids
示例11: test_user_cannot_be_anonymous
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import type [as 别名]
def test_user_cannot_be_anonymous(self):
request = self.request_factory.get('/')
request.user = AnonymousUser()
obj = Mock(spec=[])
obj.type = amo.ADDON_EXTENSION
obj.has_listed_versions = lambda: True
assert not self.permission.has_permission(request, myview)
assert not self.permission.has_object_permission(
request, myview, obj)
示例12: test_add_new_cover
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import type [as 别名]
async def test_add_new_cover(hass):
"""Test successful creation of cover entity."""
data = {}
await setup_gateway(hass, data)
cover = Mock()
cover.name = 'name'
cover.type = "Level controllable output"
cover.register_async_callback = Mock()
async_dispatcher_send(hass, 'deconz_new_light', [cover])
await hass.async_block_till_done()
assert "cover.name" in hass.data[deconz.DOMAIN].deconz_ids
示例13: test_add_new_sensor
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import type [as 别名]
async def test_add_new_sensor(hass):
"""Test successful creation of sensor entities."""
data = {}
await setup_bridge(hass, data)
sensor = Mock()
sensor.name = 'name'
sensor.type = 'ZHATemperature'
sensor.register_async_callback = Mock()
async_dispatcher_send(hass, 'deconz_new_sensor', [sensor])
await hass.async_block_till_done()
assert "sensor.name" in hass.data[deconz.DATA_DECONZ_ID]
示例14: test_add_new_switch
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import type [as 别名]
async def test_add_new_switch(hass):
"""Test successful creation of switch entity."""
data = {}
await setup_bridge(hass, data)
switch = Mock()
switch.name = 'name'
switch.type = "Smart plug"
switch.register_async_callback = Mock()
async_dispatcher_send(hass, 'deconz_new_light', [switch])
await hass.async_block_till_done()
assert "switch.name" in hass.data[deconz.DATA_DECONZ_ID]
示例15: test_do_not_allow_clipsensor
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import type [as 别名]
async def test_do_not_allow_clipsensor(hass):
"""Test that clip sensors can be ignored."""
data = {}
await setup_bridge(hass, data, allow_clip_sensor=False)
sensor = Mock()
sensor.name = 'name'
sensor.type = 'CLIPTemperature'
sensor.register_async_callback = Mock()
async_dispatcher_send(hass, 'deconz_new_sensor', [sensor])
await hass.async_block_till_done()
assert len(hass.data[deconz.DATA_DECONZ_ID]) == 0