當前位置: 首頁>>代碼示例>>Python>>正文


Python BaseEndpoint.create_endpoint方法代碼示例

本文整理匯總了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()
開發者ID:daf,項目名稱:pyon,代碼行數:74,代碼來源:test_endpoint.py

示例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)
開發者ID:dstuebe,項目名稱:pyon,代碼行數:74,代碼來源:test_endpoint.py


注:本文中的pyon.net.endpoint.BaseEndpoint.create_endpoint方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。