本文整理汇总了Python中mock.mocksignature函数的典型用法代码示例。如果您正苦于以下问题:Python mocksignature函数的具体用法?Python mocksignature怎么用?Python mocksignature使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mocksignature函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_event_process
def test_create_event_process(self):
"""
Test creating an event process
"""
# process_definition = ProcessDefinition(name='test')
mock = Mock()
mock.definition = 'a_definition'
mock.detail = 'event_process_detail'
mock_id = 'a_process_definition_id'
self.mock_rr_client.read = Mock()
self.mock_rr_client.read.return_value = mock
self.mock_rr_client.update = Mock()
self.mock_rr_client.update = mocksignature(self.mock_rr_client.update)
self.mock_rr_client.find_objects = Mock()
self.mock_rr_client.find_objects.return_value = ['stream_id_1'], 'obj_assoc_1'
self.mock_pd_client.schedule_process = Mock()
self.mock_pd_client.schedule_process.return_value = 'process_id'
self.mock_rr_client.create_association = mocksignature(self.mock_rr_client.create_association)
self.mock_dams_client.register_event_process = mocksignature(self.mock_dams_client.register_event_process)
pid = self.event_management.create_event_process(process_definition_id=mock_id,
event_types=['type_1', 'type_2'],
sub_types=['subtype_1', 'subtype_2'],
origins=['or_1', 'or_2'],
origin_types=['t1', 't2'],
out_data_products={'conductivity': 'id1'}
)
示例2: setUp
def setUp(self):
abstract_node_class = mocksignature(AbstractNode, AbstractNode)
selector_class = mocksignature(StaticSelector, StaticSelector)
self.abstract_node = abstract_node_class(self)
self.abstract_node.selector = selector_class(self)
self.root_node = Node(pattern='', parent=None, abstract_node=self.abstract_node)
示例3: setUp
def setUp(self):
def config_get_args(str1, str2):
if str2 == 'api_root':
return sentinel.api_root
else:
return sentinel.promo_code
self.config = Mock()
self.config.get = config_get_args
def testfun_nopromo(api_root, user):
pass
def testfun_promo(api_root, user, promo_code):
pass
self.testfun_nopromo_mock = Mock()
self.testfun_nopromo = mocksignature(testfun_nopromo,
self.testfun_nopromo_mock)
self.testfun_nopromo.return_value = sentinel.testfun_nopromo
self.testfun_promo_mock = Mock()
self.testfun_promo = mocksignature(testfun_promo,
self.testfun_promo_mock)
self.testfun_promo.return_value = sentinel.testfun_promo
示例4: testIntrospection
def testIntrospection(self):
def f(a, *args, **kwargs):
pass
f2 = mocksignature(f, f)
self.assertEqual(inspect.getargspec(f), inspect.getargspec(f2))
def f(a, b=None, c=3, d=object()):
pass
f2 = mocksignature(f, f)
self.assertEqual(inspect.getargspec(f), inspect.getargspec(f2))
示例5: test_create_event_type
def test_create_event_type(self):
"""
Test creating an event
"""
event_type = EventType(name="Test event type")
self.mock_rr_client.create = mocksignature(self.mock_rr_client.create)
self.mock_rr_client.create.return_value = ('event_type_id','rev_1')
self.mock_dams_client.register_process = mocksignature(self.mock_dams_client.register_process)
event_type_id = self.event_management.create_event_type(event_type)
self.assertEquals(event_type_id, 'event_type_id')
self.mock_rr_client.create.assert_called_once_with(event_type)
示例6: testMockSignatureWithReservedArg
def testMockSignatureWithReservedArg(self):
def f(_mock_):
pass
self.assertRaises(AssertionError, lambda: mocksignature(f))
def f(_mock_=None):
pass
self.assertRaises(AssertionError, lambda: mocksignature(f))
def f(*_mock_):
pass
self.assertRaises(AssertionError, lambda: mocksignature(f))
def f(**_mock_):
pass
self.assertRaises(AssertionError, lambda: mocksignature(f))
示例7: test_create_event_process
def test_create_event_process(self):
"""
Test creating an event process
"""
process_definition = ProcessDefinition(name='test')
process_definition.definition = ''
rrc = ResourceRegistryServiceClient(node = self.container.node)
process_definition_id = rrc.create(process_definition)
self.mock_rr_client.find_objects = Mock()
self.mock_rr_client.find_objects.return_value = ['stream_id_1'], 'obj_assoc_1'
# self.mock_pd_client.schedule_process = Mock()
# self.mock_pd_client.schedule_process.return_value = 'process_id'
self.mock_rr_client.create_association = mocksignature(self.mock_rr_client.create_association)
pid = self.event_management.create_event_process(process_definition_id=process_definition_id,
event_types=['type_1', 'type_2'],
sub_types=['subtype_1', 'subtype_2'],
origins=['or_1', 'or_2'],
origin_types=['t1', 't2'],
out_data_products={'conductivity': 'id1'}
)
示例8: test_side_effect_from_existing_mock
def test_side_effect_from_existing_mock(self):
mock = Mock(side_effect=KeyError)
func = mocksignature(f, mock)
self.assertRaises(KeyError, func, 1, 2, 3)
mock.side_effect = NameError
self.assertRaises(NameError, func, 1, 2, 3)
示例9: test_return_value_from_existing_mock
def test_return_value_from_existing_mock(self):
mock = Mock(return_value='foo')
func = mocksignature(f, mock)
self.assertEqual(func(1, 2, 3), 'foo')
mock.return_value = 'bar'
self.assertEqual(func(1, 2, 3), 'bar')
示例10: _create_service_mock
def _create_service_mock(self, service_name):
# set self.clients if not already set
clients = Mock(name='clients')
base_service = get_service_registry().get_service_base(service_name)
# Save it to use in test_verify_service
self.base_service = base_service
self.addCleanup(delattr, self, 'base_service')
dependencies = base_service.dependencies
for dep_name in dependencies:
dep_service = get_service_registry().get_service_base(dep_name)
# Force mock service to use interface
mock_service = Mock(name='clients.%s' % dep_name,
spec=dep_service)
setattr(clients, dep_name, mock_service)
# set self.dep_name for convenience
setattr(self, dep_name, mock_service)
self.addCleanup(delattr, self, dep_name)
iface = list(implementedBy(dep_service))[0]
names_and_methods = iface.namesAndDescriptions()
for func_name, _ in names_and_methods:
mock_func = mocksignature(getattr(dep_service, func_name),
mock=Mock(name='clients.%s.%s' % (dep_name,
func_name)), skipfirst=True)
setattr(mock_service, func_name, mock_func)
return clients
示例11: test_mocksignature_with_reserved_arg
def test_mocksignature_with_reserved_arg(self):
def f(_mock_):
pass
self.assertRaises(AssertionError, lambda: mocksignature(f))
def f(_mock_=None):
pass
self.assertRaises(AssertionError, lambda: mocksignature(f))
def f(*_mock_):
pass
self.assertRaises(AssertionError, lambda: mocksignature(f))
def f(**_mock_):
pass
self.assertRaises(AssertionError, lambda: mocksignature(f))
示例12: test_load_cards
def test_load_cards(self):
fbb = [u"Foo", u"Bar", u"Baz"]
parse = mock.mocksignature(p.parse)
for l, f in itertools.izip_longest(p.load_cards(S, _parse=parse), fbb):
self.assertEqual(list(parse.mock.call_args[0][0]), [f] * 3)
示例13: test_delete_event_process
def test_delete_event_process(self):
"""
Test deleting an event process
"""
self.mock_rr_client.delete = mocksignature(self.mock_rr_client.delete)
self.event_management.delete_event_process('event_process_id')
self.mock_rr_client.delete.assert_called_once_with('event_process_id')
示例14: test_delete_event_type
def test_delete_event_type(self):
"""
Test updating an event
"""
self.mock_rr_client.delete = mocksignature(self.mock_rr_client.delete)
self.event_management.delete_event_type(event_type_id='event_type_id')
self.mock_rr_client.delete.assert_called_once_with('event_type_id')
示例15: test_get_pod_files
def test_get_pod_files():
mock_os_listdir = Mock(return_value = ['foo', 'bar', 'baz'])
mock_pod_executable_file_p = mocksignature(barker.pod.executable_file_p)
mock_pod_executable_file_p.return_value = True
with patch.object(barker.pod.os, 'listdir', mock_os_listdir):
with patch.object(barker.pod, "executable_file_p", mock_pod_executable_file_p):
assert_equals(list(barker.pod.get_pod_files('/barker-tests')),
['/barker-tests/foo', '/barker-tests/bar', '/barker-tests/baz'])