本文整理汇总了Python中mock.Mock.target方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.target方法的具体用法?Python Mock.target怎么用?Python Mock.target使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.Mock
的用法示例。
在下文中一共展示了Mock.target方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_nodetype
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import target [as 别名]
def test_nodetype(self):
mock_node = MagicMock(id=333)
mock_node.type = 'vos:ContainerNode'
client = Client()
client.get_node = Mock(return_value=mock_node)
self.assertEquals('vos:ContainerNode',
client._node_type('vos:/somenode'))
self.assertTrue(client.isdir('vos:/somenode'))
mock_node.type = 'vos:DataNode'
self.assertEquals('vos:DataNode', client._node_type('vos:/somenode'))
self.assertTrue(client.isfile('vos:/somenode'))
# through a link
mock_node.type = 'vos:ContainerNode'
mock_link_node = Mock(type='vos:LinkNode')
mock_link_node.target = 'vos:/somefile'
client.get_node = Mock(side_effect=[mock_link_node, mock_node,
mock_link_node, mock_node])
self.assertEquals('vos:ContainerNode',
client._node_type('vos:/somenode'))
self.assertTrue(client.isdir('vos:/somenode'))
# through an external link - not sure why the type is DataNode in
# this case???
mock_link_node.target = '/somefile'
client.get_node = Mock(side_effect=[mock_link_node, mock_link_node])
self.assertEquals('vos:DataNode', client._node_type('vos:/somenode'))
self.assertTrue(client.isfile('vos:/somenode'))
示例2: test_should_create_process_protocol_with_tracking_id_if_given
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import target [as 别名]
def test_should_create_process_protocol_with_tracking_id_if_given(self, mock_protocol, mock_reactor):
mock_protocol.return_value = 'mock-protocol'
mock_receiver = Mock(Receiver)
mock_broadcaster = Mock()
mock_receiver.states = {'foo': Mock()}
mock_receiver.broadcaster = mock_broadcaster
mock_receiver.get_target_directory.return_value = '/etc/yadtshell/targets/devabc123'
mock_receiver.configuration = {'hostname': 'hostname',
'python_command': '/usr/bin/python',
'script_to_execute': '/usr/bin/yadtshell'}
mock_event = Mock(Event)
mock_event.target = 'devabc123'
mock_event.command = 'yadtshell'
mock_event.arguments = ['update', '--tracking-id=foo']
Receiver.perform_request(mock_receiver, mock_event, Mock())
expected_command_with_arguments = '/usr/bin/python /usr/bin/yadtshell update --tracking-id=foo'
self.assertEqual(
call(
'hostname', mock_broadcaster, 'devabc123', expected_command_with_arguments,
tracking_id='foo'), mock_protocol.call_args)
示例3: test_remove_effect
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import target [as 别名]
def test_remove_effect(self):
effect = Mock()
effect.target = self.unit
self.unit.effects.append(effect)
self.unit.remove_effect(effect)
self.assertEquals(len(self.unit.effects), 0)
self.assertTrue(effect.target is None)
示例4: __loaded_slidelayout
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import target [as 别名]
def __loaded_slidelayout(self, prs_slidemaster=None):
"""
Return _SlideLayout instance loaded using mocks. *prs_slidemaster* is
an already-loaded model-side _SlideMaster instance (or mock, as
appropriate to calling test).
"""
# partname for related slideMaster
sldmaster_partname = '/ppt/slideMasters/slideMaster1.xml'
# path to test slideLayout XML
slidelayout_path = absjoin(test_file_dir, 'slideLayout1.xml')
# model-side slideMaster part
if prs_slidemaster is None:
prs_slidemaster = Mock(spec=_SlideMaster)
# a part dict containing the already-loaded model-side slideMaster
loaded_part_dict = {sldmaster_partname: prs_slidemaster}
# a slideMaster package part for rel target
pkg_slidemaster_part = Mock(spec=pptx.packaging.Part)
pkg_slidemaster_part.partname = sldmaster_partname
# a package-side relationship from slideLayout to its slideMaster
rel = Mock(name='pptx.packaging._Relationship')
rel.rId = 'rId1'
rel.reltype = RT_SLIDE_MASTER
rel.target = pkg_slidemaster_part
# the slideLayout package part to send to _load()
pkg_slidelayout_part = Mock(spec=pptx.packaging.Part)
pkg_slidelayout_part.relationships = [rel]
with open(slidelayout_path, 'rb') as f:
pkg_slidelayout_part.blob = f.read()
# _load and return
slidelayout = _SlideLayout()
return slidelayout._load(pkg_slidelayout_part, loaded_part_dict)
示例5: test_sendEvent_should_use_kwargs_as_event_items
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import target [as 别名]
def test_sendEvent_should_use_kwargs_as_event_items(self):
mock_broadcaster = Mock(WampBroadcaster)
mock_broadcaster.target = "broadcaster-target"
mock_broadcaster.logger = Mock()
mock_broadcaster.client = Mock()
WampBroadcaster._sendEvent(
mock_broadcaster,
"event-id",
"event-data",
tracking_id="tracking-id",
target="target",
state="foobar",
bar="baz",
)
actual_call = mock_broadcaster.client.publish.call_args
self.assertEqual(
call(
"target",
{
"payload": "event-data",
"type": "event",
"id": "event-id",
"tracking_id": "tracking-id",
"target": "target",
"state": "foobar",
"bar": "baz",
},
),
actual_call,
)
示例6: default_args
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import target [as 别名]
def default_args():
args = Mock()
args.conf_file = '.lamvery.yml'
args.dry_run = True
args.publish = True
args.alias = None
args.version = None
args.target = None
return args
示例7: test_by_address_with_srv
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import target [as 别名]
def test_by_address_with_srv(self):
with patch("dns.resolver.query") as query:
answer = Mock()
answer.target = "different.example.org."
answer.port = 12345
query.return_value = [answer]
self.server = MinecraftServer.lookup("example.org")
query.assert_called_once_with("_minecraft._tcp.example.org", "SRV")
self.assertEqual(self.server.host, "different.example.org")
self.assertEqual(self.server.port, 12345)
示例8: _learning_curve
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import target [as 别名]
def _learning_curve(learning_curve):
X = np.array([[0, 1], [1, 0], [1, 1]] * 100, dtype=float)
X[:, 1] += np.random.random((300)) - 0.5
y = np.array([0, 0, 1] * 100)
dataset = Mock()
dataset.train_test_split.return_value = train_test_split(X, y)
dataset.data = X
dataset.target = y
return learning_curve(dataset, LogisticRegression(), steps=5, verbose=1)
示例9: test_get_info_list
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import target [as 别名]
def test_get_info_list(self):
# list tuples of a LinkNode
mock_node = MagicMock(type='vos:DataNode')
mock_node.return_value = mock_node
mock_node.name = 'testnode'
mock_node.get_info.return_value = {'name': 'aa'}
mock_link_node = Mock(type='vos:LinkNode')
mock_link_node.target = 'vos:/somefile'
client = Client()
client.get_node = MagicMock(side_effect=[mock_link_node, mock_node])
self.assertEquals([mock_node],
client.get_children_info('vos:/somenode'))
示例10: mock_context
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import target [as 别名]
def mock_context():
@contextlib.contextmanager
def target(*args):
ctx.push(*args)
yield
ctx.pop()
ctx = Mock(name='context', spec=['push', 'pop', 'peek'])
ctx.formatter = JSONFormatter()
ctx.build_resource_uri = lambda resource: 'uri://' + resource.resource_path
ctx.target = target
return ctx
示例11: test_should_vote_when_handling_request
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import target [as 别名]
def test_should_vote_when_handling_request(self, uuid_fun):
uuid_fun.return_value = "1234-5678"
receiver = Mock(Receiver)
receiver.broadcaster = Mock()
receiver.states = {'foo': None}
event = Mock()
event.arguments = ['--tracking-id=foo']
event.target = 'target'
Receiver.handle_request(receiver, event)
receiver.broadcaster._sendEvent.assert_called_with(
'vote', data='1234-5678', tracking_id='foo', target='target')
示例12: create_mock_formulabase
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import target [as 别名]
def create_mock_formulabase():
""" Generate a formulabase object that does nothing, and returns no errors """
mock_formulabase = Mock(spec=FormulaBase)
mock_formulabase.side_effect = lambda *args, **kw: mock_formulabase
mock_formulabase.should_run.return_value = True
mock_formulabase.resolve.return_value = None
mock_formulabase.prompt.return_value = None
mock_formulabase.sync.return_value = None
mock_formulabase.target = True
for phase in PHASE.values:
setattr(mock_formulabase, phase.name, Mock(return_value=None))
return mock_formulabase
示例13: test_grid_search
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import target [as 别名]
def test_grid_search():
from ..grid_search import grid_search
dataset = Mock()
dataset.data = np.array([[1, 2, 3], [3, 3, 3]] * 20)
dataset.target = np.array([0, 1] * 20)
pipeline = LogisticRegression()
parameters = dict(C=[1.0, 3.0])
result = grid_search(dataset, pipeline, parameters)
assert isinstance(result, GridSearchCV)
assert hasattr(result, 'best_estimator_')
assert hasattr(result, 'best_score_')
示例14: test_search
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import target [as 别名]
def test_search(grid_search, Dataset, main):
from ..learn import search
dataset = Mock()
dataset.data = np.array([[1], [2]])
dataset.target = np.array([1, 2])
Dataset.return_value = dataset
main.arguments = {'<model_name>': 'lr'}
result = search()
assert result is grid_search.return_value
assert grid_search.call_args[0][0] is dataset
assert isinstance(grid_search.call_args[0][1], Pipeline)
assert isinstance(grid_search.call_args[0][2], dict)
示例15: test_should_publish_finished_event
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import target [as 别名]
def test_should_publish_finished_event(self):
mock_protocol = Mock(ProcessProtocol)
mock_broadcaster = Mock()
mock_protocol.broadcaster = mock_broadcaster
mock_protocol.hostname = 'hostname'
mock_protocol.target = 'dev123'
mock_protocol.readable_command = '/usr/bin/python abc'
mock_protocol.tracking_id = 'tracking-id'
mock_protocol.error_buffer = Mock()
ProcessProtocol.publish_finished(mock_protocol)
self.assertEquals(call('dev123', '/usr/bin/python abc', 'finished',
'(hostname) target[dev123] request finished: "/usr/bin/python abc" succeeded.', tracking_id='tracking-id'), mock_broadcaster.publish_cmd_for_target.call_args)
self.assertEqual(METRICS['commands_succeeded.dev123'], 1)