本文整理汇总了Python中pyon.net.endpoint.BaseEndpoint.create_endpoint方法的典型用法代码示例。如果您正苦于以下问题:Python BaseEndpoint.create_endpoint方法的具体用法?Python BaseEndpoint.create_endpoint怎么用?Python BaseEndpoint.create_endpoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyon.net.endpoint.BaseEndpoint
的用法示例。
在下文中一共展示了BaseEndpoint.create_endpoint方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestBaseEndpoint
# 需要导入模块: from pyon.net.endpoint import BaseEndpoint [as 别名]
# 或者: from pyon.net.endpoint.BaseEndpoint import create_endpoint [as 别名]
class TestBaseEndpoint(PyonTestCase):
def setUp(self):
self._node = Mock(spec=NodeB)
self._ef = BaseEndpoint(node=self._node)
self._ch = Mock(spec=SendChannel)
self._node.channel.return_value = self._ch
def test_create_endpoint(self):
e = self._ef.create_endpoint()
# check attrs
self.assertTrue(hasattr(e, 'channel'))
# make sure we can shut it down
e.close()
self._ch.close.assert_any_call()
def test_create_endpoint_existing_channel(self):
ch = Mock(spec=SendChannel)
e = self._ef.create_endpoint(existing_channel=ch)
self.assertEquals(e.channel, ch)
self.assertEquals(ch.connect.call_count, 0)
ch.connect("exist")
ch.connect.assert_called_once_with('exist')
e.close()
def test_create_endpoint_kwarg(self):
"""
Make sure our kwarg gets set.
"""
class OptEndpointUnit(EndpointUnit):
def __init__(self, opt=None, **kwargs):
self._opt = opt
EndpointUnit.__init__(self, **kwargs)
self._ef.endpoint_unit_type = OptEndpointUnit
e = self._ef.create_endpoint(opt="stringer")
self.assertTrue(hasattr(e, "_opt"))
self.assertEquals(e._opt, "stringer")
def test__ensure_node_errors(self):
bep = BaseEndpoint()
gcimock = Mock()
gcimock.return_value = None
with patch('pyon.net.endpoint.BaseEndpoint._get_container_instance', gcimock):
self.assertRaises(EndpointError, bep._ensure_node)
@patch('pyon.net.endpoint.BaseEndpoint._get_container_instance')
def test__ensure_node_existing_node(self, gcimock):
self._ef._ensure_node()
self.assertFalse(gcimock.called)
@patch('pyon.net.endpoint.BaseEndpoint._get_container_instance')
def test__ensure_node(self, gcimock):
bep = BaseEndpoint()
self.assertIsNone(bep.node)
bep._ensure_node()
self.assertEquals(bep.node, gcimock().node)
def test__get_container_instance(self):
c = Container() # ensure we've got an instance in Container.instance
self.assertEquals(BaseEndpoint._get_container_instance(), c)
def test_close(self):
bep = BaseEndpoint()
bep.close()
示例2: TestBaseEndpoint
# 需要导入模块: from pyon.net.endpoint import BaseEndpoint [as 别名]
# 或者: from pyon.net.endpoint.BaseEndpoint import create_endpoint [as 别名]
class TestBaseEndpoint(PyonTestCase):
def setUp(self):
self._node = Mock(spec=NodeB)
self._ef = BaseEndpoint(node=self._node, name="EFTest")
self._ch = Mock(spec=SendChannel)
self._node.channel.return_value = self._ch
def test_create_endpoint(self):
e = self._ef.create_endpoint()
# check attrs
self.assertTrue(hasattr(e, "channel"))
self.assertEquals(self._ch.connect.call_count, 1)
self.assertTrue(self._ef.name in self._ch.connect.call_args[0])
# make sure we can shut it down
e.close()
self._ch.close.assert_any_call()
def test_create_endpoint_new_name(self):
e = self._ef.create_endpoint(to_name="reroute")
self.assertEquals(self._ch.connect.call_count, 1)
self.assertTrue("reroute" in self._ch.connect.call_args[0][0]) # @TODO: this is obtuse
e.close()
def test_create_endpoint_existing_channel(self):
ch = Mock(spec=SendChannel)
e = self._ef.create_endpoint(existing_channel=ch)
self.assertEquals(e.channel, ch)
self.assertEquals(ch.connect.call_count, 0)
ch.connect("exist")
ch.connect.assert_called_once_with("exist")
e.close()
def test_create_endpoint_kwarg(self):
"""
Make sure our kwarg gets set.
"""
class OptEndpointUnit(EndpointUnit):
def __init__(self, opt=None, **kwargs):
self._opt = opt
EndpointUnit.__init__(self, **kwargs)
self._ef.endpoint_unit_type = OptEndpointUnit
e = self._ef.create_endpoint(opt="stringer")
self.assertTrue(hasattr(e, "_opt"))
self.assertEquals(e._opt, "stringer")
def test__ensure_node_errors(self):
bep = BaseEndpoint(name=sentinel.name)
gcimock = Mock()
gcimock.return_value = None
with patch("pyon.net.endpoint.BaseEndpoint._get_container_instance", gcimock):
self.assertRaises(EndpointError, bep._ensure_node)
@patch("pyon.net.endpoint.BaseEndpoint._get_container_instance")
def test__ensure_node_existing_node(self, gcimock):
self._ef._ensure_node()
self.assertFalse(gcimock.called)
@patch("pyon.net.endpoint.BaseEndpoint._get_container_instance")
def test__ensure_node(self, gcimock):
bep = BaseEndpoint(name=sentinel.name)
self.assertIsNone(bep.node)
bep._ensure_node()
self.assertEquals(bep.node, gcimock().node)