本文整理匯總了Python中pyon.net.endpoint.BaseEndpoint._ensure_node方法的典型用法代碼示例。如果您正苦於以下問題:Python BaseEndpoint._ensure_node方法的具體用法?Python BaseEndpoint._ensure_node怎麽用?Python BaseEndpoint._ensure_node使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyon.net.endpoint.BaseEndpoint
的用法示例。
在下文中一共展示了BaseEndpoint._ensure_node方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test__ensure_node
# 需要導入模塊: from pyon.net.endpoint import BaseEndpoint [as 別名]
# 或者: from pyon.net.endpoint.BaseEndpoint import _ensure_node [as 別名]
def test__ensure_node(self, gcimock):
bep = BaseEndpoint()
self.assertIsNone(bep.node)
bep._ensure_node()
self.assertEquals(bep.node, gcimock().node)
示例2: TestBaseEndpoint
# 需要導入模塊: from pyon.net.endpoint import BaseEndpoint [as 別名]
# 或者: from pyon.net.endpoint.BaseEndpoint import _ensure_node [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()
示例3: TestBaseEndpoint
# 需要導入模塊: from pyon.net.endpoint import BaseEndpoint [as 別名]
# 或者: from pyon.net.endpoint.BaseEndpoint import _ensure_node [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)